aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mgcsweep.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-02-26 21:57:16 +0100
committerDmitry Vyukov <dvyukov@google.com>2016-05-03 11:00:43 +0000
commitcaa21475328999c1cd108b71ceb6efb7f4cf8fc4 (patch)
tree9555dae9965819297a5f490ca45c6c4c8cf2c1e8 /src/runtime/mgcsweep.go
parentfcd7c02c70a110c6f6dbac30ad4ac3eb435ac3fd (diff)
downloadgo-caa21475328999c1cd108b71ceb6efb7f4cf8fc4.tar.gz
go-caa21475328999c1cd108b71ceb6efb7f4cf8fc4.zip
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>
Diffstat (limited to 'src/runtime/mgcsweep.go')
-rw-r--r--src/runtime/mgcsweep.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go
index b8e33897c1..947c38e400 100644
--- a/src/runtime/mgcsweep.go
+++ b/src/runtime/mgcsweep.go
@@ -251,7 +251,7 @@ func (s *mspan) sweep(preserve bool) bool {
}
}
- if debug.allocfreetrace != 0 {
+ if debug.allocfreetrace != 0 || raceenabled || msanenabled {
// Find all newly freed objects. This doesn't have to
// efficient; allocfreetrace has massive overhead.
mbits := s.markBitsForBase()
@@ -259,7 +259,15 @@ func (s *mspan) sweep(preserve bool) bool {
for i := uintptr(0); i < s.nelems; i++ {
if !mbits.isMarked() && (abits.index < s.freeindex || abits.isMarked()) {
x := s.base() + i*s.elemsize
- tracefree(unsafe.Pointer(x), size)
+ if debug.allocfreetrace != 0 {
+ tracefree(unsafe.Pointer(x), size)
+ }
+ if raceenabled {
+ racefree(unsafe.Pointer(x), size)
+ }
+ if msanenabled {
+ msanfree(unsafe.Pointer(x), size)
+ }
}
mbits.advance()
abits.advance()