From be47aea0c8655e32a43455ede4eb0447535951fb Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 26 Feb 2020 21:24:02 +0000 Subject: [PATCH] Tidying --- src/mem/largealloc.h | 35 ++++++++++++++----- .../thread_alloc_external.cc | 8 +---- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index 7e3de6a..5c1437b 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -57,19 +57,44 @@ namespace snmalloc template class MemoryProviderStateMixin : public PAL { + /** + * Flag to protect the bump allocator + **/ std::atomic_flag lock = ATOMIC_FLAG_INIT; + + /** + * Pointer to block being bump allocated + **/ void* bump = nullptr; + + /** + * Space remaining in this block being bump allocated + **/ size_t remaining = 0; + /** + * The last time we saw a low memory notification. + */ + std::atomic last_low_memory_epoch = 0; + + /** + * Simple flag for checking if another instance of lazy-decommit is + * running + **/ + std::atomic_flag lazy_decommit_guard = {}; + public: /** * Stack of large allocations that have been returned for reuse. */ ModArray> large_stack; + /** + * Make a new memory provide for this PAL. + **/ static MemoryProviderStateMixin* make() noexcept { - // Temporary storage to start the allocator in. + // Temporary stack-based storage to start the allocator in. MemoryProviderStateMixin local; // Allocate permanent storage for the allocator usung temporary allocator @@ -84,12 +109,6 @@ namespace snmalloc } private: - /** - * The last time we saw a low memory notification. - */ - std::atomic last_low_memory_epoch = 0; - std::atomic_flag lazy_decommit_guard = {}; - void new_block() { // Reserve the smallest large_class which is SUPERSLAB_SIZE @@ -290,8 +309,6 @@ namespace snmalloc } } - // printf("Alloc %zx (size = %zx)\n", start, size); - void* result = pointer_cast(start); if (committed) PAL::template notify_using(result, size); diff --git a/src/test/func/thread_alloc_external/thread_alloc_external.cc b/src/test/func/thread_alloc_external/thread_alloc_external.cc index 5439248..f542759 100644 --- a/src/test/func/thread_alloc_external/thread_alloc_external.cc +++ b/src/test/func/thread_alloc_external/thread_alloc_external.cc @@ -26,17 +26,11 @@ int main() { setup(); - MemoryProviderStateMixin mp; - - // 28 is large enough to produce a nested allocator. - // It is also large enough for the example to run in. - // For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example. - auto a = ThreadAlloc::get(); for (size_t i = 0; i < 1000; i++) { - auto r1 = a->alloc(100); + auto r1 = a->alloc(i); a->dealloc(r1); }