From 2e289573c8a8179b4583a6fcb891fd39cda714b6 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 29 Jan 2020 12:17:16 +0000 Subject: [PATCH] Move all decommit strategy into LargeAllocator The code for decommit was distribured in the code base. Removing Decommit All means that it can logically reside in lthe arge allocator. --- src/mem/alloc.h | 28 +--------------------------- src/mem/largealloc.h | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 43eef20..8d1ae12 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -1111,20 +1111,6 @@ namespace snmalloc { super_available.remove(super); - if constexpr (decommit_strategy == DecommitSuper) - { - large_allocator.memory_provider.notify_not_using( - pointer_offset(super, OS_PAGE_SIZE), - SUPERSLAB_SIZE - OS_PAGE_SIZE); - } - else if constexpr (decommit_strategy == DecommitSuperLazy) - { - static_assert( - pal_supports, - "A lazy decommit strategy cannot be implemented on platforms " - "without low memory notifications"); - } - chunkmap().clear_slab(super); large_allocator.dealloc(super, 0); stats().superslab_push(); @@ -1208,12 +1194,6 @@ namespace snmalloc sc->remove(slab); } - if constexpr (decommit_strategy == DecommitSuper) - { - large_allocator.memory_provider.notify_not_using( - pointer_offset(slab, OS_PAGE_SIZE), SUPERSLAB_SIZE - OS_PAGE_SIZE); - } - chunkmap().clear_slab(slab); large_allocator.dealloc(slab, 0); stats().superslab_push(); @@ -1261,19 +1241,13 @@ namespace snmalloc MEASURE_TIME(large_dealloc, 4, 16); size_t size_bits = bits::next_pow2_bits(size); - size_t rsize = bits::one_at_bit(size_bits); - assert(rsize >= SUPERSLAB_SIZE); + assert(bits::one_at_bit(size_bits) >= SUPERSLAB_SIZE); size_t large_class = size_bits - SUPERSLAB_BITS; chunkmap().clear_large_size(p, size); stats().large_dealloc(large_class); - // Cross-reference largealloc's alloc() decommitted condition. - if ((decommit_strategy != DecommitNone) || (large_class > 0)) - large_allocator.memory_provider.notify_not_using( - pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE); - // Initialise in order to set the correct SlabKind. Largeslab* slab = static_cast(p); slab->init(); diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index c70a9b9..291457c 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -362,7 +362,7 @@ namespace snmalloc bool decommitted = ((decommit_strategy == DecommitSuperLazy) && (static_cast(p)->get_kind() == Decommitted)) || - (large_class > 0) || (decommit_strategy != DecommitNone); + (large_class > 0) || (decommit_strategy == DecommitSuper); if (decommitted) { @@ -392,6 +392,24 @@ namespace snmalloc void dealloc(void* p, size_t large_class) { + if constexpr (decommit_strategy == DecommitSuperLazy) + { + static_assert( + pal_supports, + "A lazy decommit strategy cannot be implemented on platforms " + "without low memory notifications"); + } + + // Cross-reference largealloc's alloc() decommitted condition. + if ((decommit_strategy != DecommitNone) + && (large_class != 0 || decommit_strategy == DecommitSuper)) + { + 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); + } + stats.superslab_push(); memory_provider.large_stack[large_class].push(static_cast(p)); memory_provider.lazy_decommit_if_needed();