aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mcentral.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-04-14 13:52:27 -0400
committerAustin Clements <austin@google.com>2017-04-19 18:31:11 +0000
commit79c56addb680b04804e1c3553ba96760d0172d55 (patch)
tree31668ce20720b85326258eb97cb520968f3a8c81 /src/runtime/mcentral.go
parentfb28f5ba3aa1ca704295b9960c332b0178335788 (diff)
downloadgo-79c56addb680b04804e1c3553ba96760d0172d55.tar.gz
go-79c56addb680b04804e1c3553ba96760d0172d55.zip
runtime: make sweep trace events encompass entire sweep loop
Currently, each individual span sweep emits a span to the trace. But sweeps are generally done in loops until some condition is satisfied, so this tracing is lower-level than anyone really wants any hides the fact that no other work is being accomplished between adjacent sweep events. This is also high overhead: enabling tracing significantly impacts sweep latency. Replace this with instead tracing around the sweep loops used for allocation. This is slightly tricky because sweep loops don't generally know if any sweeping will happen in them. Hence, we make the tracing lazy by recording in the P that we would like to start tracing the sweep *if* one happens, and then only closing the sweep event if we started it. This does mean we don't get tracing on every sweep path, which are legion. However, we get much more informative tracing on the paths that block allocation, which are the paths that matter. Change-Id: I73e14fbb250acb0c9d92e3648bddaa5e7d7e271c Reviewed-on: https://go-review.googlesource.com/40810 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/mcentral.go')
-rw-r--r--src/runtime/mcentral.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/runtime/mcentral.go b/src/runtime/mcentral.go
index be3820a9a5..8f9c529539 100644
--- a/src/runtime/mcentral.go
+++ b/src/runtime/mcentral.go
@@ -43,6 +43,10 @@ func (c *mcentral) cacheSpan() *mspan {
deductSweepCredit(spanBytes, 0)
lock(&c.lock)
+ traceDone := false
+ if trace.enabled {
+ traceGCSweepStart()
+ }
sg := mheap_.sweepgen
retry:
var s *mspan
@@ -92,6 +96,10 @@ retry:
// all subsequent ones must also be either swept or in process of sweeping
break
}
+ if trace.enabled {
+ traceGCSweepDone()
+ traceDone = true
+ }
unlock(&c.lock)
// Replenish central list if empty.
@@ -106,6 +114,9 @@ retry:
// At this point s is a non-empty span, queued at the end of the empty list,
// c is unlocked.
havespan:
+ if trace.enabled && !traceDone {
+ traceGCSweepDone()
+ }
cap := int32((s.npages << _PageShift) / s.elemsize)
n := cap - int32(s.allocCount)
if n == 0 || s.freeindex == s.nelems || uintptr(s.allocCount) == s.nelems {