From: Leonard Wang Date: Sun, 24 Apr 2022 04:14:13 +0000 (+0800) Subject: runtime: set userForced while holding gcsema X-Git-Tag: go1.20rc1~1068 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6f7c9ea855b1ae97871837abf33b85aaa6731eae;p=gostls13.git runtime: set userForced while holding gcsema Fixes #52515 Change-Id: If10068a97733daf61aba72da5ed3935db8eed8b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/401776 Reviewed-by: hopehook Run-TryBot: hopehook Reviewed-by: Michael Knyszek Auto-Submit: Jenny Rakoczy Run-TryBot: Michael Knyszek Reviewed-by: Jenny Rakoczy TryBot-Result: Gopher Robot --- diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 3243a15b4d..f7e54d3dd3 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -612,9 +612,6 @@ func gcStart(trigger gcTrigger) { return } - // For stats, check if this GC was forced by the user. - work.userForced = trigger.kind == gcTriggerCycle - // In gcstoptheworld debug mode, upgrade the mode accordingly. // We do this after re-checking the transition condition so // that multiple goroutines that detect the heap trigger don't @@ -630,6 +627,10 @@ func gcStart(trigger gcTrigger) { semacquire(&gcsema) semacquire(&worldsema) + // For stats, check if this GC was forced by the user. + // Update it under gcsema to avoid gctrace getting wrong values. + work.userForced = trigger.kind == gcTriggerCycle + if trace.enabled { traceGCStart() }