From 1e8d0bd743ecc98908cd8722daec7e79ab829b3d Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Mon, 7 Sep 2020 11:57:38 +0100 Subject: [PATCH] MemoryProviderStateMixin is not a PAL --- src/mem/alloc.h | 12 ++++++------ src/mem/largealloc.h | 16 +++++++++------- src/mem/mediumslab.h | 6 +++--- src/mem/slab.h | 13 +++++-------- src/test/perf/low_memory/low-memory.cc | 6 +++--- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 74380d1d7..fac0f1bd8 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -1063,7 +1063,7 @@ namespace snmalloc void* p = remove_cache_friendly_offset(head, sizeclass); if constexpr (zero_mem == YesZero) { - large_allocator.memory_provider.zero(p, sizeclass_to_size(sizeclass)); + MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass)); } return p; } @@ -1109,8 +1109,8 @@ namespace snmalloc SlabLink* link = sl.get_next(); slab = get_slab(link); auto& ffl = small_fast_free_lists[sizeclass]; - return slab->alloc( - sl, ffl, rsize, large_allocator.memory_provider); + return slab->alloc( + sl, ffl, rsize); } return small_alloc_rare(sizeclass, size); } @@ -1182,7 +1182,7 @@ namespace snmalloc if constexpr (zero_mem == YesZero) { - large_allocator.memory_provider.zero(p, sizeclass_to_size(sizeclass)); + MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass)); } return p; } @@ -1313,7 +1313,7 @@ namespace snmalloc if (slab != nullptr) { - p = slab->alloc(size, large_allocator.memory_provider); + p = slab->alloc(size); if (slab->full()) sc->pop(); @@ -1336,7 +1336,7 @@ namespace snmalloc slab->init(public_state(), sizeclass, rsize); chunkmap().set_slab(slab); - p = slab->alloc(size, large_allocator.memory_provider); + p = slab->alloc(size); if (!slab->full()) sc->insert(slab); diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index ff85bb56c..34f5ce7e7 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -57,7 +57,7 @@ namespace snmalloc // global state of the allocator. This is currently stored in the memory // provider, so we add this in. template - class MemoryProviderStateMixin : public PalNotificationObject, public PAL + class MemoryProviderStateMixin : public PalNotificationObject { /** * Simple flag for checking if another instance of lazy-decommit is @@ -76,6 +76,8 @@ namespace snmalloc std::atomic peak_memory_used_bytes{0}; public: + using Pal = PAL; + /** * Memory current available in large_stacks */ @@ -258,7 +260,7 @@ namespace snmalloc p = memory_provider.template reserve(large_class); if (p == nullptr) return nullptr; - memory_provider.template notify_using(p, rsize); + MemoryProvider::Pal::template notify_using(p, rsize); } else { @@ -276,19 +278,19 @@ namespace snmalloc // The first page is already in "use" for the stack element, // this will need zeroing for a YesZero call. if constexpr (zero_mem == YesZero) - memory_provider.template zero(p, OS_PAGE_SIZE); + MemoryProvider::Pal::template zero(p, OS_PAGE_SIZE); // Notify we are using the rest of the allocation. // Passing zero_mem ensures the PAL provides zeroed pages if // required. - memory_provider.template notify_using( + MemoryProvider::Pal::template notify_using( pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE); } else { // This is a superslab that has not been decommitted. if constexpr (zero_mem == YesZero) - memory_provider.template zero( + MemoryProvider::Pal::template zero( p, bits::align_up(size, OS_PAGE_SIZE)); else UNUSED(size); @@ -304,7 +306,7 @@ namespace snmalloc if constexpr (decommit_strategy == DecommitSuperLazy) { static_assert( - pal_supports, + pal_supports, "A lazy decommit strategy cannot be implemented on platforms " "without low memory notifications"); } @@ -316,7 +318,7 @@ namespace snmalloc (decommit_strategy != DecommitNone) && (large_class != 0 || decommit_strategy == DecommitSuper)) { - memory_provider.notify_not_using( + MemoryProvider::Pal::notify_not_using( pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE); } diff --git a/src/mem/mediumslab.h b/src/mem/mediumslab.h index 59a10f2e0..9dcfa6651 100644 --- a/src/mem/mediumslab.h +++ b/src/mem/mediumslab.h @@ -76,8 +76,8 @@ namespace snmalloc return sizeclass; } - template - void* alloc(size_t size, MemoryProvider& memory_provider) + template + void* alloc(size_t size) { SNMALLOC_ASSERT(!full()); @@ -86,7 +86,7 @@ namespace snmalloc free--; if constexpr (zero_mem == YesZero) - memory_provider.zero(p, size); + PAL::zero(p, size); else UNUSED(size); diff --git a/src/mem/slab.h b/src/mem/slab.h index 8c14fe364..c59e82e62 100644 --- a/src/mem/slab.h +++ b/src/mem/slab.h @@ -36,12 +36,9 @@ namespace snmalloc * Returns the link as the allocation, and places the free list into the * `fast_free_list` for further allocations. */ - template - SNMALLOC_FAST_PATH void* alloc( - SlabList& sl, - FreeListHead& fast_free_list, - size_t rsize, - MemoryProvider& memory_provider) + template + SNMALLOC_FAST_PATH void* + alloc(SlabList& sl, FreeListHead& fast_free_list, size_t rsize) { // Read the head from the metadata stored in the superslab. Metaslab& meta = get_meta(); @@ -73,9 +70,9 @@ namespace snmalloc if constexpr (zero_mem == YesZero) { if (rsize < PAGE_ALIGNED_SIZE) - memory_provider.zero(p, rsize); + PAL::zero(p, rsize); else - memory_provider.template zero(p, rsize); + PAL::template zero(p, rsize); } else { diff --git a/src/test/perf/low_memory/low-memory.cc b/src/test/perf/low_memory/low-memory.cc index 68007b4a7..83d8742d1 100644 --- a/src/test/perf/low_memory/low-memory.cc +++ b/src/test/perf/low_memory/low-memory.cc @@ -98,17 +98,17 @@ void reduce_pressure(Queue& allocations) * Template parameter required to handle `if constexpr` always evaluating both * sides. */ -template +template void register_for_pal_notifications() { - PAL::register_for_low_memory_callback(&update_epoch); + MemoryProvider::Pal::register_for_low_memory_callback(&update_epoch); } int main(int argc, char** argv) { opt::Opt opt(argc, argv); - if constexpr (pal_supports) + if constexpr (pal_supports) { register_for_pal_notifications(); }