From 7e6749595a570ed6686603a1bcfdf8cf49147f19 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Mon, 25 Apr 2016 13:26:54 -0700 Subject: [PATCH] Fix arena reset effects on large/huge stats. Reset large curruns to 0 during arena reset. Do not increase huge ndalloc stats during arena reset. --- src/arena.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/arena.c b/src/arena.c index f752acad..c6859e3b 100644 --- a/src/arena.c +++ b/src/arena.c @@ -854,6 +854,17 @@ arena_huge_dalloc_stats_update(arena_t *arena, size_t usize) arena->stats.hstats[index].curhchunks--; } +static void +arena_huge_reset_stats_cancel(arena_t *arena, size_t usize) +{ + szind_t index = size2index(usize) - nlclasses - NBINS; + + cassert(config_stats); + + arena->stats.ndalloc_huge++; + arena->stats.hstats[index].ndalloc--; +} + static void arena_huge_dalloc_stats_update_undo(arena_t *arena, size_t usize) { @@ -1884,22 +1895,30 @@ arena_reset(tsd_t *tsd, arena_t *arena) } } + /* Reset curruns for large size classes. */ + if (config_stats) { + for (i = 0; i < nlclasses; i++) + arena->stats.lstats[i].curruns = 0; + } + /* Huge allocations. */ malloc_mutex_lock(tsd, &arena->huge_mtx); for (node = ql_last(&arena->huge, ql_link); node != NULL; node = ql_last(&arena->huge, ql_link)) { void *ptr = extent_node_addr_get(node); + size_t usize; malloc_mutex_unlock(tsd, &arena->huge_mtx); - /* Remove huge allocation from prof sample set. */ - if (config_prof && opt_prof) { - size_t usize; - + if (config_stats || (config_prof && opt_prof)) usize = isalloc(tsd, ptr, config_prof); + /* Remove huge allocation from prof sample set. */ + if (config_prof && opt_prof) prof_free(tsd, ptr, usize); - } huge_dalloc(tsd, ptr); malloc_mutex_lock(tsd, &arena->huge_mtx); + /* Cancel out unwanted effects on stats. */ + if (config_stats) + arena_huge_reset_stats_cancel(arena, usize); } malloc_mutex_unlock(tsd, &arena->huge_mtx);