diff options
author | Michael Pratt <mpratt@google.com> | 2020-12-23 15:05:37 -0500 |
---|---|---|
committer | Michael Pratt <mpratt@google.com> | 2021-03-05 22:09:52 +0000 |
commit | d85083911d6ea742901933a544467dad55bb381f (patch) | |
tree | f8f826d01c3ff45af5908c8a1d71befe4439f97c /src/runtime/mgc.go | |
parent | 39bdd41d03725878f1fd6f8b500ba6700f03bdad (diff) | |
download | go-d85083911d6ea742901933a544467dad55bb381f.tar.gz go-d85083911d6ea742901933a544467dad55bb381f.zip |
runtime: encapsulate access to allgs
Correctly accessing allgs is a bit hairy. Some paths need to lock
allglock, some don't. Those that don't are safest using atomicAllG, but
usage is not consistent.
Rather than doing this ad-hoc, move all access* through forEachG /
forEachGRace, the locking and atomic versions, respectively. This will
make it easier to ensure safe access.
* markroot is the only exception, as it has a far-removed guarantee of
safe access via an atomic load of allglen far before actual use.
Change-Id: Ie1c7a8243e155ae2b4bc3143577380c695680e89
Reviewed-on: https://go-review.googlesource.com/c/go/+/279994
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/mgc.go')
-rw-r--r-- | src/runtime/mgc.go | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 7c7239beb8..6927e90daa 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -2229,14 +2229,12 @@ func gcSweep(mode gcMode) { // //go:systemstack func gcResetMarkState() { - // This may be called during a concurrent phase, so make sure + // This may be called during a concurrent phase, so lock to make sure // allgs doesn't change. - lock(&allglock) - for _, gp := range allgs { + forEachG(func(gp *g) { gp.gcscandone = false // set to true in gcphasework gp.gcAssistBytes = 0 - } - unlock(&allglock) + }) // Clear page marks. This is just 1MB per 64GB of heap, so the // time here is pretty trivial. |