]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: earlier detection of unused spans.
authorSébastien Paolacci <sebastien.paolacci@gmail.com>
Mon, 28 Jan 2013 17:53:35 +0000 (12:53 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 28 Jan 2013 17:53:35 +0000 (12:53 -0500)
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

src/pkg/runtime/mgc0.c
src/pkg/runtime/mheap.c

index a6588954897ff8ffbf9649640f8bf8771aaf45f8..dd6640717ad3705808316e73188c9ce3cd29c14b 100644 (file)
@@ -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;
index 0946adcb9f0cb4702b7efca20b32f1cba86334c7..1af53e7503655c3d4a17c7d442469a16bf7074c1 100644 (file)
@@ -138,7 +138,9 @@ HaveSpan:
                *(uintptr*)(t->start<<PageShift) = *(uintptr*)(s->start<<PageShift);  // copy "needs zeroing" mark
                t->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<<PageShift;
        s->state = MSpanFree;
-       s->unusedsince = 0;
-       s->npreleased = 0;
        runtime·MSpanList_Remove(s);
        sp = (uintptr*)(s->start<<PageShift);
+       // Stamp newly unused spans. The scavenger will use that
+       // info to potentially give back some pages to the OS.
+       s->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(&note);
                        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;