Commit 29fdbcfe authored by Austin Clements's avatar Austin Clements

runtime: track forced GCs independent of gcMode

Currently gcMode != gcBackgroundMode implies this was a user-forced GC
cycle. This is no longer going to be true when we make runtime.GC()
trigger a concurrent GC, so replace this with an explicit
work.userForced bit.

For #18216.

Change-Id: If7d71bbca78b5f0b35641b070f9d457f5c9a52bd
Reviewed-on: https://go-review.googlesource.com/37519
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent 786eb5b7
...@@ -857,6 +857,10 @@ var work struct { ...@@ -857,6 +857,10 @@ var work struct {
// mode is the concurrency mode of the current GC cycle. // mode is the concurrency mode of the current GC cycle.
mode gcMode mode gcMode
// userForced indicates the current GC cycle was forced by an
// explicit user call.
userForced bool
// totaltime is the CPU nanoseconds spent in GC since the // totaltime is the CPU nanoseconds spent in GC since the
// program started if debug.gctrace > 0. // program started if debug.gctrace > 0.
totaltime int64 totaltime int64
...@@ -992,7 +996,7 @@ func gcStart(mode gcMode, trigger gcTrigger) { ...@@ -992,7 +996,7 @@ func gcStart(mode gcMode, trigger gcTrigger) {
} }
// For stats, check if this GC was forced by the user. // For stats, check if this GC was forced by the user.
forced := trigger.kind == gcTriggerAlways work.userForced = trigger.kind == gcTriggerAlways
// In gcstoptheworld debug mode, upgrade the mode accordingly. // In gcstoptheworld debug mode, upgrade the mode accordingly.
// We do this after re-checking the transition condition so // We do this after re-checking the transition condition so
...@@ -1087,10 +1091,6 @@ func gcStart(mode gcMode, trigger gcTrigger) { ...@@ -1087,10 +1091,6 @@ func gcStart(mode gcMode, trigger gcTrigger) {
work.tMark, work.tMarkTerm = t, t work.tMark, work.tMarkTerm = t, t
work.heapGoal = work.heap0 work.heapGoal = work.heap0
if forced {
memstats.numforcedgc++
}
// Perform mark termination. This will restart the world. // Perform mark termination. This will restart the world.
gcMarkTermination() gcMarkTermination()
} }
...@@ -1330,6 +1330,10 @@ func gcMarkTermination() { ...@@ -1330,6 +1330,10 @@ func gcMarkTermination() {
sweep.nbgsweep = 0 sweep.nbgsweep = 0
sweep.npausesweep = 0 sweep.npausesweep = 0
if work.userForced {
memstats.numforcedgc++
}
// Finish the current heap profiling cycle and start a new // Finish the current heap profiling cycle and start a new
// heap profiling cycle. We do this before starting the world // heap profiling cycle. We do this before starting the world
// so events don't leak into the wrong cycle. // so events don't leak into the wrong cycle.
...@@ -1378,7 +1382,7 @@ func gcMarkTermination() { ...@@ -1378,7 +1382,7 @@ func gcMarkTermination() {
work.heap0>>20, "->", work.heap1>>20, "->", work.heap2>>20, " MB, ", work.heap0>>20, "->", work.heap1>>20, "->", work.heap2>>20, " MB, ",
work.heapGoal>>20, " MB goal, ", work.heapGoal>>20, " MB goal, ",
work.maxprocs, " P") work.maxprocs, " P")
if work.mode != gcBackgroundMode { if work.userForced {
print(" (forced)") print(" (forced)")
} }
print("\n") print("\n")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment