From: Sébastien Paolacci Date: Mon, 28 Jan 2013 17:53:35 +0000 (-0500) Subject: runtime: earlier detection of unused spans. X-Git-Tag: go1.1rc2~1278 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=09ea3b518ee6fd45a7b09b7f34a4ef84c5159240;p=gostls13.git runtime: earlier detection of unused spans. Mark candidate spans one GC pass earlier. Move scavenger's code out from mgc0 and constrain it into mheap (where it belongs). R=rsc, dvyukov, minux.ma CC=golang-dev https://golang.org/cl/7002049 --- diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index a658895489..dd6640717a 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -1159,10 +1159,6 @@ sweepspan(ParFor *desc, uint32 idx) USED(&desc); s = runtime·mheap.allspans[idx]; - // Stamp newly unused spans. The scavenger will use that - // info to potentially give back some pages to the OS. - if(s->state == MSpanFree && s->unusedsince == 0) - s->unusedsince = runtime·nanotime(); if(s->state != MSpanInUse) return; arena_start = runtime·mheap.arena_start; diff --git a/src/pkg/runtime/mheap.c b/src/pkg/runtime/mheap.c index 0946adcb9f..1af53e7503 100644 --- a/src/pkg/runtime/mheap.c +++ b/src/pkg/runtime/mheap.c @@ -138,7 +138,9 @@ HaveSpan: *(uintptr*)(t->start<start<state = MSpanInUse; MHeap_FreeLocked(h, t); + t->unusedsince = s->unusedsince; // preserve age } + s->unusedsince = 0; // Record span info, because gc needs to be // able to map interior pointer to containing span. @@ -300,10 +302,12 @@ MHeap_FreeLocked(MHeap *h, MSpan *s) } mstats.heap_idle += s->npages<state = MSpanFree; - s->unusedsince = 0; - s->npreleased = 0; runtime·MSpanList_Remove(s); sp = (uintptr*)(s->start<unusedsince = runtime·nanotime(); + s->npreleased = 0; // Coalesce with earlier, later spans. p = s->start; @@ -401,10 +405,10 @@ runtime·MHeap_Scavenger(void) runtime·entersyscall(); runtime·notesleep(¬e); runtime·exitsyscall(); + if(trace) + runtime·printf("scvg%d: GC forced\n", k); runtime·lock(h); now = runtime·nanotime(); - if (trace) - runtime·printf("scvg%d: GC forced\n", k); } sumreleased = 0; for(i=0; i < nelem(h->free)+1; i++) { @@ -415,7 +419,7 @@ runtime·MHeap_Scavenger(void) if(runtime·MSpanList_IsEmpty(list)) continue; for(s=list->next; s != list; s=s->next) { - if(s->unusedsince != 0 && (now - s->unusedsince) > limit) { + if((now - s->unusedsince) > limit) { released = (s->npages - s->npreleased) << PageShift; mstats.heap_released += released; sumreleased += released;