aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2025-05-07 22:28:23 +0000
committerMichael Knyszek <mknyszek@google.com>2025-05-08 07:50:10 -0700
commitad7a6f81597fae99f2d94dda308bdc19ff8c1362 (patch)
tree0f06d0c6fa07ca80f0bff9449c43feceecc76dc0 /src
parent509c11f3a39aeb627cc16dc9ffcad45fc457c5ec (diff)
downloadgo-ad7a6f81597fae99f2d94dda308bdc19ff8c1362.tar.xz
runtime: fix condition to emit gcpacertrace end-of-sweep line
It's the job of the last sweeper to emit the GC pacer trace. The last sweeper can identify themselves by reducing the count of sweepers, and also seeing that there's no more sweep work. Currently this identification is broken, however, because the last sweeper doesn't check the state they just transitioned sweeping into, but rather the state they transitioned from (one sweeper, no sweep work left). By design, it's impossible to transition *out* of this state, except for another GC to start, but that doesn't take this codepath. This means lines like pacer: sweep done at heap size ... were missing from the gcpacertrace output for a long time. This change fixes this problem by having the last sweeper check the state they just transitioned sweeping to, instead of the state they transitioned from. Change-Id: I44bcd32fe2c8ae6ac6c21ba6feb2e7b9e17f60cc Reviewed-on: https://go-review.googlesource.com/c/go/+/670735 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/mgcsweep.go3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go
index 1a9c3b3e5f..191935dfd5 100644
--- a/src/runtime/mgcsweep.go
+++ b/src/runtime/mgcsweep.go
@@ -169,9 +169,10 @@ func (a *activeSweep) end(sl sweepLocker) {
throw("mismatched begin/end of activeSweep")
}
if a.state.CompareAndSwap(state, state-1) {
- if state != sweepDrainedMask {
+ if state-1 != sweepDrainedMask {
return
}
+ // We're the last sweeper, and there's nothing left to sweep.
if debug.gcpacertrace > 0 {
live := gcController.heapLive.Load()
print("pacer: sweep done at heap size ", live>>20, "MB; allocated ", (live-mheap_.sweepHeapLiveBasis)>>20, "MB during sweep; swept ", mheap_.pagesSwept.Load(), " pages at ", mheap_.sweepPagesPerByte, " pages/byte\n")