]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: consolidate gcResetGState calls
authorAustin Clements <austin@google.com>
Sun, 18 Oct 2015 03:52:49 +0000 (23:52 -0400)
committerAustin Clements <austin@google.com>
Mon, 19 Oct 2015 18:38:00 +0000 (18:38 +0000)
Currently gcResetGState is called by func gcscan_m for concurrent GC
and directly by func gc for STW GC. Simplify this by consolidating
these two calls in to one call by func gc above where it splits for
concurrent and STW GC.

As a consequence, gcResetGState and gcResetMarkState are always called
together, so the next commit will consolidate these.

Change-Id: Ib62d404c7b32b28f7d3080d26ecf3966cbc4aca0
Reviewed-on: https://go-review.googlesource.com/16040
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mgc.go
src/runtime/mgcmark.go

index 70ceb9bbb7bec18b088ae35551ae8c5bfc7745a5..f3a95ba113c9c107a7ab56783d4a2d9078ca2d21 100644 (file)
@@ -987,6 +987,7 @@ func gc(mode gcMode) {
        // reclaimed until the next GC cycle.
        clearpools()
 
+       gcResetGState()
        gcResetMarkState()
 
        work.finalizersDone = false
@@ -1105,11 +1106,6 @@ func gc(mode gcMode) {
 
                gcController.endCycle()
        } else {
-               // For non-concurrent GC (mode != gcBackgroundMode)
-               // The g stacks have not been scanned so clear g state
-               // such that mark termination scans all stacks.
-               gcResetGState()
-
                t := nanotime()
                tScan, tInstallWB, tMark, tMarkTerm = t, t, t, t
                heapGoal = heap0
@@ -1653,9 +1649,9 @@ func gcCopySpans() {
        unlock(&mheap_.lock)
 }
 
-// gcResetGState resets the GC state of all G's and returns the length
-// of allgs.
-func gcResetGState() (numgs int) {
+// gcResetGState resets the GC state of all G's. Any Gs created after
+// this will also be in this reset state.
+func gcResetGState() {
        // This may be called during a concurrent phase, so make sure
        // allgs doesn't change.
        lock(&allglock)
@@ -1664,9 +1660,7 @@ func gcResetGState() (numgs int) {
                gp.gcscanvalid = false // stack has not been scanned
                gp.gcAssistBytes = 0
        }
-       numgs = len(allgs)
        unlock(&allglock)
-       return
 }
 
 // gcResetMarkState resets state prior to marking (concurrent or STW).
index 9b20f0aae56d6a0b23e956b4d25a16471ab2238f..35bdda97899e5f20864a6bd34b61e1d8fdc71ef8 100644 (file)
@@ -26,8 +26,12 @@ func gcscan_m() {
        // runtimeĀ·restartg(mastergp) to make it Grunnable.
        // At the bottom we will want to return this p back to the scheduler.
 
-       // Prepare flag indicating that the scan has not been completed.
-       local_allglen := gcResetGState()
+       // Snapshot of allglen. During concurrent scan, we just need
+       // to be consistent about how many markroot jobs we create and
+       // how many Gs we check. Gs may be created after this and
+       // they'll be scanned during mark termination. During mark
+       // termination, allglen isn't changing.
+       local_allglen := int(atomicloaduintptr(&allglen))
 
        work.ndone = 0
        useOneP := uint32(1) // For now do not do this in parallel.