From 4003805d4d987a4b338c8ffad34b320c1ccb3153 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 29 Jan 2020 16:09:04 +0000 Subject: [PATCH] Minor code tidying --- src/ds/helpers.h | 2 +- src/mem/largealloc.h | 5 +++-- src/mem/metaslab.h | 4 ++-- src/mem/superslab.h | 26 +++++++++++++------------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ds/helpers.h b/src/ds/helpers.h index 5e22ef563..4e6905441 100644 --- a/src/ds/helpers.h +++ b/src/ds/helpers.h @@ -56,7 +56,7 @@ namespace snmalloc length == bits::next_pow2_const(length), "Must be a power of two."); private: - T value; + T value = 0; public: operator T() diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index 28f6ab654..997d95196 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -80,7 +80,7 @@ namespace snmalloc */ std::atomic last_low_memory_epoch = 0; std::atomic_flag lazy_decommit_guard; - void lazy_decommit() + SNMALLOC_SLOW_PATH void lazy_decommit() { // If another thread is try to do lazy decommit, let it continue. If // we try to parallelise this, we'll most likely end up waiting on the @@ -93,6 +93,7 @@ namespace snmalloc // the memory that we can. Start with the small size classes so that we // hit cached superslabs first. // FIXME: We probably shouldn't do this all at once. + // FIXME: We currently Decommit all the sizeclasses larger than 0. for (size_t large_class = 0; large_class < NUM_LARGE_CLASSES; large_class++) { @@ -408,7 +409,7 @@ namespace snmalloc size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class; memory_provider.notify_not_using( - pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE); + pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE); } stats.superslab_push(); diff --git a/src/mem/metaslab.h b/src/mem/metaslab.h index 6a87c8989..fbfcc9a94 100644 --- a/src/mem/metaslab.h +++ b/src/mem/metaslab.h @@ -36,7 +36,7 @@ namespace snmalloc * The list will be (allocated - needed - 1) long. The -1 is * for the `link` element which is not in the free list. */ - void* head; + void* head = nullptr; /** * How many entries are not in the free list of slab, i.e. @@ -51,7 +51,7 @@ namespace snmalloc /** * How many entries have been allocated from this slab. */ - uint16_t allocated; + uint16_t allocated = 0; // When a slab has free space it will be on the has space list for // that size class. We use an empty block in this slab to be the diff --git a/src/mem/superslab.h b/src/mem/superslab.h index e74987843..b0a036a98 100644 --- a/src/mem/superslab.h +++ b/src/mem/superslab.h @@ -84,7 +84,7 @@ namespace snmalloc { if (kind != Fresh) { - // If this wasn't previously Fresh, we need to zero some things. + // If this wasn't previously Fresh, we need to zero some things. used = 0; for (size_t i = 0; i < SLAB_COUNT; i++) { @@ -97,21 +97,21 @@ namespace snmalloc kind = Super; // Point head at the first non-short slab. head = 1; + } #ifndef NDEBUG - auto curr = head; - for (size_t i = 0; i < SLAB_COUNT - used - 1; i++) - { - curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1); - } - assert(curr == 0); + auto curr = head; + for (size_t i = 0; i < SLAB_COUNT - used - 1; i++) + { + curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1); + } + if (curr != 0) abort(); - for (size_t i = 0; i < SLAB_COUNT; i++) - { - assert(meta[i].is_unused()); - } -#endif + for (size_t i = 0; i < SLAB_COUNT; i++) + { + assert(meta[i].is_unused()); } +#endif } bool is_empty() @@ -165,7 +165,7 @@ namespace snmalloc meta[0].link = get_initial_offset(sizeclass, true); used++; - return (Slab*)this; + return reinterpret_cast(this); } Slab* alloc_slab(sizeclass_t sizeclass)