aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime2.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2019-09-18 15:57:36 +0000
committerMichael Knyszek <mknyszek@google.com>2019-11-08 17:01:32 +0000
commit4517c02f284cc19262304ba22c1c98b2bbdb0208 (patch)
treeafd70218f58aa49b881c2d5335ccb1a6ffe92e04 /src/runtime/runtime2.go
parenta762221bea7c02a17cffc6937d8af33a027a32e5 (diff)
downloadgo-4517c02f284cc19262304ba22c1c98b2bbdb0208.tar.xz
runtime: add per-p mspan cache
This change adds a per-p mspan object cache similar to the sudog cache. Unfortunately this cache can't quite operate like the sudog cache, since it is used in contexts where write barriers are disallowed (i.e. allocation codepaths), so rather than managing an array and a slice, it's just an array and a length. A little bit more unsafe, but avoids any write barriers. The purpose of this change is to reduce the number of operations which require the heap lock in allocation, paving the way for a lockless fast path. Updates #35112. Change-Id: I32cfdcd8528fb7be985640e4f3a13cb98ffb7865 Reviewed-on: https://go-review.googlesource.com/c/go/+/196642 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/runtime2.go')
-rw-r--r--src/runtime/runtime2.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index a5471ff765..eba2aed092 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -588,6 +588,17 @@ type p struct {
sudogcache []*sudog
sudogbuf [128]*sudog
+ // Cache of mspan objects from the heap.
+ mspancache struct {
+ // We need an explicit length here because this field is used
+ // in allocation codepaths where write barriers are not allowed,
+ // and eliminating the write barrier/keeping it eliminated from
+ // slice updates is tricky, moreso than just managing the length
+ // ourselves.
+ len int
+ buf [128]*mspan
+ }
+
tracebuf traceBufPtr
// traceSweep indicates the sweep events should be traced.
@@ -600,7 +611,7 @@ type p struct {
palloc persistentAlloc // per-P to avoid mutex
- _ uint32 // Alignment for atomic fields below
+ // _ uint32 // Alignment for atomic fields below
// Per-P GC state
gcAssistTime int64 // Nanoseconds in assistAlloc