• Rick Hudson's avatar
    runtime: reduce thrashing of gs between ps · c4fe5031
    Rick Hudson authored
    One important use case is a pipeline computation that pass values
    from one Goroutine to the next and then exits or is placed in a
    wait state. If GOMAXPROCS > 1 a Goroutine running on P1 will enable
    another Goroutine and then immediately make P1 available to execute
    it. We need to prevent other Ps from stealing the G that P1 is about
    to execute. Otherwise the Gs can thrash between Ps causing unneeded
    synchronization and slowing down throughput.
    
    Fix this by changing the stealing logic so that when a P attempts to
    steal the only G on some other P's run queue, it will pause
    momentarily to allow the victim P to schedule the G.
    
    As part of optimizing stealing we also use a per P victim queue
    move stolen gs. This eliminates the zeroing of a stack local victim
    queue which turned out to be expensive.
    
    This CL is a necessary but not sufficient prerequisite to changing
    the default value of GOMAXPROCS to something > 1 which is another
    CL/discussion.
    
    For highly serialized programs, such as GoroutineRing below this can
    make a large difference. For larger and more parallel programs such
    as the x/benchmarks there is no noticeable detriment.
    
    ~/work/code/src/rsc.io/benchstat/benchstat old.txt new.txt
    name                old mean              new mean              delta
    GoroutineRing       30.2µs × (0.98,1.01)  30.1µs × (0.97,1.04)     ~    (p=0.941)
    GoroutineRing-2      113µs × (0.91,1.07)    30µs × (0.98,1.03)  -73.17% (p=0.004)
    GoroutineRing-4      144µs × (0.98,1.02)    32µs × (0.98,1.01)  -77.69% (p=0.000)
    GoroutineRingBuf    32.7µs × (0.97,1.03)  32.5µs × (0.97,1.02)     ~    (p=0.795)
    GoroutineRingBuf-2   120µs × (0.92,1.08)    33µs × (1.00,1.00)  -72.48% (p=0.004)
    GoroutineRingBuf-4   138µs × (0.92,1.06)    33µs × (1.00,1.00)  -76.21% (p=0.003)
    
    The bench benchmarks show little impact.
        	  	      old  	 new
    garbage	      	      7032879	 7011696
    httpold		        25509	   25301
    splayold	      1022073	 1019499
    jsonold		     28230624   28081433
    
    Change-Id: I228c48fed8d85c9bbef16a7edc53ab7898506f50
    Reviewed-on: https://go-review.googlesource.com/9872Reviewed-by: 's avatarAustin Clements <austin@google.com>
    c4fe5031
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...
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...
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...
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...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc 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...