]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add freemcache() function
authorDmitriy Vyukov <dvyukov@google.com>
Sun, 1 Jul 2012 09:10:01 +0000 (13:10 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Sun, 1 Jul 2012 09:10:01 +0000 (13:10 +0400)
It will be required for scheduler that maintains
GOMAXPROCS MCache's.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6350062

src/pkg/runtime/malloc.goc
src/pkg/runtime/malloc.h
src/pkg/runtime/mgc0.c
src/pkg/runtime/mheap.c
src/pkg/runtime/runtime.h

index 2dff981fb40d4126dd342e7f6a2bf8765e33baef..babe4d2f4ccb13d2075d28f6d84b15bc2dc22e0b 100644 (file)
@@ -76,7 +76,7 @@ runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
        if (sizeof(void*) == 4 && c->local_total_alloc >= (1<<30)) {
                // purge cache stats to prevent overflow
                runtime·lock(&runtime·mheap);
-               runtime·purgecachedstats(m);
+               runtime·purgecachedstats(c);
                runtime·unlock(&runtime·mheap);
        }
 
@@ -181,7 +181,7 @@ runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **sp)
        if (sizeof(void*) == 4 && m->mcache->local_nlookup >= (1<<30)) {
                // purge cache stats to prevent overflow
                runtime·lock(&runtime·mheap);
-               runtime·purgecachedstats(m);
+               runtime·purgecachedstats(m->mcache);
                runtime·unlock(&runtime·mheap);
        }
 
@@ -234,6 +234,7 @@ runtime·allocmcache(void)
        mstats.mcache_inuse = runtime·mheap.cachealloc.inuse;
        mstats.mcache_sys = runtime·mheap.cachealloc.sys;
        runtime·unlock(&runtime·mheap);
+       runtime·memclr((byte*)c, sizeof(*c));
 
        // Set first allocation sample size.
        rate = runtime·MemProfileRate;
@@ -246,12 +247,19 @@ runtime·allocmcache(void)
 }
 
 void
-runtime·purgecachedstats(M* m)
+runtime·freemcache(MCache *c)
 {
-       MCache *c;
+       runtime·MCache_ReleaseAll(c);
+       runtime·lock(&runtime·mheap);
+       runtime·purgecachedstats(c);
+       runtime·FixAlloc_Free(&runtime·mheap.cachealloc, c);
+       runtime·unlock(&runtime·mheap);
+}
 
+void
+runtime·purgecachedstats(MCache *c)
+{
        // Protected by either heap or GC lock.
-       c = m->mcache;
        mstats.heap_alloc += c->local_cachealloc;
        c->local_cachealloc = 0;
        mstats.heap_objects += c->local_objects;
index f2408f18f2f7088ce0c6ff08ae2a992653655c4b..fee6e0178909634d8158497c1d31516eb4c4803f 100644 (file)
@@ -401,7 +401,7 @@ void        runtime·markspan(void *v, uintptr size, uintptr n, bool leftover);
 void   runtime·unmarkspan(void *v, uintptr size);
 bool   runtime·blockspecial(void*);
 void   runtime·setblockspecial(void*, bool);
-void   runtime·purgecachedstats(M*);
+void   runtime·purgecachedstats(MCache*);
 
 enum
 {
index 70d0a0f2e2843cf7b66031dd5e887132ff46a30f..147c78ad80e17d12da1131903d395f8da1dcb704 100644 (file)
@@ -823,7 +823,8 @@ cachestats(GCStats *stats)
        stacks_inuse = 0;
        stacks_sys = 0;
        for(m=runtime·allm; m; m=m->alllink) {
-               runtime·purgecachedstats(m);
+               c = m->mcache;
+               runtime·purgecachedstats(c);
                stacks_inuse += m->stackalloc->inuse;
                stacks_sys += m->stackalloc->sys;
                if(stats) {
@@ -833,7 +834,6 @@ cachestats(GCStats *stats)
                                dst[i] += src[i];
                        runtime·memclr((byte*)&m->gcstats, sizeof(m->gcstats));
                }
-               c = m->mcache;
                for(i=0; i<nelem(c->local_by_size); i++) {
                        mstats.by_size[i].nmalloc += c->local_by_size[i].nmalloc;
                        c->local_by_size[i].nmalloc = 0;
index a8a435b20e97e456dbd5ac08a316f343a0dd3618..1ea748904959dbd6c313759969724e2e4e220469 100644 (file)
@@ -71,7 +71,7 @@ runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct, int32
        MSpan *s;
 
        runtime·lock(h);
-       runtime·purgecachedstats(m);
+       runtime·purgecachedstats(m->mcache);
        s = MHeap_AllocLocked(h, npage, sizeclass);
        if(s != nil) {
                mstats.heap_inuse += npage<<PageShift;
@@ -271,7 +271,7 @@ void
 runtime·MHeap_Free(MHeap *h, MSpan *s, int32 acct)
 {
        runtime·lock(h);
-       runtime·purgecachedstats(m);
+       runtime·purgecachedstats(m->mcache);
        mstats.heap_inuse -= s->npages<<PageShift;
        if(acct) {
                mstats.heap_alloc -= s->npages<<PageShift;
index cdd71726e5aa9e881e8170a61dbb45a577d32b51..07c1585c778af8811f04748acb2550ef0e495b0e 100644 (file)
@@ -590,6 +590,7 @@ int32       runtime·funcline(Func*, uintptr);
 void*  runtime·stackalloc(uint32);
 void   runtime·stackfree(void*, uintptr);
 MCache*        runtime·allocmcache(void);
+void   runtime·freemcache(MCache*);
 void   runtime·mallocinit(void);
 bool   runtime·ifaceeq_c(Iface, Iface);
 bool   runtime·efaceeq_c(Eface, Eface);