From e94fe50a0d02a4202ef5bb674f3690a4bdcd8de2 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 6 Apr 2019 22:43:56 -0400 Subject: [PATCH] include zero byte size class in stats The allocations don't consume any actual memory, but it does still use up the virtual memory assigned to the size class and requires metadata. --- h_malloc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/h_malloc.c b/h_malloc.c index a5f73a2..58ec9db 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -1609,8 +1609,7 @@ EXPORT struct mallinfo h_mallinfo(void) { mutex_unlock(&ra->lock); for (unsigned arena = 0; arena < N_ARENA; arena++) { - // skip zero byte size class - for (unsigned class = 1; class < N_SIZE_CLASSES; class++) { + for (unsigned class = 0; class < N_SIZE_CLASSES; class++) { struct size_class *c = &ro.size_class_metadata[arena][class]; mutex_lock(&c->lock); @@ -1665,8 +1664,7 @@ EXPORT struct mallinfo __mallinfo_arena_info(UNUSED size_t arena) { #if STATS if (arena < N_ARENA) { - // skip zero byte size class - for (unsigned class = 1; class < N_SIZE_CLASSES; class++) { + for (unsigned class = 0; class < N_SIZE_CLASSES; class++) { struct size_class *c = &ro.size_class_metadata[arena][class]; mutex_lock(&c->lock); @@ -1697,8 +1695,7 @@ EXPORT struct mallinfo __mallinfo_bin_info(UNUSED size_t arena, UNUSED size_t bi struct mallinfo info = {0}; #if STATS - // skip zero byte size class for consistency - if (arena < N_ARENA && bin > 0 && bin < N_SIZE_CLASSES) { + if (arena < N_ARENA && bin < N_SIZE_CLASSES) { struct size_class *c = &ro.size_class_metadata[arena][bin]; mutex_lock(&c->lock);