1
0
mirror of https://github.com/golang/go synced 2024-11-23 17:40:03 -07:00

runtime: remove useless heap_objects accounting

This change removes useless additional heap_objects accounting for large
objects. heap_objects is computed from scratch at ReadMemStats time
(which stops the world) by using nlargealloc and nlargefree, so mutating
heap_objects turns out to be pointless.

As a result, the "large" parameter on "mheap_.freeSpan" is no longer
necessary and so this change cleans that up too.

Change-Id: I7d6b486d9b57c018e3db46221d81b55fe4c1b021
Reviewed-on: https://go-review.googlesource.com/c/go/+/196637
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Michael Anthony Knyszek 2019-09-18 14:11:28 +00:00 committed by Michael Knyszek
parent 4208dbef16
commit 814c5058bb
4 changed files with 7 additions and 12 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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()

View File

@ -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.