• Austin Clements's avatar
    runtime: wake idle Ps when enqueuing GC work · 0bae74e8
    Austin Clements authored
    If the scheduler has no user work and there's no GC work visible, it
    puts the P to sleep (or blocks on the network). However, if we later
    enqueue more GC work, there's currently nothing that specifically
    wakes up the scheduler to let it start an idle GC worker. As a result,
    we can underutilize the CPU during GC if Ps have been put to sleep.
    
    Fix this by making GC wake idle Ps when work buffers are put on the
    full list. We already have a hook to do this, since we use this to
    preempt a random P if we need more dedicated workers. We expand this
    hook to instead wake an idle P if there is one. The logic we use for
    this is identical to the logic used to wake an idle P when we ready a
    goroutine.
    
    To make this really sound, we also fix the scheduler to re-check the
    idle GC worker condition after releasing its P. This closes a race
    where 1) the scheduler checks for idle work and finds none, 2) new
    work is enqueued but there are no idle Ps so none are woken, and 3)
    the scheduler releases its P.
    
    There is one subtlety here. Currently we call enlistWorker directly
    from putfull, but the gcWork is in an inconsistent state in the places
    that call putfull. This isn't a problem right now because nothing that
    enlistWorker does touches the gcWork, but with the added call to
    wakep, it's possible to get a recursive call into the gcWork
    (specifically, while write barriers are disallowed, this can do an
    allocation, which can dispose a gcWork, which can put a workbuf). To
    handle this, we lift the enlistWorker calls up a layer and delay them
    until the gcWork is in a consistent state.
    
    Fixes #14179.
    
    Change-Id: Ia2467a52e54c9688c3c1752e1fc00f5b37bbfeeb
    Reviewed-on: https://go-review.googlesource.com/32434
    Run-TryBot: Austin Clements <austin@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarDmitry Vyukov <dvyukov@google.com>
    0bae74e8
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
plugin Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...