Skip to content

Commit 79b43fa

Browse files
committed
runtime: preempt dedicated background mark workers for STW
Currently, dedicated background mark workers are essentially always non-preemptible. This change makes it so that dedicated background mark workers park if their preemption flag is set and someone is trying to STW, allowing them to do so. This change prepares us for allowing a STW to happen (and happen promptly) during GC marking in a follow-up change. Updates #19812. Change-Id: I67fb6085bf0f0aebd18ca500172767818a1f15e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/215157 Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 6197104 commit 79b43fa

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/runtime/mgcmark.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ const (
963963
// credit to gcController.bgScanCredit every gcCreditSlack units of
964964
// scan work.
965965
//
966+
// gcDrain will always return if there is a pending STW.
967+
//
966968
//go:nowritebarrier
967969
func gcDrain(gcw *gcWork, flags gcDrainFlags) {
968970
if !writeBarrier.needed {
@@ -991,7 +993,8 @@ func gcDrain(gcw *gcWork, flags gcDrainFlags) {
991993

992994
// Drain root marking jobs.
993995
if work.markrootNext < work.markrootJobs {
994-
for !(preemptible && gp.preempt) {
996+
// Stop if we're preemptible or if someone wants to STW.
997+
for !(gp.preempt && (preemptible || atomic.Load(&sched.gcwaiting) != 0)) {
995998
job := atomic.Xadd(&work.markrootNext, +1) - 1
996999
if job >= work.markrootJobs {
9971000
break
@@ -1004,7 +1007,8 @@ func gcDrain(gcw *gcWork, flags gcDrainFlags) {
10041007
}
10051008

10061009
// Drain heap marking jobs.
1007-
for !(preemptible && gp.preempt) {
1010+
// Stop if we're preemptible or if someone wants to STW.
1011+
for !(gp.preempt && (preemptible || atomic.Load(&sched.gcwaiting) != 0)) {
10081012
// Try to keep work available on the global queue. We used to
10091013
// check if there were waiting workers, but it's better to
10101014
// just keep work available than to make workers wait. In the

0 commit comments

Comments
 (0)