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);
}
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);
}
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;
}
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;
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
{
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) {
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;
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;
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;
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);