Skip to content

Commit

Permalink
[release-branch.go1.7] runtime: force workers out before checking mar…
Browse files Browse the repository at this point in the history
…k 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]>
  • Loading branch information
aclements authored and bradfitz committed Jan 25, 2017
1 parent faafe0e commit c4552c1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/runtime/mgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,6 @@ top:
// objects reachable from global roots since they don't have write
// barriers. Rescan some roots and flush work caches.

gcMarkRootCheck()

// Disallow caching workbufs and indicate that we're in mark 2.
gcBlackenPromptly = true

Expand All @@ -1101,6 +1099,16 @@ top:
})
})

// Check that roots are marked. We should be able to
// do this before the forEachP, but based on issue
// #16083 there may be a (harmless) race where we can
// enter mark 2 while some workers are still scanning
// stacks. The forEachP ensures these scans are done.
//
// TODO(austin): Figure out the race and fix this
// properly.
gcMarkRootCheck()

// Now we can start up mark 2 workers.
atomic.Xaddint64(&gcController.dedicatedMarkWorkersNeeded, 0xffffffff)
atomic.Xaddint64(&gcController.fractionalMarkWorkersNeeded, 0xffffffff)
Expand Down

0 comments on commit c4552c1

Please sign in to comment.