]> Cypherpunks repositories - gostls13.git/commit
runtime: fix sweep termination condition
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 8 Jul 2021 21:42:01 +0000 (21:42 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 29 Oct 2021 17:12:47 +0000 (17:12 +0000)
commit3aecb3a8f7e1435c76003a20068c0208fd73649a
tree2862c933092a5dcf54f70bb397bfc0ebfd259ad9
parentf2885263748364a2a7f4e0d47abd5095699cd39f
runtime: fix sweep termination condition

Currently, there is a chance that the sweep termination condition could
flap, causing e.g. runtime.GC to return before all sweep work has not
only been drained, but also completed. CL 307915 and CL 307916 attempted
to fix this problem, but it is still possible that mheap_.sweepDrained is
marked before any outstanding sweepers are accounted for in
mheap_.sweepers, leaving a window in which a thread could observe
isSweepDone as true before it actually was (and after some time it would
revert to false, then true again, depending on the number of outstanding
sweepers at that point).

This change fixes the sweep termination condition by merging
mheap_.sweepers and mheap_.sweepDrained into a single atomic value.

This value is updated such that a new potential sweeper will increment
the oustanding sweeper count iff there are still outstanding spans to be
swept without an outstanding sweeper to pick them up. This design
simplifies the sweep termination condition into a single atomic load and
comparison and ensures the condition never flaps.

Updates #46500.
Fixes #45315.

Change-Id: I6d69aff156b8d48428c4cc8cfdbf28be346dbf04
Reviewed-on: https://go-review.googlesource.com/c/go/+/333389
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mcentral.go
src/runtime/mgc.go
src/runtime/mgcsweep.go
src/runtime/mheap.go
src/runtime/pprof/mprof_test.go