]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: convert gcController.maxStackScan to atomic type
authorMichael Pratt <mpratt@google.com>
Fri, 15 Jul 2022 18:27:48 +0000 (14:27 -0400)
committerMichael Pratt <mpratt@google.com>
Mon, 8 Aug 2022 14:11:32 +0000 (14:11 +0000)
For #53821.

Change-Id: I1bd23cdbc371011ec2331fb0a37482ecf99a063b
Reviewed-on: https://go-review.googlesource.com/c/go/+/417778
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/mgc.go
src/runtime/mgcpacer.go

index 03309a22d06bfbb113205d3ceec4ec52353f64fa..9fe7b61c44070b9f756cf034ac1ef6ff63a02a1e 100644 (file)
@@ -22,7 +22,6 @@ var AtomicFields = []uintptr{
        unsafe.Offsetof(schedt{}.pollUntil),
        unsafe.Offsetof(schedt{}.timeToRun),
        unsafe.Offsetof(gcControllerState{}.bgScanCredit),
-       unsafe.Offsetof(gcControllerState{}.maxStackScan),
        unsafe.Offsetof(gcControllerState{}.dedicatedMarkTime),
        unsafe.Offsetof(gcControllerState{}.dedicatedMarkWorkersNeeded),
        unsafe.Offsetof(gcControllerState{}.fractionalMarkTime),
index 1018875651949ab70d3940d5d60929d329fa38ac..473616367389a1b30bb41a3d06370a71188f5e94 100644 (file)
@@ -1322,7 +1322,7 @@ func (c *GCController) StartCycle(stackSize, globalsSize uint64, scannableFrac f
        if c.heapMarked > trigger {
                trigger = c.heapMarked
        }
-       c.maxStackScan = stackSize
+       c.maxStackScan.Store(stackSize)
        c.globalsScan = globalsSize
        c.heapLive.Store(trigger)
        c.heapScan.Add(int64(float64(trigger-c.heapMarked) * scannableFrac))
index c35e9af05bf27ff8be824d36c4fecc665f7093bc..b1657482a0735222095998b766fda8c26001c011 100644 (file)
@@ -1120,7 +1120,7 @@ func gcMarkTermination() {
                print(" ms cpu, ",
                        work.heap0>>20, "->", work.heap1>>20, "->", work.heap2>>20, " MB, ",
                        gcController.lastHeapGoal>>20, " MB goal, ",
-                       atomic.Load64(&gcController.maxStackScan)>>20, " MB stacks, ",
+                       gcController.maxStackScan.Load()>>20, " MB stacks, ",
                        gcController.globalsScan>>20, " MB globals, ",
                        work.maxprocs, " P")
                if work.userForced {
index bc4946d46f4eb38db931af1769d4fbcebb5fdd8c..fe31d6fbd851faaee1f951072f92a86a89441871 100644 (file)
@@ -227,9 +227,7 @@ type gcControllerState struct {
        // goroutine stack space is much harder to measure cheaply. By using
        // allocated space, we make an overestimate; this is OK, it's better
        // to conservatively overcount than undercount.
-       //
-       // Read and updated atomically.
-       maxStackScan uint64
+       maxStackScan atomic.Uint64
 
        // globalsScan is the total amount of global variable space
        // that is scannable.
@@ -563,7 +561,7 @@ func (c *gcControllerState) revise() {
        // needs to be performed in this GC cycle. Specifically, it represents
        // the case where *all* scannable memory turns out to be live, and
        // *all* allocated stack space is scannable.
-       maxStackScan := atomic.Load64(&c.maxStackScan)
+       maxStackScan := c.maxStackScan.Load()
        maxScanWork := int64(scan + maxStackScan + c.globalsScan)
        if work > scanWorkExpected {
                // We've already done more scan work than expected. Because our expectation
@@ -944,12 +942,12 @@ func (c *gcControllerState) update(dHeapLive, dHeapScan int64) {
 
 func (c *gcControllerState) addScannableStack(pp *p, amount int64) {
        if pp == nil {
-               atomic.Xadd64(&c.maxStackScan, amount)
+               c.maxStackScan.Add(amount)
                return
        }
        pp.maxStackScanDelta += amount
        if pp.maxStackScanDelta >= maxStackScanSlack || pp.maxStackScanDelta <= -maxStackScanSlack {
-               atomic.Xadd64(&c.maxStackScan, pp.maxStackScanDelta)
+               c.maxStackScan.Add(pp.maxStackScanDelta)
                pp.maxStackScanDelta = 0
        }
 }