Skip to content

Commit 3618ac2

Browse files
aclementsandybons
authored andcommitted
[release-branch.go1.9] runtime: fix gctrace STW CPU time and CPU fraction
The CPU time reported in the gctrace for STW phases is simply work.stwprocs times the wall-clock duration of these phases. However, work.stwprocs is set to gcprocs(), which is wrong for multiple reasons: 1. gcprocs is intended to limit the number of Ms used for mark termination based on how well the garbage collector actually scales, but the gctrace wants to report how much CPU time is being stolen from the application. During STW, that's *all* of the CPU, regardless of how many the garbage collector can actually use. 2. gcprocs assumes it's being called during STW, so it limits its result to sched.nmidle+1. However, we're not calling it during STW, so sched.nmidle is typically quite small, even if GOMAXPROCS is quite large. Fix this by setting work.stwprocs to min(ncpu, GOMAXPROCS). This also fixes the overall GC CPU fraction, which is based on the computed CPU times. Fixes #22725. Change-Id: I64b5ce87e28dbec6870aa068ce7aecdd28c058d1 Reviewed-on: https://go-review.googlesource.com/77710 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rick Hudson <[email protected]> Reviewed-on: https://go-review.googlesource.com/88321 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 1cca09a commit 3618ac2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/runtime/mgc.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,12 @@ func gcStart(mode gcMode, trigger gcTrigger) {
12511251

12521252
gcResetMarkState()
12531253

1254-
work.stwprocs, work.maxprocs = gcprocs(), gomaxprocs
1254+
work.stwprocs, work.maxprocs = gomaxprocs, gomaxprocs
1255+
if work.stwprocs > ncpu {
1256+
// This is used to compute CPU time of the STW phases,
1257+
// so it can't be more than ncpu, even if GOMAXPROCS is.
1258+
work.stwprocs = ncpu
1259+
}
12551260
work.heap0 = atomic.Load64(&memstats.heap_live)
12561261
work.pauseNS = 0
12571262
work.mode = mode

0 commit comments

Comments
 (0)