aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2020-11-02 16:58:38 +0000
committerMichael Knyszek <mknyszek@google.com>2020-11-02 21:10:41 +0000
commitac766e37182f36cd0a3247e44a4143d2d2132e42 (patch)
treec42b32e149d0113aa9ba5e2f3cd2694bec02d502 /src/runtime/malloc.go
parent4fcb5068f6aa907166535531862cfd4a3dec6be7 (diff)
downloadgo-ac766e37182f36cd0a3247e44a4143d2d2132e42.tar.gz
go-ac766e37182f36cd0a3247e44a4143d2d2132e42.zip
runtime: make getMCache inlineable
This change moves the responsibility of throwing if an mcache is not available to the caller, because the inlining cost of throw is set very high in the compiler. Even if it was reduced down to the cost of a usual function call, it would still be too expensive, so just move it out. This choice also makes sense in the context of #42339 since we're going to have to handle the case where we don't have an mcache to update stats in a few contexts anyhow. Also, add getMCache to the list of functions that should be inlined to prevent future regressions. getMCache is called on the allocation fast path and because its not inlined actually causes a significant regression (~10%) in some microbenchmarks. Fixes #42305. Change-Id: I64ac5e4f26b730bd4435ea1069a4a50f55411ced Reviewed-on: https://go-review.googlesource.com/c/go/+/267157 Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 4b798d129c..551acd0796 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -975,6 +975,9 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
shouldhelpgc := false
dataSize := size
c := getMCache()
+ if c == nil {
+ throw("mallocgc called without a P or outside bootstrapping")
+ }
var span *mspan
var x unsafe.Pointer
noscan := typ == nil || typ.ptrdata == 0
@@ -1202,7 +1205,11 @@ func reflect_unsafe_NewArray(typ *_type, n int) unsafe.Pointer {
}
func profilealloc(mp *m, x unsafe.Pointer, size uintptr) {
- getMCache().nextSample = nextSample()
+ c := getMCache()
+ if c == nil {
+ throw("profilealloc called without a P or outside bootstrapping")
+ }
+ c.nextSample = nextSample()
mProf_Malloc(x, size)
}