diff --git a/src/runtime/mcentral.go b/src/runtime/mcentral.go index cd5901054ae..2f97b7d0946 100644 --- a/src/runtime/mcentral.go +++ b/src/runtime/mcentral.go @@ -243,7 +243,7 @@ func (c *mcentral) freeSpan(s *mspan, preserve bool, wasempty bool) bool { c.nonempty.remove(s) unlock(&c.lock) - mheap_.freeSpan(s, false) + mheap_.freeSpan(s) return true } diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index 580de7a7153..b95c7f13a4a 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -386,7 +386,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, true) + mheap_.freeSpan(s) } c.local_nlargefree++ c.local_largefree += size diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index c2a23267bcb..f9039f78ca3 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -926,7 +926,6 @@ func (h *mheap) alloc_m(npage uintptr, spanclass spanClass, large bool) *mspan { // update stats, sweep lists h.pagesInUse += uint64(npage) if large { - memstats.heap_objects++ mheap_.largealloc += uint64(s.elemsize) mheap_.nlargealloc++ atomic.Xadd64(&memstats.heap_live, int64(npage<<_PageShift)) @@ -1201,10 +1200,7 @@ func (h *mheap) grow(npage uintptr) bool { } // Free the span back into the heap. -// -// large must match the value of large passed to mheap.alloc. This is -// used for accounting. -func (h *mheap) freeSpan(s *mspan, large bool) { +func (h *mheap) freeSpan(s *mspan) { systemstack(func() { mp := getg().m lock(&h.lock) @@ -1218,10 +1214,6 @@ func (h *mheap) freeSpan(s *mspan, large bool) { bytes := s.npages << _PageShift msanfree(base, bytes) } - if large { - // Match accounting done in mheap.alloc. - memstats.heap_objects-- - } if gcBlackenEnabled != 0 { // heap_scan changed. gcController.revise() diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index 09dbb267355..a6866e3a157 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -40,7 +40,10 @@ type mstats struct { heap_idle uint64 // bytes in idle spans heap_inuse uint64 // bytes in mSpanInUse spans heap_released uint64 // bytes released to the os - heap_objects uint64 // total number of allocated objects + + // heap_objects is not used by the runtime directly and instead + // computed on the fly by updatememstats. + heap_objects uint64 // total number of allocated objects // Statistics about allocation of low-level fixed-size structures. // Protected by FixAlloc locks.