]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove useless heap_objects accounting
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 18 Sep 2019 14:11:28 +0000 (14:11 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 8 Nov 2019 16:20:27 +0000 (16:20 +0000)
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>
src/runtime/mcentral.go
src/runtime/mgcsweep.go
src/runtime/mheap.go
src/runtime/mstats.go

index cd5901054ae4ea94049dc1c3a861d84ac3f3ffc7..2f97b7d0946bd55bd330f1a16002f59102118d46 100644 (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
 }
 
index 580de7a715372bdac8d3ce729ebd962f3c0db0e3..b95c7f13a4ab8db9810fc140bf0dcba39ab53883 100644 (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
index c2a23267bcbcbf21f3a112e36491e09d71e6fd23..f9039f78ca365ea54443979567ef692bb787b2b0 100644 (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()
index 09dbb267355d0e8fef15fd0214114ed8b1aa47ee..a6866e3a15702f599d5a7e58cbaff3d1a1348855 100644 (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.