From e240dd279a0c40247abd1324604eb58be6cf620c Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 9 Jul 2019 10:41:58 +0100 Subject: [PATCH] Use FlatPageMap on OS with lazy commit If the operating system will allocate private pages on demand for the pagemap then use the FlatPageMap by default as it generates better code for deallocation. --- src/mem/alloc.h | 8 ++++++-- src/pal/pal_apple.h | 2 +- src/pal/pal_consts.h | 8 +++++++- src/pal/pal_freebsd.h | 2 +- src/pal/pal_linux.h | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index bd76171..c08ac2d 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -46,8 +46,10 @@ namespace snmalloc // Use flat map is under a single node. # define SNMALLOC_MAX_FLATPAGEMAP_SIZE PAGEMAP_NODE_SIZE #endif - static constexpr bool USE_FLATPAGEMAP = SNMALLOC_MAX_FLATPAGEMAP_SIZE >= - sizeof(FlatPagemap); + static constexpr bool USE_FLATPAGEMAP = + (Pal::pal_features & PalFeatures::LazyCommit) || + (SNMALLOC_MAX_FLATPAGEMAP_SIZE >= + sizeof(FlatPagemap)); using SuperslabPagemap = std::conditional_t< USE_FLATPAGEMAP, @@ -1152,6 +1154,8 @@ namespace snmalloc SNMALLOC_SLOW_PATH void small_dealloc_offseted_slow( Superslab* super, void* p, sizeclass_t sizeclass) { + handle_message_queue(); + bool was_full = super->is_full(); SlabList* sl = &small_classes[sizeclass]; Slab* slab = Slab::get(p); diff --git a/src/pal/pal_apple.h b/src/pal/pal_apple.h index 9e456d5..97f72bb 100644 --- a/src/pal/pal_apple.h +++ b/src/pal/pal_apple.h @@ -22,7 +22,7 @@ namespace snmalloc * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. */ - static constexpr uint64_t pal_features = 0; + static constexpr uint64_t pal_features = LazyCommit; static void error(const char* const str) { puts(str); diff --git a/src/pal/pal_consts.h b/src/pal/pal_consts.h index e5e165d..40e50bb 100644 --- a/src/pal/pal_consts.h +++ b/src/pal/pal_consts.h @@ -25,7 +25,13 @@ namespace snmalloc * a size and alignment. A PAL that does *not* support it must expose a * `request()` method that takes only a size. */ - AlignedAllocation = (1 << 1) + AlignedAllocation = (1 << 1), + /** + * This PAL natively supports lazy commit of pages. This means have large + * allocations and not touching them does not up memory usage. This is + * exposed in the P + */ + LazyCommit = (1 << 2), }; /** * Flag indicating whether requested memory should be zeroed. diff --git a/src/pal/pal_freebsd.h b/src/pal/pal_freebsd.h index 8487f19..d0e6bc6 100644 --- a/src/pal/pal_freebsd.h +++ b/src/pal/pal_freebsd.h @@ -17,7 +17,7 @@ namespace snmalloc * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. */ - static constexpr uint64_t pal_features = AlignedAllocation; + static constexpr uint64_t pal_features = AlignedAllocation | LazyCommit; static void error(const char* const str) { puts(str); diff --git a/src/pal/pal_linux.h b/src/pal/pal_linux.h index b2af742..dcb75dd 100644 --- a/src/pal/pal_linux.h +++ b/src/pal/pal_linux.h @@ -18,7 +18,7 @@ namespace snmalloc * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. */ - static constexpr uint64_t pal_features = 0; + static constexpr uint64_t pal_features = LazyCommit; static void error(const char* const str) { puts(str);