]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: track forced GCs independent of gcMode
authorAustin Clements <austin@google.com>
Mon, 27 Feb 2017 15:46:12 +0000 (10:46 -0500)
committerAustin Clements <austin@google.com>
Fri, 31 Mar 2017 01:15:13 +0000 (01:15 +0000)
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: Rick Hudson <rlh@golang.org>
src/runtime/mgc.go

index bcd43d8f34251672c584b471ce9bc8f94285d5b4..ba7cf9cb14a98f1b1be6599af06aef7a86bb0ccb 100644 (file)
@@ -857,6 +857,10 @@ var work struct {
        // mode is the concurrency mode of the current GC cycle.
        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
        // program started if debug.gctrace > 0.
        totaltime int64
@@ -992,7 +996,7 @@ func gcStart(mode gcMode, trigger gcTrigger) {
        }
 
        // 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.
        // We do this after re-checking the transition condition so
@@ -1087,10 +1091,6 @@ func gcStart(mode gcMode, trigger gcTrigger) {
                work.tMark, work.tMarkTerm = t, t
                work.heapGoal = work.heap0
 
-               if forced {
-                       memstats.numforcedgc++
-               }
-
                // Perform mark termination. This will restart the world.
                gcMarkTermination()
        }
@@ -1330,6 +1330,10 @@ func gcMarkTermination() {
        sweep.nbgsweep = 0
        sweep.npausesweep = 0
 
+       if work.userForced {
+               memstats.numforcedgc++
+       }
+
        // Finish the current heap profiling cycle and start a new
        // heap profiling cycle. We do this before starting the world
        // so events don't leak into the wrong cycle.
@@ -1378,7 +1382,7 @@ func gcMarkTermination() {
                        work.heap0>>20, "->", work.heap1>>20, "->", work.heap2>>20, " MB, ",
                        work.heapGoal>>20, " MB goal, ",
                        work.maxprocs, " P")
-               if work.mode != gcBackgroundMode {
+               if work.userForced {
                        print(" (forced)")
                }
                print("\n")