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
// Initialized from $GOGC. GOGC=off means no gc.
static int32 gcpercent = GcpercentUnknown;
-void runtime·gc_unixnanotime(int64 *now);
-
static FuncVal* poolcleanup;
void
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++;
{
MHeap *h;
uint64 tick, now, forcegc, limit;
+ int64 unixnow;
int32 k;
Note note, *notep;
runtime·notetsleepg(¬e, 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.
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);
}
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);
// 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);