mirror of
https://github.com/golang/go
synced 2024-11-18 08:44:43 -07:00
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 <rlh@golang.org>
This commit is contained in:
parent
feb92a8e8c
commit
b0d5e5c500
@ -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).
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user