aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mheap.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-11-04 14:25:22 -0800
committerIan Lance Taylor <iant@golang.org>2020-02-24 16:39:52 +0000
commit3093959ee10f5c28211094e784c954f6a304b9c9 (patch)
tree52ce31ecacb6575a97097a193bb2abefc620c06c /src/runtime/mheap.go
parent7802b551769c9f39e2b08a13f7ba2b4e5c521f9e (diff)
downloadgo-3093959ee10f5c28211094e784c954f6a304b9c9.tar.gz
go-3093959ee10f5c28211094e784c954f6a304b9c9.zip
runtime: remove mcache field from m
Having an mcache field in both m and p is confusing, so remove it from m. Always use mcache field from p. Use new variable mcache0 during bootstrap. Change-Id: If2cba9f8bb131d911d512b61fd883a86cf62cc98 Reviewed-on: https://go-review.googlesource.com/c/go/+/205239 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mheap.go')
-rw-r--r--src/runtime/mheap.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go
index 5427d8839d..86ecf3377d 100644
--- a/src/runtime/mheap.go
+++ b/src/runtime/mheap.go
@@ -1141,10 +1141,21 @@ func (h *mheap) allocSpan(npages uintptr, manual bool, spanclass spanClass, sysS
// which may only be done with the heap locked.
// Transfer stats from mcache to global.
- memstats.heap_scan += uint64(gp.m.mcache.local_scan)
- gp.m.mcache.local_scan = 0
- memstats.tinyallocs += uint64(gp.m.mcache.local_tinyallocs)
- gp.m.mcache.local_tinyallocs = 0
+ var c *mcache
+ if gp.m.p != 0 {
+ c = gp.m.p.ptr().mcache
+ } else {
+ // This case occurs while bootstrapping.
+ // See the similar code in mallocgc.
+ c = mcache0
+ if c == nil {
+ throw("mheap.allocSpan called with no P")
+ }
+ }
+ memstats.heap_scan += uint64(c.local_scan)
+ c.local_scan = 0
+ memstats.tinyallocs += uint64(c.local_tinyallocs)
+ c.local_tinyallocs = 0
// Do some additional accounting if it's a large allocation.
if spanclass.sizeclass() == 0 {
@@ -1342,12 +1353,12 @@ func (h *mheap) grow(npage uintptr) bool {
// Free the span back into the heap.
func (h *mheap) freeSpan(s *mspan) {
systemstack(func() {
- mp := getg().m
+ c := getg().m.p.ptr().mcache
lock(&h.lock)
- memstats.heap_scan += uint64(mp.mcache.local_scan)
- mp.mcache.local_scan = 0
- memstats.tinyallocs += uint64(mp.mcache.local_tinyallocs)
- mp.mcache.local_tinyallocs = 0
+ memstats.heap_scan += uint64(c.local_scan)
+ c.local_scan = 0
+ memstats.tinyallocs += uint64(c.local_tinyallocs)
+ c.local_tinyallocs = 0
if msanenabled {
// Tell msan that this entire span is no longer in use.
base := unsafe.Pointer(s.base())