From 363629df88fc9d32cd4efbcc3c1a3eef1bbfe525 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Fri, 6 Jan 2017 18:56:02 -0800 Subject: [PATCH] Fix allocated_large stats with respect to sampled small allocations. --- src/arena.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/arena.c b/src/arena.c index 2c3cc5ca..ec8d4790 100644 --- a/src/arena.c +++ b/src/arena.c @@ -211,11 +211,15 @@ arena_nactive_sub(arena_t *arena, size_t sub_pages) static void arena_large_malloc_stats_update(arena_t *arena, size_t usize) { - szind_t index = size2index(usize); - szind_t hindex = (index >= NBINS) ? index - NBINS : 0; + szind_t index, hindex; cassert(config_stats); + if (usize < LARGE_MINCLASS) + usize = LARGE_MINCLASS; + index = size2index(usize); + hindex = (index >= NBINS) ? index - NBINS : 0; + arena->stats.nmalloc_large++; arena->stats.allocated_large += usize; arena->stats.lstats[hindex].nmalloc++; @@ -226,11 +230,15 @@ arena_large_malloc_stats_update(arena_t *arena, size_t usize) static void arena_large_malloc_stats_update_undo(arena_t *arena, size_t usize) { - szind_t index = size2index(usize); - szind_t hindex = (index >= NBINS) ? index - NBINS : 0; + szind_t index, hindex; cassert(config_stats); + if (usize < LARGE_MINCLASS) + usize = LARGE_MINCLASS; + index = size2index(usize); + hindex = (index >= NBINS) ? index - NBINS : 0; + arena->stats.nmalloc_large--; arena->stats.allocated_large -= usize; arena->stats.lstats[hindex].nmalloc--; @@ -241,11 +249,15 @@ arena_large_malloc_stats_update_undo(arena_t *arena, size_t usize) static void arena_large_dalloc_stats_update(arena_t *arena, size_t usize) { - szind_t index = size2index(usize); - szind_t hindex = (index >= NBINS) ? index - NBINS : 0; + szind_t index, hindex; cassert(config_stats); + if (usize < LARGE_MINCLASS) + usize = LARGE_MINCLASS; + index = size2index(usize); + hindex = (index >= NBINS) ? index - NBINS : 0; + arena->stats.ndalloc_large++; arena->stats.allocated_large -= usize; arena->stats.lstats[hindex].ndalloc++;