mirror of
https://github.com/golang/go
synced 2024-09-29 19:14:28 -06:00
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 <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
5440bfc2ea
commit
3f86d7cc67
@ -244,7 +244,7 @@ func (c *mcentral) freeSpan(s *mspan, preserve bool, wasempty bool) bool {
|
|||||||
|
|
||||||
c.nonempty.remove(s)
|
c.nonempty.remove(s)
|
||||||
unlock(&c.lock)
|
unlock(&c.lock)
|
||||||
mheap_.freeSpan(s, 0)
|
mheap_.freeSpan(s, false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ func (s *mspan) sweep(preserve bool) bool {
|
|||||||
s.limit = 0 // prevent mlookup from finding this span
|
s.limit = 0 // prevent mlookup from finding this span
|
||||||
sysFault(unsafe.Pointer(s.base()), size)
|
sysFault(unsafe.Pointer(s.base()), size)
|
||||||
} else {
|
} else {
|
||||||
mheap_.freeSpan(s, 1)
|
mheap_.freeSpan(s, true)
|
||||||
}
|
}
|
||||||
c.local_nlargefree++
|
c.local_nlargefree++
|
||||||
c.local_largefree += size
|
c.local_largefree += size
|
||||||
|
@ -945,7 +945,10 @@ func (h *mheap) grow(npage uintptr) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Free the span back into the heap.
|
// 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() {
|
systemstack(func() {
|
||||||
mp := getg().m
|
mp := getg().m
|
||||||
lock(&h.lock)
|
lock(&h.lock)
|
||||||
@ -959,7 +962,8 @@ func (h *mheap) freeSpan(s *mspan, acct int32) {
|
|||||||
bytes := s.npages << _PageShift
|
bytes := s.npages << _PageShift
|
||||||
msanfree(base, bytes)
|
msanfree(base, bytes)
|
||||||
}
|
}
|
||||||
if acct != 0 {
|
if large {
|
||||||
|
// Match accounting done in mheap.alloc.
|
||||||
memstats.heap_objects--
|
memstats.heap_objects--
|
||||||
}
|
}
|
||||||
if gcBlackenEnabled != 0 {
|
if gcBlackenEnabled != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user