From 5d637b83a90cd16ea6badbe716f5e964bd9e06db Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 6 Jun 2013 14:56:50 +0400 Subject: runtime: speedup malloc stats collection Count only number of frees, everything else is derivable and does not need to be counted on every malloc. benchmark old ns/op new ns/op delta BenchmarkMalloc8 68 66 -3.07% BenchmarkMalloc16 75 70 -6.48% BenchmarkMallocTypeInfo8 102 97 -4.80% BenchmarkMallocTypeInfo16 108 105 -2.78% R=golang-dev, dave, rsc CC=golang-dev https://golang.org/cl/9776043 --- src/pkg/runtime/malloc.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/pkg/runtime/malloc.h') diff --git a/src/pkg/runtime/malloc.h b/src/pkg/runtime/malloc.h index ba8036ab68..41604501f0 100644 --- a/src/pkg/runtime/malloc.h +++ b/src/pkg/runtime/malloc.h @@ -286,22 +286,15 @@ struct MCache { // 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 + 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 - // Statistics about allocation size classes since last lock of heap - struct { - uintptr nmalloc; - uintptr nfree; - } local_by_size[NumSizeClasses]; - + // Local allocator stats, flushed during GC. + uintptr local_nlookup; // number of pointer lookups + uintptr local_largefree; // bytes freed for large objects (>MaxSmallSize) + uintptr local_nlargefree; // number of frees for large objects (>MaxSmallSize) + uintptr local_nsmallfree[NumSizeClasses]; // number of frees for small objects (<=MaxSmallSize) }; void runtime·MCache_Refill(MCache *c, int32 sizeclass); @@ -431,6 +424,11 @@ struct MHeap FixAlloc spanalloc; // allocator for Span* FixAlloc cachealloc; // allocator for MCache* + + // Malloc stats. + uint64 largefree; // bytes freed for large objects (>MaxSmallSize) + uint64 nlargefree; // number of frees for large objects (>MaxSmallSize) + uint64 nsmallfree[NumSizeClasses]; // number of frees for small objects (<=MaxSmallSize) }; extern MHeap runtime·mheap; -- cgit v1.3-5-g9baa