]> Cypherpunks repositories - gostls13.git/commit
runtime: per-P contexts for race detector
authorDmitry Vyukov <dvyukov@google.com>
Fri, 26 Feb 2016 20:57:16 +0000 (21:57 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 3 May 2016 11:00:43 +0000 (11:00 +0000)
commitcaa21475328999c1cd108b71ceb6efb7f4cf8fc4
tree9555dae9965819297a5f490ca45c6c4c8cf2c1e8
parentfcd7c02c70a110c6f6dbac30ad4ac3eb435ac3fd
runtime: per-P contexts for race detector

Race runtime also needs local malloc caches and currently uses
a mix of per-OS-thread and per-goroutine caches. This leads to
increased memory consumption. But more importantly cache of
synchronization objects is per-goroutine and we don't always
have goroutine context when feeing memory in GC. As the result
synchronization object descriptors leak (more precisely, they
can be reused if another synchronization object is recreated
at the same address, but it does not always help). For example,
the added BenchmarkSyncLeak has effectively runaway memory
consumption (based on a real long running server).

This change updates race runtime with support for per-P contexts.
BenchmarkSyncLeak now stabilizes at ~1GB memory consumption.

Long term, this will allow us to remove race runtime dependency
on glibc (as malloc is the main cornerstone).

I've also implemented a different scheme to pass P context to
race runtime: scheduler notified race runtime about association
between G and P by calling procwire(g, p)/procunwire(g, p).
But it turned out to be very messy as we have lots of places
where the association changes (e.g. syscalls). So I dropped it
in favor of the current scheme: race runtime asks scheduler
about the current P.

Fixes #14533

Change-Id: Iad10d2f816a44affae1b9fed446b3580eafd8c69
Reviewed-on: https://go-review.googlesource.com/19970
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
13 files changed:
src/runtime/mgcsweep.go
src/runtime/proc.go
src/runtime/race.go
src/runtime/race/README
src/runtime/race/output_test.go
src/runtime/race/race_darwin_amd64.syso
src/runtime/race/race_freebsd_amd64.syso
src/runtime/race/race_linux_amd64.syso
src/runtime/race/race_test.go
src/runtime/race/race_windows_amd64.syso
src/runtime/race0.go
src/runtime/race_amd64.s
src/runtime/runtime2.go