]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: convert gcController.heapScan to atomic type
authorMichael Pratt <mpratt@google.com>
Fri, 15 Jul 2022 20:56:03 +0000 (16:56 -0400)
committerMichael Pratt <mpratt@google.com>
Mon, 8 Aug 2022 14:11:19 +0000 (14:11 +0000)
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>

src/runtime/align_runtime_test.go
src/runtime/export_test.go
src/runtime/mgcpacer.go

index 6a9ffeffa448857127d1d78eceebf8db6eefb0e9..3f86838ac5af5a05551b58cf8a9081c642832e9e 100644 (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),
index fd1e89609b79f69d3a8b820f5250fcc0548ce9cc..1018875651949ab70d3940d5d60929d329fa38ac 100644 (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)
index 29ee2d5909b902b27154e9ce9e4f53b59f22fc1a..9366bc355f1e49836296d1e09ab0ece2f73ef521 100644 (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.