From a33ef8d11b9db6646991bee5732015562fd4efd2 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Fri, 6 Sep 2013 16:55:40 -0400 Subject: runtime: account for all sys memory in MemStats Currently lots of sys allocations are not accounted in any of XxxSys, including GC bitmap, spans table, GC roots blocks, GC finalizer blocks, iface table, netpoll descriptors and more. Up to ~20% can unaccounted. This change introduces 2 new stats: GCSys and OtherSys for GC metadata and all other misc allocations, respectively. Also ensures that all XxxSys indeed sum up to Sys. All sys memory allocation functions require the stat for accounting, so that it's impossible to miss something. Also fix updating of mcache_sys/inuse, they were not updated after deallocation. test/bench/garbage/parser before: Sys 670064344 HeapSys 610271232 StackSys 65536 MSpanSys 14204928 MCacheSys 16384 BuckHashSys 1439992 after: Sys 670064344 HeapSys 610271232 StackSys 65536 MSpanSys 14188544 MCacheSys 16384 BuckHashSys 3194304 GCSys 39198688 OtherSys 3129656 Fixes #5799. R=rsc, dave, alex.brainman CC=golang-dev https://golang.org/cl/12946043 --- src/pkg/runtime/malloc_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/pkg/runtime/malloc_test.go') diff --git a/src/pkg/runtime/malloc_test.go b/src/pkg/runtime/malloc_test.go index 1afd32d08c..2b686a6e7e 100644 --- a/src/pkg/runtime/malloc_test.go +++ b/src/pkg/runtime/malloc_test.go @@ -5,10 +5,25 @@ package runtime_test import ( + . "runtime" "testing" "unsafe" ) +func TestMemStats(t *testing.T) { + // Test that MemStats has sane values. + st := new(MemStats) + ReadMemStats(st) + if st.HeapSys == 0 || st.StackSys == 0 || st.MSpanSys == 0 || st.MCacheSys == 0 || + st.BuckHashSys == 0 || st.GCSys == 0 || st.OtherSys == 0 { + t.Fatalf("Zero sys value: %+v", *st) + } + if st.Sys != st.HeapSys+st.StackSys+st.MSpanSys+st.MCacheSys+ + st.BuckHashSys+st.GCSys+st.OtherSys { + t.Fatalf("Bad sys value: %+v", *st) + } +} + var mallocSink uintptr func BenchmarkMalloc8(b *testing.B) { -- cgit v1.3