From: Michael Pratt Date: Fri, 15 Jul 2022 20:56:03 +0000 (-0400) Subject: runtime: convert gcController.heapScan to atomic type X-Git-Tag: go1.20rc1~1792 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6e9925c4f71fd862685859e9116f165cff5118c1;p=gostls13.git 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 Reviewed-by: Austin Clements TryBot-Result: Gopher Robot --- diff --git a/src/runtime/align_runtime_test.go b/src/runtime/align_runtime_test.go index 6a9ffeffa4..3f86838ac5 100644 --- a/src/runtime/align_runtime_test.go +++ b/src/runtime/align_runtime_test.go @@ -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), diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index fd1e89609b..1018875651 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -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) diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go index 29ee2d5909..9366bc355f 100644 --- a/src/runtime/mgcpacer.go +++ b/src/runtime/mgcpacer.go @@ -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.