aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/malloc_test.go
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2013-09-06 16:55:40 -0400
committerRuss Cox <rsc@golang.org>2013-09-06 16:55:40 -0400
commita33ef8d11b9db6646991bee5732015562fd4efd2 (patch)
treea778eda45c6c02b014890cc0e35e6f8c56ee8361 /src/pkg/runtime/malloc_test.go
parent52f15df9e2e9fada55c7f132242eb78a8ba4f3ab (diff)
downloadgo-a33ef8d11b9db6646991bee5732015562fd4efd2.tar.xz
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
Diffstat (limited to 'src/pkg/runtime/malloc_test.go')
-rw-r--r--src/pkg/runtime/malloc_test.go15
1 files changed, 15 insertions, 0 deletions
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) {