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.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/pkg/runtime/malloc.h') diff --git a/src/pkg/runtime/malloc.h b/src/pkg/runtime/malloc.h index cbcc09cdb7..0d31326a22 100644 --- a/src/pkg/runtime/malloc.h +++ b/src/pkg/runtime/malloc.h @@ -285,15 +285,18 @@ struct MCacheList struct MCache { - MCacheList list[NumSizeClasses]; + // The following members are accessed on every malloc, + // so they are grouped here for better caching. + int32 next_sample; // trigger heap sample after allocating this many bytes intptr local_cachealloc; // bytes allocated (or freed) from cache since last lock of heap + // The rest is not accessed on every malloc. + MCacheList list[NumSizeClasses]; intptr local_objects; // objects allocated (or freed) from cache since last lock of heap intptr local_alloc; // bytes allocated (or freed) since last lock of heap uintptr local_total_alloc; // bytes allocated (even if freed) since last lock of heap uintptr local_nmalloc; // number of mallocs since last lock of heap uintptr local_nfree; // number of frees since last lock of heap uintptr local_nlookup; // number of pointer lookups since last lock of heap - int32 next_sample; // trigger heap sample after allocating this many bytes // Statistics about allocation size classes since last lock of heap struct { uintptr nmalloc; -- cgit v1.3