From d36d5bd3c1906d3581ac4ac0d8a1a0eb4b5b16c4 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Fri, 1 Apr 2022 18:15:24 +0000 Subject: runtime: clean up inconsistent heap stats The inconsistent heaps stats in memstats are a bit messy. Primarily, heap_sys is non-orthogonal with heap_released and heap_inuse. In later CLs, we're going to want heap_sys-heap_released-heap_inuse, so clean this up by replacing heap_sys with an orthogonal metric: heapFree. heapFree represents page heap memory that is free but not released. I think this change also simplifies a lot of reasoning about these stats; it's much clearer what they mean, and to obtain HeapSys for memstats, we no longer need to do the strange subtraction from heap_sys when allocating specifically non-heap memory from the page heap. Because we're removing heap_sys, we need to replace it with a sysMemStat for mem.go functions. In this case, heap_released is the most appropriate because we increase it anyway (again, non-orthogonality). In which case, it makes sense for heap_inuse, heap_released, and heapFree to become more uniform, and to just represent them all as sysMemStats. While we're here and messing with the types of heap_inuse and heap_released, let's also fix their names (and last_heap_inuse's name) up to the more modern Go convention of camelCase. For #48409. Change-Id: I87fcbf143b3e36b065c7faf9aa888d86bd11710b Reviewed-on: https://go-review.googlesource.com/c/go/+/397677 Run-TryBot: Michael Knyszek Reviewed-by: Michael Pratt TryBot-Result: Gopher Robot --- src/runtime/malloc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/runtime/malloc.go') diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index ae41da8764..30a2a5f289 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -565,7 +565,8 @@ func (h *mheap) sysAlloc(n uintptr) (v unsafe.Pointer, size uintptr) { n = alignUp(n, heapArenaBytes) // First, try the arena pre-reservation. - v = h.arena.alloc(n, heapArenaBytes, &memstats.heap_sys) + // Newly-used mappings are considered released. + v = h.arena.alloc(n, heapArenaBytes, &memstats.heapReleased) if v != nil { size = n goto mapped -- cgit v1.3