aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mpagealloc_test.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2020-07-27 15:04:17 -0400
committerMichael Pratt <mpratt@google.com>2020-07-28 16:59:04 +0000
commit85afa2eb190d5d1a06584803bde4b4ee9b0e79b0 (patch)
tree1ed8494c2f4d84deba043e9da13bf611bc417579 /src/runtime/mpagealloc_test.go
parentc4fed25553ee266ed9cb3a98e7a33a82af110ed4 (diff)
downloadgo-85afa2eb190d5d1a06584803bde4b4ee9b0e79b0.tar.xz
runtime: ensure startm new M is consistently visible to checkdead
If no M is available, startm first grabs an idle P, then drops sched.lock and calls newm to start a new M to run than P. Unfortunately, that leaves a window in which a G (e.g., returning from a syscall) may find no idle P, add to the global runq, and then in stopm discover that there are no running M's, a condition that should be impossible with runnable G's. To avoid this condition, we pre-allocate the new M ID in startm before dropping sched.lock. This ensures that checkdead will see the M as running, and since that new M must eventually run the scheduler, it will handle any pending work as necessary. Outside of startm, most other calls to newm/allocm don't have a P at all. The only exception is startTheWorldWithSema, which always has an M if there is 1 P (i.e., the currently running M), and if there is >1 P the findrunnable spinning dance ensures the problem never occurs. This has been tested with strategically placed sleeps in the runtime to help induce the correct race ordering, but the timing on this is too narrow for a test that can be checked in. Fixes #40368 Change-Id: If5e0293a430cc85154b7ed55bc6dadf9b340abe2 Reviewed-on: https://go-review.googlesource.com/c/go/+/245018 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mpagealloc_test.go')
0 files changed, 0 insertions, 0 deletions