dumpint(memstats.nfree)
dumpint(memstats.heap_alloc)
dumpint(memstats.heap_sys.load())
- dumpint(memstats.heap_idle)
+ dumpint(memstats.heap_sys.load() - memstats.heap_inuse)
dumpint(memstats.heap_inuse)
dumpint(memstats.heap_released)
dumpint(memstats.heap_objects)
// Manually managed memory doesn't count toward heap_sys.
memstats.heap_sys.add(-int64(nbytes))
}
- atomic.Xadd64(&memstats.heap_idle, -int64(nbytes))
// Publish the span in various locations.
// size which is always > physPageSize, so its safe to
// just add directly to heap_released.
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
// Manually managed memory doesn't count toward heap_sys, so add it back.
memstats.heap_sys.add(int64(nbytes))
}
- atomic.Xadd64(&memstats.heap_idle, int64(nbytes))
// Mark the space as free.
h.pages.free(s.base(), s.npages)
// in manually-managed spans.
heap_alloc uint64 // bytes allocated and not yet freed (same as alloc above)
heap_sys sysMemStat // virtual address space obtained from system for GC'd heap
- heap_idle uint64 // bytes in idle spans
heap_inuse uint64 // bytes in mSpanInUse spans
heap_released uint64 // bytes released to the os
stats.Frees = memstats.nfree
stats.HeapAlloc = memstats.heap_alloc
stats.HeapSys = memstats.heap_sys.load()
- stats.HeapIdle = memstats.heap_idle
+ // By definition, HeapIdle is memory that was mapped
+ // for the heap but is not currently used to hold heap
+ // objects. It also specifically is memory that can be
+ // used for other purposes, like stacks, but this memory
+ // is subtracted out of HeapSys before it makes that
+ // transition. Put another way:
+ //
+ // heap_sys = bytes allocated from the OS for the heap - bytes ultimately used for non-heap purposes
+ // heap_idle = bytes allocated from the OS for the heap - bytes ultimately used for any purpose
+ //
+ // or
+ //
+ // heap_sys = sys - stacks_inuse - gcWorkBufInUse - gcProgPtrScalarBitsInUse
+ // heap_idle = sys - stacks_inuse - gcWorkBufInUse - gcProgPtrScalarBitsInUse - heap_inuse
+ //
+ // => heap_idle = heap_sys - heap_inuse
+ stats.HeapIdle = memstats.heap_sys.load() - memstats.heap_inuse
stats.HeapInuse = memstats.heap_inuse
stats.HeapReleased = memstats.heap_released
stats.HeapObjects = memstats.heap_objects