]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix triggering of forced GC
authorDmitriy Vyukov <dvyukov@google.com>
Tue, 13 May 2014 05:53:03 +0000 (09:53 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Tue, 13 May 2014 05:53:03 +0000 (09:53 +0400)
mstats.last_gc is unix time now, it is compared with abstract monotonic time.
On my machine GC is forced every 5 mins regardless of last_gc.

LGTM=rsc
R=golang-codereviews
CC=golang-codereviews, iant, rsc
https://golang.org/cl/91350045

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

index 1ba0c0ee4ac6dda0aa177061aacfd2d96548ad94..3afbec2c860e68660ce24a6c4c00f3d9cdfca32f 100644 (file)
@@ -91,8 +91,6 @@ enum {
 // Initialized from $GOGC.  GOGC=off means no gc.
 static int32 gcpercent = GcpercentUnknown;
 
-void runtime·gc_unixnanotime(int64 *now);
-
 static FuncVal* poolcleanup;
 
 void
@@ -2406,7 +2404,7 @@ gc(struct gc_args *args)
        mstats.next_gc = mstats.heap_alloc+mstats.heap_alloc*gcpercent/100;
 
        t4 = runtime·nanotime();
-       runtime·gc_unixnanotime((int64*)&mstats.last_gc);  // must be Unix time to make sense to user
+       mstats.last_gc = runtime·unixnanotime();  // must be Unix time to make sense to user
        mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = t4 - t0;
        mstats.pause_total_ns += t4 - t0;
        mstats.numgc++;
index 43bf106592c74aaf656ce44664bf02d48e2ef560..3de6b8bb4ee0f85709441ef70062b3422a58a855 100644 (file)
@@ -508,6 +508,7 @@ runtime·MHeap_Scavenger(void)
 {
        MHeap *h;
        uint64 tick, now, forcegc, limit;
+       int64 unixnow;
        int32 k;
        Note note, *notep;
 
@@ -531,8 +532,8 @@ runtime·MHeap_Scavenger(void)
                runtime·notetsleepg(&note, tick);
 
                runtime·lock(h);
-               now = runtime·nanotime();
-               if(now - mstats.last_gc > forcegc) {
+               unixnow = runtime·unixnanotime();
+               if(unixnow - mstats.last_gc > forcegc) {
                        runtime·unlock(h);
                        // The scavenger can not block other goroutines,
                        // otherwise deadlock detector can fire spuriously.
@@ -544,8 +545,8 @@ runtime·MHeap_Scavenger(void)
                        if(runtime·debug.gctrace > 0)
                                runtime·printf("scvg%d: GC forced\n", k);
                        runtime·lock(h);
-                       now = runtime·nanotime();
                }
+               now = runtime·nanotime();
                scavenge(k, now, limit);
                runtime·unlock(h);
        }
index 864b681f4a1d6c86d5d9adcdbaba0123262ce9ab..39a849c80588d97e996ba092c890708199901189 100644 (file)
@@ -920,7 +920,8 @@ void        runtime·exitsyscall(void);
 G*     runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
 bool   runtime·sigsend(int32 sig);
 int32  runtime·callers(int32, uintptr*, int32);
-int64  runtime·nanotime(void);
+int64  runtime·nanotime(void);        // monotonic time
+int64  runtime·unixnanotime(void); // real time, can skip
 void   runtime·dopanic(int32);
 void   runtime·startpanic(void);
 void   runtime·freezetheworld(void);
index 195c5c41a37713c635fbc69d934687ac02c7ab5b..712e03e838832f0ae8d7d0436224405db13dab94 100644 (file)
@@ -54,6 +54,16 @@ func stopTimer(t *Timer) (stopped bool) {
 
 // C runtime.
 
+void runtime·gc_unixnanotime(int64 *now);
+
+int64 runtime·unixnanotime(void)
+{
+       int64 now;
+
+       runtime·gc_unixnanotime(&now);
+       return now;
+}
+
 static void timerproc(void);
 static void siftup(int32);
 static void siftdown(int32);