Skip to content

Commit c4552c1

Browse files
aclementsbradfitz
authored andcommitted
[release-branch.go1.7] runtime: force workers out before checking mark roots
Fixes #18700 (backport) 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/35678 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent faafe0e commit c4552c1

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
@@ -1076,8 +1076,6 @@ top:
10761076
// objects reachable from global roots since they don't have write
10771077
// barriers. Rescan some roots and flush work caches.
10781078

1079-
gcMarkRootCheck()
1080-
10811079
// Disallow caching workbufs and indicate that we're in mark 2.
10821080
gcBlackenPromptly = true
10831081

@@ -1101,6 +1099,16 @@ top:
11011099
})
11021100
})
11031101

1102+
// Check that roots are marked. We should be able to
1103+
// do this before the forEachP, but based on issue
1104+
// #16083 there may be a (harmless) race where we can
1105+
// enter mark 2 while some workers are still scanning
1106+
// stacks. The forEachP ensures these scans are done.
1107+
//
1108+
// TODO(austin): Figure out the race and fix this
1109+
// properly.
1110+
gcMarkRootCheck()
1111+
11041112
// Now we can start up mark 2 workers.
11051113
atomic.Xaddint64(&gcController.dedicatedMarkWorkersNeeded, 0xffffffff)
11061114
atomic.Xaddint64(&gcController.fractionalMarkWorkersNeeded, 0xffffffff)

0 commit comments

Comments
 (0)