From b0d5e5c5001f6c9e2a0c12bb8e33883710126974 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 17 Oct 2015 23:52:49 -0400 Subject: [PATCH] runtime: consolidate gcResetGState calls 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 --- src/runtime/mgc.go | 14 ++++---------- src/runtime/mgcmark.go | 8 ++++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 70ceb9bbb7..f3a95ba113 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -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). diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 9b20f0aae5..35bdda9789 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -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.