From ae585ee52c2437bfd0e955ad6fc8911bf292f51d Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 3 Aug 2020 19:31:23 +0000 Subject: [PATCH] runtime: remove memstats.heap_alloc memstats.heap_alloc is 100% a duplicate and unnecessary copy of memstats.alloc which exists because MemStats used to be populated from memstats via a memmove. Change-Id: I995489f61be39786e573b8494a8ab6d4ea8bed9c Reviewed-on: https://go-review.googlesource.com/c/go/+/246975 Run-TryBot: Michael Knyszek TryBot-Result: Go Bot Trust: Michael Knyszek Reviewed-by: Michael Pratt --- src/runtime/heapdump.go | 2 +- src/runtime/mstats.go | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/runtime/heapdump.go b/src/runtime/heapdump.go index f96475e848..6fcd9746af 100644 --- a/src/runtime/heapdump.go +++ b/src/runtime/heapdump.go @@ -550,7 +550,7 @@ func dumpmemstats() { dumpint(memstats.nlookup) dumpint(memstats.nmalloc) dumpint(memstats.nfree) - dumpint(memstats.heap_alloc) + dumpint(memstats.alloc) dumpint(memstats.heap_sys.load()) dumpint(memstats.heap_sys.load() - memstats.heap_inuse) dumpint(memstats.heap_inuse) diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index 43f74273f7..a6e38d1c1b 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -32,7 +32,6 @@ type mstats struct { // // Like MemStats, heap_sys and heap_inuse do not count memory // 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_inuse uint64 // bytes in mSpanInUse spans heap_released uint64 // bytes released to the os @@ -112,11 +111,10 @@ type mstats struct { // heap_live is the number of bytes considered live by the GC. // That is: retained by the most recent GC plus allocated - // since then. heap_live <= heap_alloc, since heap_alloc - // includes unmarked objects that have not yet been swept (and - // hence goes up as we allocate and down as we sweep) while - // heap_live excludes these objects (and hence only goes up - // between GCs). + // since then. heap_live <= alloc, since alloc includes unmarked + // objects that have not yet been swept (and hence goes up as we + // allocate and down as we sweep) while heap_live excludes these + // objects (and hence only goes up between GCs). // // This is updated atomically without locking. To reduce // contention, this is updated only when obtaining a span from @@ -458,7 +456,7 @@ func readmemstats_m(stats *MemStats) { stats.Sys = memstats.sys stats.Mallocs = memstats.nmalloc stats.Frees = memstats.nfree - stats.HeapAlloc = memstats.heap_alloc + stats.HeapAlloc = memstats.alloc stats.HeapSys = memstats.heap_sys.load() // By definition, HeapIdle is memory that was mapped // for the heap but is not currently used to hold heap @@ -639,7 +637,6 @@ func updatememstats() { // Calculate derived stats. memstats.total_alloc = totalAlloc memstats.alloc = totalAlloc - totalFree - memstats.heap_alloc = memstats.alloc memstats.heap_objects = memstats.nmalloc - memstats.nfree } -- 2.48.1