mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: make gcSetTriggerRatio work at any time
This changes gcSetTriggerRatio so it can be called even during concurrent mark or sweep. In this case, it will adjust the pacing of the current phase, accounting for progress that has already been made. To make this work for concurrent sweep, this introduces a "basis" for the pagesSwept count, much like the basis we just introduced for heap_live. This lets gcSetTriggerRatio shift the basis to the current heap_live and pagesSwept and compute a slope from there to completion. This avoids creating a discontinuity where, if the ratio has increased, there has to be a flurry of sweep activity to catch up. Instead, this creates a continuous, piece-wise linear function as adjustments are made. For #19076. Change-Id: Ibcd76aeeb81ff4814b00be7cbd3530b73bbdbba9 Reviewed-on: https://go-review.googlesource.com/39833 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rick Hudson <rlh@golang.org>
This commit is contained in:
parent
a5eb3dceaf
commit
1c4f3c5ea0
3 changed files with 53 additions and 18 deletions
|
|
@ -75,8 +75,26 @@ type mheap struct {
|
|||
_ uint32 // align uint64 fields on 32-bit for atomics
|
||||
|
||||
// Proportional sweep
|
||||
//
|
||||
// These parameters represent a linear function from heap_live
|
||||
// to page sweep count. The proportional sweep system works to
|
||||
// stay in the black by keeping the current page sweep count
|
||||
// above this line at the current heap_live.
|
||||
//
|
||||
// The line has slope sweepPagesPerByte and passes through a
|
||||
// basis point at (sweepHeapLiveBasis, pagesSweptBasis). At
|
||||
// any given time, the system is at (memstats.heap_live,
|
||||
// pagesSwept) in this space.
|
||||
//
|
||||
// It's important that the line pass through a point we
|
||||
// control rather than simply starting at a (0,0) origin
|
||||
// because that lets us adjust sweep pacing at any time while
|
||||
// accounting for current progress. If we could only adjust
|
||||
// the slope, it would create a discontinuity in debt if any
|
||||
// progress has already been made.
|
||||
pagesInUse uint64 // pages of spans in stats _MSpanInUse; R/W with mheap.lock
|
||||
pagesSwept uint64 // pages swept this cycle; updated atomically
|
||||
pagesSweptBasis uint64 // pagesSwept to use as the origin of the sweep ratio; updated atomically
|
||||
sweepHeapLiveBasis uint64 // value of heap_live to use as the origin of sweep ratio; written with lock, read without
|
||||
sweepPagesPerByte float64 // proportional sweep ratio; written with lock, read without
|
||||
// TODO(austin): pagesInUse should be a uintptr, but the 386
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue