]> Cypherpunks repositories - gostls13.git/commit
runtime: buffered write barrier implementation
authorAustin Clements <austin@google.com>
Thu, 26 Oct 2017 16:21:16 +0000 (12:21 -0400)
committerAustin Clements <austin@google.com>
Mon, 30 Oct 2017 18:12:44 +0000 (18:12 +0000)
commite9079a69f34365e99a4787f2e2e463cab8429a66
tree0b92628a6e7947f9b086a97e14eacb8ff85f624d
parent1e8ab99b37dd67aaf7b188be743bdb938005df7a
runtime: buffered write barrier implementation

This implements runtime support for buffered write barriers on amd64.
The buffered write barrier has a fast path that simply enqueues
pointers in a per-P buffer. Unlike the current write barrier, this
fast path is *not* a normal Go call and does not require the compiler
to spill general-purpose registers or put arguments on the stack. When
the buffer fills up, the write barrier takes the slow path, which
spills all general purpose registers and flushes the buffer. We don't
allow safe-points or stack splits while this frame is active, so it
doesn't matter that we have no type information for the spilled
registers in this frame.

One minor complication is cgocheck=2 mode, which uses the write
barrier to detect Go pointers being written to non-Go memory. We
obviously can't buffer this, so instead we set the buffer to its
minimum size, forcing the write barrier into the slow path on every
call. For this specific case, we pass additional information as
arguments to the flush function. This also requires enabling the cgo
write barrier slightly later during runtime initialization, after Ps
(and the per-P write barrier buffers) have been initialized.

The code in this CL is not yet active. The next CL will modify the
compiler to generate calls to the new write barrier.

This reduces the average cost of the write barrier by roughly a factor
of 4, which will pay for the cost of having it enabled more of the
time after we make the GC pacer less aggressive. (Benchmarks will be
in the next CL.)

Updates #14951.
Updates #22460.

Change-Id: I396b5b0e2c5e5c4acfd761a3235fd15abadc6cb1
Reviewed-on: https://go-review.googlesource.com/73711
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/cmd/vet/all/whitelist/amd64.txt
src/runtime/asm_amd64.s
src/runtime/cgocheck.go
src/runtime/mgc.go
src/runtime/mgcmark.go
src/runtime/mgcwork.go
src/runtime/mwbbuf.go [new file with mode: 0644]
src/runtime/proc.go
src/runtime/runtime1.go
src/runtime/runtime2.go