Skip to content

Commit c1730ae

Browse files
committed
runtime: force workers out before checking mark roots
Currently we check that all roots are marked as soon as gcMarkDone decides to transition from mark 1 to mark 2. However, issue #16083 indicates that there may be a race where we try to complete mark 1 while a worker is still scanning a stack, causing the root mark check to fail. We don't yet understand this race, but as a simple mitigation, move the root check to after gcMarkDone performs a ragged barrier, which will force any remaining workers to finish their current job. Updates #16083. This may "fix" it, but it would be better to understand and fix the underlying race. Change-Id: I1af9ce67bd87ade7bc2a067295d79c28cd11abd2 Reviewed-on: https://go-review.googlesource.com/35353 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Rick Hudson <[email protected]>
1 parent d10eddc commit c1730ae

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/runtime/mgc.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,8 +1129,6 @@ top:
11291129
// sitting in the per-P work caches.
11301130
// Flush and disable work caches.
11311131

1132-
gcMarkRootCheck()
1133-
11341132
// Disallow caching workbufs and indicate that we're in mark 2.
11351133
gcBlackenPromptly = true
11361134

@@ -1153,6 +1151,16 @@ top:
11531151
})
11541152
})
11551153

1154+
// Check that roots are marked. We should be able to
1155+
// do this before the forEachP, but based on issue
1156+
// #16083 there may be a (harmless) race where we can
1157+
// enter mark 2 while some workers are still scanning
1158+
// stacks. The forEachP ensures these scans are done.
1159+
//
1160+
// TODO(austin): Figure out the race and fix this
1161+
// properly.
1162+
gcMarkRootCheck()
1163+
11561164
// Now we can start up mark 2 workers.
11571165
atomic.Xaddint64(&gcController.dedicatedMarkWorkersNeeded, 0xffffffff)
11581166
atomic.Xaddint64(&gcController.fractionalMarkWorkersNeeded, 0xffffffff)

0 commit comments

Comments
 (0)