aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2022-04-01 18:15:24 +0000
committerMichael Knyszek <mknyszek@google.com>2022-05-03 15:12:31 +0000
commitd36d5bd3c1906d3581ac4ac0d8a1a0eb4b5b16c4 (patch)
treeff8470fcd1eded1c8380663c15275f37b4249a23 /src/runtime/malloc.go
parent4649a439035a0634109f11f7ac25e4e7184b5598 (diff)
downloadgo-d36d5bd3c1906d3581ac4ac0d8a1a0eb4b5b16c4.tar.xz
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 <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go3
1 files changed, 2 insertions, 1 deletions
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