diff options
author | Austin Clements <austin@google.com> | 2017-11-14 15:08:32 -0800 |
---|---|---|
committer | Andrew Bonventre <andybons@golang.org> | 2018-01-22 20:25:02 +0000 |
commit | 3618ac2ca5020b8ece78e6c5348e091f5b79c5e8 (patch) | |
tree | e716197b1daf5983414bd66eaa373c21590034ca | |
parent | 1cca09a8edb777f094026ad3a88111d56454a1b3 (diff) | |
download | go-3618ac2ca5020b8ece78e6c5348e091f5b79c5e8.tar.gz go-3618ac2ca5020b8ece78e6c5348e091f5b79c5e8.zip |
[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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-on: https://go-review.googlesource.com/88321
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
-rw-r--r-- | src/runtime/mgc.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index b708720322..e6909918f2 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1251,7 +1251,12 @@ func gcStart(mode gcMode, trigger gcTrigger) { gcResetMarkState() - work.stwprocs, work.maxprocs = gcprocs(), gomaxprocs + work.stwprocs, work.maxprocs = gomaxprocs, gomaxprocs + if work.stwprocs > ncpu { + // This is used to compute CPU time of the STW phases, + // so it can't be more than ncpu, even if GOMAXPROCS is. + work.stwprocs = ncpu + } work.heap0 = atomic.Load64(&memstats.heap_live) work.pauseNS = 0 work.mode = mode |