Commit aea99eda authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: fix runaway memory usage

It was caused by mstats.heap_alloc skew.
Fixes #7430.

LGTM=khr
R=golang-codereviews, khr
CC=golang-codereviews, rsc
https://golang.org/cl/69870055
parent fd7ff204
......@@ -329,6 +329,7 @@ runtime·free(void *v)
// it might coalesce v and other blocks into a bigger span
// and change the bitmap further.
c->local_nsmallfree[sizeclass]++;
c->local_cachealloc -= size;
if(c->alloc[sizeclass] == s) {
// We own the span, so we can just add v to the freelist
runtime·markfreed(v);
......
......@@ -97,7 +97,6 @@ runtime·MCache_Free(MCache *c, MLink *p, int32 sizeclass, uintptr size)
p->next = l->list;
l->list = p;
l->nlist++;
c->local_cachealloc -= size;
// We transfer a span at a time from MCentral to MCache,
// so we'll do the same in the other direction.
......
......@@ -2346,8 +2346,12 @@ gc(struct gc_args *args)
runtime·printf("pause %D\n", t4-t0);
if(runtime·debug.gctrace) {
updatememstats(&stats);
heap1 = mstats.heap_alloc;
updatememstats(&stats);
if(heap1 != mstats.heap_alloc) {
runtime·printf("runtime: mstats skew: heap=%p/%p\n", heap1, mstats.heap_alloc);
runtime·throw("mstats skew");
}
obj = mstats.nmalloc - mstats.nfree;
stats.nprocyield += work.markfor->nprocyield;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment