void runtime·MCache_Free(MCache *c, void *v, int32 sizeclass, uintptr size) { int32 i, n; MCacheList *l; MLink *p; // Put back on list. l = &c->list[sizeclass]; p = v; p->next = l->list; l->list = p; l->nlist++; c->size += size; c->local_cachealloc -= size; c->local_objects--; if(l->nlist >= MaxMCacheListLen) { // Release a chunk back. ReleaseN(c, l, runtime·class_to_transfercount[sizeclass], sizeclass); } if(c->size >= MaxMCacheSize) { // Scavenge. for(i=0; i<NumSizeClasses; i++) { l = &c->list[i]; n = l->nlistmin; // n is the minimum number of elements we've seen on // the list since the last scavenge. If n > 0, it means that // we could have gotten by with n fewer elements // without needing to consult the central free list. // Move toward that situation by releasing n/2 of them. if(n > 0) { if(n > 1) n /= 2; ReleaseN(c, l, n, i); } l->nlistmin = l->nlist; } } }
void runtime·MCache_ReleaseAll(MCache *c) { int32 i; MCacheList *l; for(i=0; i<NumSizeClasses; i++) { l = &c->list[i]; ReleaseN(c, l, l->nlist, i); l->nlistmin = 0; } }
void runtime·MCache_Free(MCache *c, void *v, int32 sizeclass, uintptr size) { MCacheList *l; MLink *p; // Put back on list. l = &c->list[sizeclass]; p = v; p->next = l->list; l->list = p; l->nlist++; c->local_cachealloc -= size; c->local_objects--; // We transfer span at a time from MCentral to MCache, // if we have 2 times more than that, release a half back. if(l->nlist >= 2*(runtime·class_to_allocnpages[sizeclass]<<PageShift)/size) ReleaseN(l, l->nlist/2, sizeclass); }