Skip to content

Commit cb10ff1

Browse files
committed
runtime: report next_gc for initial heap size in gctrace
Currently, the initial heap size reported in the gctrace line is the heap_live right before sweep termination. However, we triggered GC when heap_live reached next_gc, and there may have been significant allocation between that point and the beginning of sweep termination. Ideally these would be essentially the same, but currently there's scheduler delay when readying the GC goroutine as well as delay from background sweep finalization. We should fix this delay, but in the mean time, to give the user a better idea of how much the heap grew during the whole of garbage collection, report the trigger rather than what the heap size happened to be after the garbage collector finished rolling out of bed. This will also be more useful for heap growth plots. Change-Id: I08476b9fbcfb2de90592405e9c9f434dfb9eb1f8 Reviewed-on: https://go-review.googlesource.com/8512 Reviewed-by: Rick Hudson <[email protected]>
1 parent d13f479 commit cb10ff1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/runtime/mgc.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,14 @@ func gc(mode int) {
314314
if debug.gctrace > 0 {
315315
stwprocs, maxprocs = gcprocs(), gomaxprocs
316316
tSweepTerm = nanotime()
317-
heap0 = memstats.heap_live
317+
if mode == gcBackgroundMode {
318+
// We started GC when heap_live == next_gc,
319+
// but the mutator may have allocated between
320+
// then and now. Report heap when GC started.
321+
heap0 = memstats.next_gc
322+
} else {
323+
heap0 = memstats.heap_live
324+
}
318325
}
319326

320327
if trace.enabled {

0 commit comments

Comments
 (0)