From c075d82ccac5eb6fca481efccc798acac00f7dae Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Wed, 22 May 2013 22:22:57 +0400 Subject: runtime: fix and speedup malloc stats Currently per-sizeclass stats are lost for destroyed MCache's. This patch fixes this. Also, only update mstats.heap_alloc on heap operations, because that's the only stat that needs to be promptly updated. Everything else needs to be up-to-date only in ReadMemStats(). R=golang-dev, remyoudompheng, dave, iant CC=golang-dev https://golang.org/cl/9207047 --- src/pkg/runtime/malloc.goc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/pkg/runtime/malloc.goc') diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index 5326551fee..7e691fe9c8 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -278,6 +278,8 @@ runtime·freemcache(MCache *c) void runtime·purgecachedstats(MCache *c) { + int32 i; + // Protected by either heap or GC lock. mstats.heap_alloc += c->local_cachealloc; c->local_cachealloc = 0; @@ -293,6 +295,12 @@ runtime·purgecachedstats(MCache *c) c->local_alloc= 0; mstats.total_alloc += c->local_total_alloc; c->local_total_alloc= 0; + for(i=0; ilocal_by_size); i++) { + mstats.by_size[i].nmalloc += c->local_by_size[i].nmalloc; + c->local_by_size[i].nmalloc = 0; + mstats.by_size[i].nfree += c->local_by_size[i].nfree; + c->local_by_size[i].nfree = 0; + } } uintptr runtime·sizeof_C_MStats = sizeof(MStats); -- cgit v1.3