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>
This commit is contained in:
Michael Anthony Knyszek 2020-11-02 16:58:38 +00:00 committed by Michael Knyszek
parent 4fcb5068f6
commit ac766e3718
5 changed files with 26 additions and 6 deletions

View file

@ -1247,6 +1247,10 @@ HaveSpan:
}
// Update consistent stats.
c := getMCache()
if c == nil {
// TODO(mknyszek): Remove this and handle this case to fix #42339.
throw("allocSpan called without P or outside bootstrapping")
}
stats := memstats.heapStats.acquire(c)
atomic.Xaddint64(&stats.committed, int64(scav))
atomic.Xaddint64(&stats.released, -int64(scav))
@ -1341,6 +1345,10 @@ func (h *mheap) grow(npage uintptr) bool {
// just add directly to heap_released.
atomic.Xadd64(&memstats.heap_released, int64(asize))
c := getMCache()
if c == nil {
// TODO(mknyszek): Remove this and handle this case to fix #42339.
throw("grow called without P or outside bootstrapping")
}
stats := memstats.heapStats.acquire(c)
atomic.Xaddint64(&stats.released, int64(asize))
memstats.heapStats.release(c)
@ -1440,6 +1448,10 @@ func (h *mheap) freeSpanLocked(s *mspan, typ spanAllocType) {
}
// Update consistent stats.
c := getMCache()
if c == nil {
// TODO(mknyszek): Remove this and handle this case to fix #42339.
throw("freeSpanLocked called without P or outside bootstrapping")
}
stats := memstats.heapStats.acquire(c)
switch typ {
case spanAllocHeap: