1
0
mirror of https://github.com/golang/go synced 2024-11-18 00:14:47 -07:00

runtime: convert gcController.heapScan to atomic type

For #53821.

Change-Id: I64d3f53c89a579d93056906304e4c05fc35cd9b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/417776
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Michael Pratt 2022-07-15 16:56:03 -04:00
parent 3a9281ff61
commit 6e9925c4f7
3 changed files with 12 additions and 14 deletions

View File

@ -23,7 +23,6 @@ var AtomicFields = []uintptr{
unsafe.Offsetof(schedt{}.timeToRun),
unsafe.Offsetof(gcControllerState{}.bgScanCredit),
unsafe.Offsetof(gcControllerState{}.maxStackScan),
unsafe.Offsetof(gcControllerState{}.heapScan),
unsafe.Offsetof(gcControllerState{}.dedicatedMarkTime),
unsafe.Offsetof(gcControllerState{}.dedicatedMarkWorkersNeeded),
unsafe.Offsetof(gcControllerState{}.fractionalMarkTime),

View File

@ -1325,7 +1325,7 @@ func (c *GCController) StartCycle(stackSize, globalsSize uint64, scannableFrac f
c.maxStackScan = stackSize
c.globalsScan = globalsSize
c.heapLive.Store(trigger)
c.heapScan += uint64(float64(trigger-c.heapMarked) * scannableFrac)
c.heapScan.Add(int64(float64(trigger-c.heapMarked) * scannableFrac))
c.startCycle(0, gomaxprocs, gcTrigger{kind: gcTriggerHeap})
}
@ -1359,7 +1359,7 @@ type GCControllerReviseDelta struct {
func (c *GCController) Revise(d GCControllerReviseDelta) {
c.heapLive.Add(d.HeapLive)
c.heapScan += uint64(d.HeapScan)
c.heapScan.Add(d.HeapScan)
c.heapScanWork.Add(d.HeapScanWork)
c.stackScanWork.Add(d.StackScanWork)
c.globalsScanWork.Add(d.GlobalsScanWork)

View File

@ -200,14 +200,13 @@ type gcControllerState struct {
// this gcControllerState's revise() method.
heapLive atomic.Uint64
// heapScan is the number of bytes of "scannable" heap. This
// is the live heap (as counted by heapLive), but omitting
// no-scan objects and no-scan tails of objects.
// heapScan is the number of bytes of "scannable" heap. This is the
// live heap (as counted by heapLive), but omitting no-scan objects and
// no-scan tails of objects.
//
// This value is fixed at the start of a GC cycle, so during a
// GC cycle it is safe to read without atomics, and it represents
// the maximum scannable heap.
heapScan uint64
// This value is fixed at the start of a GC cycle. It represents the
// maximum scannable heap.
heapScan atomic.Uint64
// lastHeapScan is the number of bytes of heap that were scanned
// last GC cycle. It is the same as heapMarked, but only
@ -511,7 +510,7 @@ func (c *gcControllerState) startCycle(markStartTime int64, procs int, trigger g
if debug.gcpacertrace > 0 {
assistRatio := c.assistWorkPerByte.Load()
print("pacer: assist ratio=", assistRatio,
" (scan ", gcController.heapScan>>20, " MB in ",
" (scan ", gcController.heapScan.Load()>>20, " MB in ",
work.initialHeapLive>>20, "->",
heapGoal>>20, " MB)",
" workers=", c.dedicatedMarkWorkersNeeded,
@ -549,7 +548,7 @@ func (c *gcControllerState) revise() {
gcPercent = 100000
}
live := c.heapLive.Load()
scan := atomic.Load64(&c.heapScan)
scan := c.heapScan.Load()
work := c.heapScanWork.Load() + c.stackScanWork.Load() + c.globalsScanWork.Load()
// Assume we're under the soft goal. Pace GC to complete at
@ -891,7 +890,7 @@ func (c *gcControllerState) findRunnableGCWorker(pp *p, now int64) (*g, int64) {
func (c *gcControllerState) resetLive(bytesMarked uint64) {
c.heapMarked = bytesMarked
c.heapLive.Store(bytesMarked)
c.heapScan = uint64(c.heapScanWork.Load())
c.heapScan.Store(uint64(c.heapScanWork.Load()))
c.lastHeapScan = uint64(c.heapScanWork.Load())
c.lastStackScan = uint64(c.stackScanWork.Load())
c.triggered = ^uint64(0) // Reset triggered.
@ -935,7 +934,7 @@ func (c *gcControllerState) update(dHeapLive, dHeapScan int64) {
// Update heapScan when we're not in a current GC. It is fixed
// at the beginning of a cycle.
if dHeapScan != 0 {
atomic.Xadd64(&gcController.heapScan, dHeapScan)
gcController.heapScan.Add(dHeapScan)
}
} else {
// gcController.heapLive changed.