From 3f86d7cc6762a5f6745cdcda4bd50031bfafc92f Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 25 Sep 2018 15:44:27 -0400 Subject: [PATCH] runtime: tidy mheap.freeSpan freeSpan currently takes a mysterious "acct int32" argument. This is really just a boolean and actually just needs to match the "large" argument to alloc in order to balance out accounting. To make this clearer, replace acct with a "large bool" argument that must match the call to mheap.alloc. Change-Id: Ibc81faefdf9f0583114e1953fcfb362e9c3c76de Reviewed-on: https://go-review.googlesource.com/c/138655 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/mcentral.go | 2 +- src/runtime/mgcsweep.go | 2 +- src/runtime/mheap.go | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runtime/mcentral.go b/src/runtime/mcentral.go index 9ca8e5d222..baede31405 100644 --- a/src/runtime/mcentral.go +++ b/src/runtime/mcentral.go @@ -244,7 +244,7 @@ func (c *mcentral) freeSpan(s *mspan, preserve bool, wasempty bool) bool { c.nonempty.remove(s) unlock(&c.lock) - mheap_.freeSpan(s, 0) + mheap_.freeSpan(s, false) return true } diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index 00950aede2..104bd868fa 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -366,7 +366,7 @@ func (s *mspan) sweep(preserve bool) bool { s.limit = 0 // prevent mlookup from finding this span sysFault(unsafe.Pointer(s.base()), size) } else { - mheap_.freeSpan(s, 1) + mheap_.freeSpan(s, true) } c.local_nlargefree++ c.local_largefree += size diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 1d672cdf21..48b3f5364a 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -945,7 +945,10 @@ func (h *mheap) grow(npage uintptr) bool { } // Free the span back into the heap. -func (h *mheap) freeSpan(s *mspan, acct int32) { +// +// large must match the value of large passed to mheap.alloc. This is +// used for accounting. +func (h *mheap) freeSpan(s *mspan, large bool) { systemstack(func() { mp := getg().m lock(&h.lock) @@ -959,7 +962,8 @@ func (h *mheap) freeSpan(s *mspan, acct int32) { bytes := s.npages << _PageShift msanfree(base, bytes) } - if acct != 0 { + if large { + // Match accounting done in mheap.alloc. memstats.heap_objects-- } if gcBlackenEnabled != 0 { -- 2.48.1