Skip to content

Commit

Permalink
runtime: consolidate gcResetGState calls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aclements committed Oct 19, 2015
1 parent feb92a8 commit b0d5e5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/runtime/mgc.go
Expand Up @@ -987,6 +987,7 @@ func gc(mode gcMode) {
// reclaimed until the next GC cycle.
clearpools()

gcResetGState()
gcResetMarkState()

work.finalizersDone = false
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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).
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/mgcmark.go
Expand Up @@ -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.
Expand Down

0 comments on commit b0d5e5c

Please sign in to comment.