From 1dff8f0a056517f0a8adfda663402ffb2e089281 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 18 Oct 2021 23:10:43 +0000 Subject: [PATCH] runtime: retype mheap.pagesSweptBasis as atomic.Uint64 [git-generate] cd src/runtime mv export_test.go export.go GOROOT=$(dirname $(dirname $PWD)) rf ' add mheap.pagesSweptBasis pagesSweptBasis_ atomic.Uint64 // pagesSwept to use as the origin of the sweep ratio ex { import "runtime/internal/atomic" var t mheap var v, w uint64 var d int64 t.pagesSweptBasis -> t.pagesSweptBasis_.Load() t.pagesSweptBasis = v -> t.pagesSweptBasis_.Store(v) atomic.Load64(&t.pagesSweptBasis) -> t.pagesSweptBasis_.Load() atomic.LoadAcq64(&t.pagesSweptBasis) -> t.pagesSweptBasis_.LoadAcquire() atomic.Store64(&t.pagesSweptBasis, v) -> t.pagesSweptBasis_.Store(v) atomic.StoreRel64(&t.pagesSweptBasis, v) -> t.pagesSweptBasis_.StoreRelease(v) atomic.Cas64(&t.pagesSweptBasis, v, w) -> t.pagesSweptBasis_.CompareAndSwap(v, w) atomic.Xchg64(&t.pagesSweptBasis, v) -> t.pagesSweptBasis_.Swap(v) atomic.Xadd64(&t.pagesSweptBasis, d) -> t.pagesSweptBasis_.Add(d) } rm mheap.pagesSweptBasis mv mheap.pagesSweptBasis_ mheap.pagesSweptBasis ' mv export.go export_test.go Change-Id: Id9438184b9bd06d96894c02376385bad45dee154 Reviewed-on: https://go-review.googlesource.com/c/go/+/356710 Reviewed-by: Austin Clements Trust: Michael Knyszek --- src/runtime/mgcpacer.go | 2 +- src/runtime/mgcsweep.go | 4 ++-- src/runtime/mheap.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go index f858ab08d0..55f3bc926d 100644 --- a/src/runtime/mgcpacer.go +++ b/src/runtime/mgcpacer.go @@ -762,7 +762,7 @@ func (c *gcControllerState) commit(triggerRatio float64) { // Write pagesSweptBasis last, since this // signals concurrent sweeps to recompute // their debt. - atomic.Store64(&mheap_.pagesSweptBasis, pagesSwept) + mheap_.pagesSweptBasis.Store(pagesSwept) } } diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index 78d1f33925..aedd6c316e 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -719,7 +719,7 @@ func deductSweepCredit(spanBytes uintptr, callerSweepPages uintptr) { } retry: - sweptBasis := atomic.Load64(&mheap_.pagesSweptBasis) + sweptBasis := mheap_.pagesSweptBasis.Load() // Fix debt if necessary. newHeapLive := uintptr(atomic.Load64(&gcController.heapLive)-mheap_.sweepHeapLiveBasis) + spanBytes @@ -729,7 +729,7 @@ retry: mheap_.sweepPagesPerByte = 0 break } - if atomic.Load64(&mheap_.pagesSweptBasis) != sweptBasis { + if mheap_.pagesSweptBasis.Load() != sweptBasis { // Sweep pacing changed. Recompute debt. goto retry } diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 27f60771eb..90e55315a6 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -104,7 +104,7 @@ type mheap struct { // progress has already been made. pagesInUse atomic.Uint64 // pages of spans in stats mSpanInUse pagesSwept atomic.Uint64 // pages swept this cycle - pagesSweptBasis uint64 // pagesSwept to use as the origin of the sweep ratio; updated atomically + pagesSweptBasis atomic.Uint64 // pagesSwept to use as the origin of the sweep ratio sweepHeapLiveBasis uint64 // value of gcController.heapLive 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 -- 2.50.0