diff --git a/src/runtime/gc_none.go b/src/runtime/gc_none.go index a27b57a24..789802ed8 100644 --- a/src/runtime/gc_none.go +++ b/src/runtime/gc_none.go @@ -13,6 +13,8 @@ import ( const gcAsserts = false // perform sanity checks +var gcTotalAlloc uint64 // for runtime.MemStats + func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index 38596dce3..5f42d6a5a 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -1,6 +1,3 @@ -//go:build gc.conservative -// +build gc.conservative - package runtime // Memory statistics @@ -47,24 +44,3 @@ type MemStats struct { // GCSys is bytes of memory in garbage collection metadata. GCSys uint64 } - -// ReadMemStats populates m with memory statistics. -// -// The returned memory statistics are up to date as of the -// call to ReadMemStats. This would not do GC implicitly for you. -func ReadMemStats(m *MemStats) { - m.HeapIdle = 0 - m.HeapInuse = 0 - for block := gcBlock(0); block < endBlock; block++ { - bstate := block.state() - if bstate == blockStateFree { - m.HeapIdle += uint64(bytesPerBlock) - } else { - m.HeapInuse += uint64(bytesPerBlock) - } - } - m.HeapReleased = 0 // always 0, we don't currently release memory back to the OS. - m.HeapSys = m.HeapInuse + m.HeapIdle - m.GCSys = uint64(heapEnd - uintptr(metadataStart)) - m.Sys = uint64(heapEnd - heapStart) -} diff --git a/src/runtime/mstats_conservative.go b/src/runtime/mstats_conservative.go new file mode 100644 index 000000000..a65c9da59 --- /dev/null +++ b/src/runtime/mstats_conservative.go @@ -0,0 +1,25 @@ +//go:build gc.conservative +// +build gc.conservative + +package runtime + +// ReadMemStats populates m with memory statistics. +// +// The returned memory statistics are up to date as of the +// call to ReadMemStats. This would not do GC implicitly for you. +func ReadMemStats(m *MemStats) { + m.HeapIdle = 0 + m.HeapInuse = 0 + for block := gcBlock(0); block < endBlock; block++ { + bstate := block.state() + if bstate == blockStateFree { + m.HeapIdle += uint64(bytesPerBlock) + } else { + m.HeapInuse += uint64(bytesPerBlock) + } + } + m.HeapReleased = 0 // always 0, we don't currently release memory back to the OS. + m.HeapSys = m.HeapInuse + m.HeapIdle + m.GCSys = uint64(heapEnd - uintptr(metadataStart)) + m.Sys = uint64(heapEnd - heapStart) +} diff --git a/src/runtime/mstats_leaking.go b/src/runtime/mstats_leaking.go new file mode 100644 index 000000000..70e0503ea --- /dev/null +++ b/src/runtime/mstats_leaking.go @@ -0,0 +1,18 @@ +//go:build gc.leaking +// +build gc.leaking + +package runtime + +// ReadMemStats populates m with memory statistics. +// +// The returned memory statistics are up to date as of the +// call to ReadMemStats. This would not do GC implicitly for you. +func ReadMemStats(m *MemStats) { + m.HeapIdle = 0 + m.HeapInuse = uint64(heapptr - heapStart) + m.HeapReleased = 0 // always 0, we don't currently release memory back to the OS. + + m.HeapSys = m.HeapInuse + m.HeapIdle + m.GCSys = 0 + m.Sys = uint64(heapEnd - heapStart) +}