mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: delineate which memstats are system stats with a type
This change modifies the type of several mstats fields to be a new type: sysMemStat. This type has the same structure as the fields used to have. The purpose of this change is to make it very clear which stats may be used in various functions for accounting (usually the platform-specific sys* functions, but there are others). Currently there's an implicit understanding that the *uint64 value passed to these functions is some kind of statistic whose value is atomically managed. This understanding isn't inherently problematic, but we're about to change how some stats (which currently use mSysStatInc and mSysStatDec) work, so we want to make it very clear what the various requirements are around "sysStat". This change also removes mSysStatInc and mSysStatDec in favor of a method on sysMemStat. Note that those two functions were originally written the way they were because atomic 64-bit adds required a valid G on ARM, but this hasn't been the case for a very long time (since golang.org/cl/14204, but even before then it wasn't clear if mutexes required a valid G anymore). Today we implement 64-bit adds on ARM with a spinlock table. Change-Id: I4e9b37cf14afc2ae20cf736e874eb0064af086d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/246971 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
dc02578ac8
commit
8ebc58452a
17 changed files with 109 additions and 130 deletions
|
|
@ -1222,22 +1222,22 @@ HaveSpan:
|
|||
// sysUsed all the pages that are actually available
|
||||
// in the span since some of them might be scavenged.
|
||||
sysUsed(unsafe.Pointer(base), nbytes)
|
||||
mSysStatDec(&memstats.heap_released, scav)
|
||||
atomic.Xadd64(&memstats.heap_released, -int64(scav))
|
||||
}
|
||||
// Update stats.
|
||||
switch typ {
|
||||
case spanAllocHeap:
|
||||
mSysStatInc(&memstats.heap_inuse, nbytes)
|
||||
atomic.Xadd64(&memstats.heap_inuse, int64(nbytes))
|
||||
case spanAllocStack:
|
||||
mSysStatInc(&memstats.stacks_inuse, nbytes)
|
||||
atomic.Xadd64(&memstats.stacks_inuse, int64(nbytes))
|
||||
case spanAllocPtrScalarBits, spanAllocWorkBuf:
|
||||
mSysStatInc(&memstats.gc_sys, nbytes)
|
||||
memstats.gc_sys.add(int64(nbytes))
|
||||
}
|
||||
if typ.manual() {
|
||||
// Manually managed memory doesn't count toward heap_sys.
|
||||
mSysStatDec(&memstats.heap_sys, nbytes)
|
||||
memstats.heap_sys.add(-int64(nbytes))
|
||||
}
|
||||
mSysStatDec(&memstats.heap_idle, nbytes)
|
||||
atomic.Xadd64(&memstats.heap_idle, -int64(nbytes))
|
||||
|
||||
// Publish the span in various locations.
|
||||
|
||||
|
|
@ -1314,8 +1314,8 @@ func (h *mheap) grow(npage uintptr) bool {
|
|||
// The allocation is always aligned to the heap arena
|
||||
// size which is always > physPageSize, so its safe to
|
||||
// just add directly to heap_released.
|
||||
mSysStatInc(&memstats.heap_released, asize)
|
||||
mSysStatInc(&memstats.heap_idle, asize)
|
||||
atomic.Xadd64(&memstats.heap_released, int64(asize))
|
||||
atomic.Xadd64(&memstats.heap_idle, int64(asize))
|
||||
|
||||
// Recalculate nBase.
|
||||
// We know this won't overflow, because sysAlloc returned
|
||||
|
|
@ -1400,18 +1400,20 @@ func (h *mheap) freeSpanLocked(s *mspan, typ spanAllocType) {
|
|||
// Update stats.
|
||||
//
|
||||
// Mirrors the code in allocSpan.
|
||||
nbytes := s.npages * pageSize
|
||||
switch typ {
|
||||
case spanAllocHeap:
|
||||
mSysStatDec(&memstats.heap_inuse, s.npages*pageSize)
|
||||
atomic.Xadd64(&memstats.heap_inuse, -int64(nbytes))
|
||||
case spanAllocStack:
|
||||
mSysStatDec(&memstats.stacks_inuse, s.npages*pageSize)
|
||||
atomic.Xadd64(&memstats.stacks_inuse, -int64(nbytes))
|
||||
case spanAllocPtrScalarBits, spanAllocWorkBuf:
|
||||
mSysStatDec(&memstats.gc_sys, s.npages*pageSize)
|
||||
memstats.gc_sys.add(-int64(nbytes))
|
||||
}
|
||||
if typ.manual() {
|
||||
mSysStatInc(&memstats.heap_sys, s.npages*pageSize)
|
||||
// Manually managed memory doesn't count toward heap_sys, so add it back.
|
||||
memstats.heap_sys.add(int64(nbytes))
|
||||
}
|
||||
mSysStatInc(&memstats.heap_idle, s.npages*pageSize)
|
||||
atomic.Xadd64(&memstats.heap_idle, int64(nbytes))
|
||||
|
||||
// Mark the space as free.
|
||||
h.pages.free(s.base(), s.npages)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue