1
0
mirror of https://github.com/golang/go synced 2024-11-24 04:00:13 -07:00
go/src
Austin Clements 9108ae7751 runtime: eliminate mark 2 and fix mark termination race
The mark 2 phase was originally introduced as a way to reduce the
chance of entering STW mark termination while there was still marking
work to do. It works by flushing and disabling all local work caches
so that all enqueued work becomes immediately globally visible.
However, mark 2 is not only slow–disabling caches makes marking and
the write barrier both much more expensive–but also imperfect. There
is still a rare but possible race (~once per all.bash) that can cause
GC to enter mark termination while there is still marking work. This
race is detailed at
https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md#appendix-mark-completion-race
The effect of this is that mark termination must still cope with the
possibility that there may be work remaining after a concurrent mark
phase. Dealing with this increases STW pause time and increases the
complexity of mark termination.

Furthermore, a similar but far more likely race can cause early
transition from mark 1 to mark 2. This is unfortunate because it
causes performance instability because of the cost of mark 2.

This CL fixes this by replacing mark 2 with a distributed termination
detection algorithm. This algorithm is correct, so it eliminates the
mark termination race, and doesn't require disabling local caches. It
ensures that there are no grey objects upon entering mark termination.
With this change, we're one step closer to eliminating marking from
mark termination entirely (it's still used by STW GC and checkmarks
mode).

This CL does not eliminate the gcBlackenPromptly global flag, though
it is always set to false now. It will be removed in a cleanup CL.

This led to only minor variations in the go1 benchmarks
(https://perf.golang.org/search?q=upload:20180909.1) and compilebench
benchmarks (https://perf.golang.org/search?q=upload:20180910.2).

This significantly improves performance of the garbage benchmark, with
no impact on STW times:

name                        old time/op    new time/op   delta
Garbage/benchmem-MB=64-12    2.21ms ± 1%   2.05ms ± 1%   -7.38% (p=0.000 n=18+19)
Garbage/benchmem-MB=1024-12  2.30ms ±16%   2.20ms ± 7%   -4.51% (p=0.001 n=20+20)

name                        old STW-ns/GC  new STW-ns/GC  delta
Garbage/benchmem-MB=64-12      138k ±44%     141k ±23%     ~    (p=0.309 n=19+20)
Garbage/benchmem-MB=1024-12    159k ±25%     178k ±98%     ~    (p=0.798 n=16+18)

name                        old STW-ns/op  new STW-ns/op                delta
Garbage/benchmem-MB=64-12     4.42k ±44%    4.24k ±23%     ~    (p=0.531 n=19+20)
Garbage/benchmem-MB=1024-12     591 ±24%      636 ±111%    ~    (p=0.309 n=16+18)

(https://perf.golang.org/search?q=upload:20180910.1)

Updates #26903.
Updates #17503.

Change-Id: Icbd1e12b7a12a76f423c9bf033b13cb363e4cd19
Reviewed-on: https://go-review.googlesource.com/c/134318
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
2018-10-02 20:35:20 +00:00
..
archive
bufio
builtin builtin: document when len and cap are constant 2018-09-18 21:52:11 +00:00
bytes bytes, strings: add ReplaceAll 2018-09-26 20:51:23 +00:00
cmd cmd/compile: instrinsify math/bits.Mul on ppc64x 2018-10-02 18:56:06 +00:00
compress Revert "compress: move benchmark text from src/testdata to src/compress/testdata" 2018-10-01 16:16:21 +00:00
container
context
crypto all: remove repeated "the" from comments 2018-09-28 08:46:55 +00:00
database/sql database/sql: correctly report MaxIdleClosed stat 2018-10-02 19:24:37 +00:00
debug
encoding all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
errors
expvar
flag all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
fmt fmt: unify the printing examples 2018-09-24 21:15:52 +00:00
go go/build, runtime/internal/sys: add GOOS=aix 2018-09-28 13:45:09 +00:00
hash
html all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
image image: optimize bounds checking for At and Set methods 2018-10-01 19:16:00 +00:00
index/suffixarray
internal go/build: move isStandardPackage to new internal/goroot package 2018-09-25 22:07:43 +00:00
io
log
math cmd/compile: optimize math.Float64(32)bits and math.Float64(32)frombits on arm64 2018-09-17 20:49:04 +00:00
mime all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
net net/http: document Header.Set canonicalizes the header key 2018-10-02 17:07:42 +00:00
os os: use FILE_FLAG_OPEN_REPARSE_POINT in SameFile 2018-09-29 04:02:38 +00:00
path path/filepath: fix Windows-specific Clean bug 2018-09-29 04:26:02 +00:00
plugin
reflect reflect: fix s390x reflect method calls 2018-09-30 20:30:55 +00:00
regexp regexp: fix incorrect name in Match doc comment 2018-09-13 16:29:06 +00:00
runtime runtime: eliminate mark 2 and fix mark termination race 2018-10-02 20:35:20 +00:00
sort
strconv
strings all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
sync sync: simplify (*entry).tryStore 2018-09-27 21:44:20 +00:00
syscall syscall: replace lstat, lchown, stat to please Android O 2018-09-24 17:08:51 +00:00
testdata Revert "compress: move benchmark text from src/testdata to src/compress/testdata" 2018-10-01 16:16:21 +00:00
testing all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
text all: use strings.ReplaceAll and bytes.ReplaceAll where applicable 2018-09-26 22:14:25 +00:00
time time: return ENOENT from androidLoadTzinfoFromTzdata if zone not found 2018-09-15 14:58:35 +00:00
unicode
unsafe
vendor/golang_org/x
all.bash
all.bat
all.rc
androidtest.bash
bootstrap.bash
buildall.bash
clean.bash
clean.bat
clean.rc
cmp.bash
iostest.bash
make.bash
make.bat
Make.dist
make.rc
naclmake.bash
nacltest.bash
race.bash
race.bat
run.bash
run.bat
run.rc