From 6a5f3c2b82fcbf5714eaf95661ac4dd4bff46259 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Tue, 31 May 2022 13:39:11 +0100 Subject: [PATCH] NFC: backend_helper: generalize chunk bounds Most ranges just deal with whatever kinds of ranges their parent deal with, but that might be Chunk- or (soon) Arena-bounded. This commit does not yet introduce nuance, but just sets the stage. --- src/snmalloc/backend/standard_range.h | 2 +- src/snmalloc/backend_helpers/commitrange.h | 9 +++++++-- src/snmalloc/backend_helpers/empty_range.h | 5 ++++- src/snmalloc/backend_helpers/globalrange.h | 8 +++++--- src/snmalloc/backend_helpers/largebuddyrange.h | 4 +++- src/snmalloc/backend_helpers/logrange.h | 8 +++++--- src/snmalloc/backend_helpers/pagemapregisterrange.h | 6 ++++-- src/snmalloc/backend_helpers/palrange.h | 2 ++ src/snmalloc/backend_helpers/smallbuddyrange.h | 4 +++- src/snmalloc/backend_helpers/statsrange.h | 8 +++++--- src/snmalloc/backend_helpers/subrange.h | 6 ++++-- 11 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/snmalloc/backend/standard_range.h b/src/snmalloc/backend/standard_range.h index d07c9a504..b9a2d5b79 100644 --- a/src/snmalloc/backend/standard_range.h +++ b/src/snmalloc/backend/standard_range.h @@ -22,7 +22,7 @@ namespace snmalloc template< typename PAL, typename Pagemap, - typename Base = EmptyRange, + typename Base = EmptyRange<>, size_t MinSizeBits = MinBaseSizeBits()> struct StandardLocalState : BaseLocalStateConstants { diff --git a/src/snmalloc/backend_helpers/commitrange.h b/src/snmalloc/backend_helpers/commitrange.h index de67a1367..2bbd7a583 100644 --- a/src/snmalloc/backend_helpers/commitrange.h +++ b/src/snmalloc/backend_helpers/commitrange.h @@ -18,9 +18,14 @@ namespace snmalloc static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + using ChunkBounds = typename ParentRange::ChunkBounds; + static_assert( + ChunkBounds::address_space_control == + capptr::dimension::AddressSpaceControl::Full); + constexpr Type() = default; - capptr::Chunk alloc_range(size_t size) + CapPtr alloc_range(size_t size) { SNMALLOC_ASSERT_MSG( (size % PAL::page_size) == 0, @@ -33,7 +38,7 @@ namespace snmalloc return range; } - void dealloc_range(capptr::Chunk base, size_t size) + void dealloc_range(CapPtr base, size_t size) { SNMALLOC_ASSERT_MSG( (size % PAL::page_size) == 0, diff --git a/src/snmalloc/backend_helpers/empty_range.h b/src/snmalloc/backend_helpers/empty_range.h index 6507a01e3..c4eb16090 100644 --- a/src/snmalloc/backend_helpers/empty_range.h +++ b/src/snmalloc/backend_helpers/empty_range.h @@ -3,6 +3,7 @@ namespace snmalloc { + template class EmptyRange { public: @@ -10,9 +11,11 @@ namespace snmalloc static constexpr bool ConcurrencySafe = true; + using ChunkBounds = B; + constexpr EmptyRange() = default; - capptr::Chunk alloc_range(size_t) + CapPtr alloc_range(size_t) { return nullptr; } diff --git a/src/snmalloc/backend_helpers/globalrange.h b/src/snmalloc/backend_helpers/globalrange.h index 3e01c3d09..760ad21d7 100644 --- a/src/snmalloc/backend_helpers/globalrange.h +++ b/src/snmalloc/backend_helpers/globalrange.h @@ -11,7 +11,7 @@ namespace snmalloc */ struct GlobalRange { - template + template> class Type : public StaticParent { using StaticParent::parent; @@ -27,15 +27,17 @@ namespace snmalloc static constexpr bool ConcurrencySafe = true; + using ChunkBounds = typename ParentRange::ChunkBounds; + constexpr Type() = default; - capptr::Chunk alloc_range(size_t size) + CapPtr alloc_range(size_t size) { FlagLock lock(spin_lock); return parent.alloc_range(size); } - void dealloc_range(capptr::Chunk base, size_t size) + void dealloc_range(CapPtr base, size_t size) { FlagLock lock(spin_lock); parent.dealloc_range(base, size); diff --git a/src/snmalloc/backend_helpers/largebuddyrange.h b/src/snmalloc/backend_helpers/largebuddyrange.h index 7d315973f..379cb5d46 100644 --- a/src/snmalloc/backend_helpers/largebuddyrange.h +++ b/src/snmalloc/backend_helpers/largebuddyrange.h @@ -208,7 +208,7 @@ namespace snmalloc bits::one_at_bit(MIN_REFILL_SIZE_BITS); public: - template + template> class Type : public ContainsParent { using ContainsParent::parent; @@ -341,6 +341,8 @@ namespace snmalloc static constexpr bool ConcurrencySafe = false; + using ChunkBounds = capptr::bounds::Chunk; + constexpr Type() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/snmalloc/backend_helpers/logrange.h b/src/snmalloc/backend_helpers/logrange.h index 9bc1d4731..0a3f907de 100644 --- a/src/snmalloc/backend_helpers/logrange.h +++ b/src/snmalloc/backend_helpers/logrange.h @@ -14,7 +14,7 @@ namespace snmalloc template struct LogRange { - template + template> class Type : public ContainsParent { using ContainsParent::parent; @@ -24,9 +24,11 @@ namespace snmalloc static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + using ChunkBounds = typename ParentRange::ChunkBounds; + constexpr Type() = default; - capptr::Chunk alloc_range(size_t size) + CapPtr alloc_range(size_t size) { #ifdef SNMALLOC_TRACING message<1024>("Call alloc_range({}) on {}", size, RangeName); @@ -39,7 +41,7 @@ namespace snmalloc return range; } - void dealloc_range(capptr::Chunk base, size_t size) + void dealloc_range(CapPtr base, size_t size) { #ifdef SNMALLOC_TRACING message<1024>( diff --git a/src/snmalloc/backend_helpers/pagemapregisterrange.h b/src/snmalloc/backend_helpers/pagemapregisterrange.h index 7201f8ff9..9a0019e33 100644 --- a/src/snmalloc/backend_helpers/pagemapregisterrange.h +++ b/src/snmalloc/backend_helpers/pagemapregisterrange.h @@ -11,7 +11,7 @@ namespace snmalloc bool CanConsolidate = true> struct PagemapRegisterRange { - template + template> class Type : public ContainsParent { using ContainsParent::parent; @@ -23,7 +23,9 @@ namespace snmalloc static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; - capptr::Chunk alloc_range(size_t size) + using ChunkBounds = typename ParentRange::ChunkBounds; + + CapPtr alloc_range(size_t size) { auto base = parent.alloc_range(size); diff --git a/src/snmalloc/backend_helpers/palrange.h b/src/snmalloc/backend_helpers/palrange.h index 0962e00bf..efa324ee1 100644 --- a/src/snmalloc/backend_helpers/palrange.h +++ b/src/snmalloc/backend_helpers/palrange.h @@ -14,6 +14,8 @@ namespace snmalloc // need to be changed. static constexpr bool ConcurrencySafe = true; + using ChunkBounds = capptr::bounds::Chunk; + constexpr PalRange() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/snmalloc/backend_helpers/smallbuddyrange.h b/src/snmalloc/backend_helpers/smallbuddyrange.h index fc42d6f7d..8e7de038e 100644 --- a/src/snmalloc/backend_helpers/smallbuddyrange.h +++ b/src/snmalloc/backend_helpers/smallbuddyrange.h @@ -145,7 +145,7 @@ namespace snmalloc struct SmallBuddyRange { - template + template> class Type : public ContainsParent { using ContainsParent::parent; @@ -187,6 +187,8 @@ namespace snmalloc static constexpr bool ConcurrencySafe = false; + using ChunkBounds = capptr::bounds::Chunk; + constexpr Type() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/snmalloc/backend_helpers/statsrange.h b/src/snmalloc/backend_helpers/statsrange.h index f38f6e999..8548be9cb 100644 --- a/src/snmalloc/backend_helpers/statsrange.h +++ b/src/snmalloc/backend_helpers/statsrange.h @@ -12,7 +12,7 @@ namespace snmalloc */ struct StatsRange { - template + template> class Type : public ContainsParent { using ContainsParent::parent; @@ -25,9 +25,11 @@ namespace snmalloc static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + using ChunkBounds = typename ParentRange::ChunkBounds; + constexpr Type() = default; - capptr::Chunk alloc_range(size_t size) + CapPtr alloc_range(size_t size) { auto result = parent.alloc_range(size); if (result != nullptr) @@ -43,7 +45,7 @@ namespace snmalloc return result; } - void dealloc_range(capptr::Chunk base, size_t size) + void dealloc_range(CapPtr base, size_t size) { current_usage -= size; parent.dealloc_range(base, size); diff --git a/src/snmalloc/backend_helpers/subrange.h b/src/snmalloc/backend_helpers/subrange.h index 03c782539..8d886a2b8 100644 --- a/src/snmalloc/backend_helpers/subrange.h +++ b/src/snmalloc/backend_helpers/subrange.h @@ -12,7 +12,7 @@ namespace snmalloc template struct SubRange { - template + template> class Type : public ContainsParent { using ContainsParent::parent; @@ -24,7 +24,9 @@ namespace snmalloc static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; - capptr::Chunk alloc_range(size_t sub_size) + using ChunkBounds = typename ParentRange::ChunkBounds; + + CapPtr alloc_range(size_t sub_size) { SNMALLOC_ASSERT(bits::is_pow2(sub_size));