]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: tidy mheap.freeSpan
authorAustin Clements <austin@google.com>
Tue, 25 Sep 2018 19:44:27 +0000 (15:44 -0400)
committerAustin Clements <austin@google.com>
Tue, 9 Oct 2018 16:43:18 +0000 (16:43 +0000)
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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/mcentral.go
src/runtime/mgcsweep.go
src/runtime/mheap.go

index 9ca8e5d2225ca216295bdda5e84060308afcab1a..baede31405488b727b07292d6163a2ac8cfd90ad 100644 (file)
@@ -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
 }
 
index 00950aede21bd5a6bc609624aeae66c8488a9c8d..104bd868faf3db857178a3808dba9b5740b0c9c2 100644 (file)
@@ -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
index 1d672cdf219252fdc72631ac3c56a4b4ee07da52..48b3f5364aa5bdbb8cd9e6afe68ecf5e8bf6a516 100644 (file)
@@ -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 {