]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix runaway memory usage
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 6 Mar 2014 17:33:00 +0000 (21:33 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 6 Mar 2014 17:33:00 +0000 (21:33 +0400)
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

src/pkg/runtime/malloc.goc
src/pkg/runtime/mcache.c
src/pkg/runtime/mgc0.c

index 0470211506df5b57d35e18fccac7db3a0c0a813a..0e8a812641a342b1e5226a5d1e96b30f50d6cfb3 100644 (file)
@@ -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);
index 0b4bbd90bec7813abc41faed2f1b7c00de964fab..26e3db2dcab92b3be53cf30fb3aa7cb6927361d7 100644 (file)
@@ -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.
index aa3eddbccd73fa6efef5ed636889a16748b0f8f7..400149c26d9bd291e56ade4f837875c6c272645a 100644 (file)
@@ -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;