From 0a4294e48df8912b83fc5990848afac8601a4deb Mon Sep 17 00:00:00 2001 From: Bobby Powers Date: Fri, 5 Apr 2024 22:31:43 -0700 Subject: [PATCH] common: define kMiniHeapSize and use it in MeshableArena's CheapHeap (#108) --- src/common.h | 5 +++++ src/meshable_arena.h | 2 +- src/mini_heap.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 5aa9d2aa..83310511 100644 --- a/src/common.h +++ b/src/common.h @@ -69,6 +69,11 @@ static constexpr int kMapShared = 1; static constexpr int kMapShared = kMeshingEnabled ? MAP_SHARED : MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; #endif +// we have to define this here for use in meshable_arena's CheapHeap we allocate +// MiniHeaps out of. We validate (and fail compilation) if this gets out of date +// with a static_assert at the bottom of mini_heap.h +static constexpr size_t kMiniHeapSize = 64; + static constexpr size_t kMinObjectSize = 16; static constexpr size_t kMaxSize = 16384; static constexpr size_t kClassSizesMax = 25; diff --git a/src/meshable_arena.h b/src/meshable_arena.h index 09042159..b4a340df 100644 --- a/src/meshable_arena.h +++ b/src/meshable_arena.h @@ -277,7 +277,7 @@ class MeshableArena : public mesh::OneWayMmapHeap { atomic *_mhIndex{nullptr}; protected: - CheapHeap<64, kArenaSize / kPageSize> _mhAllocator{}; + CheapHeap _mhAllocator{}; MWC _fastPrng; private: diff --git a/src/mini_heap.h b/src/mini_heap.h index 1451da0a..a480b22e 100644 --- a/src/mini_heap.h +++ b/src/mini_heap.h @@ -526,6 +526,7 @@ typedef FixedArray MiniHeapArray; static_assert(sizeof(pid_t) == 4, "pid_t not 32-bits!"); static_assert(sizeof(mesh::internal::Bitmap) == 32, "Bitmap too big!"); static_assert(sizeof(MiniHeap) == 64, "MiniHeap too big!"); +static_assert(sizeof(MiniHeap) == kMiniHeapSize, "MiniHeap size mismatch"); static_assert(sizeof(MiniHeapArray) == 64 * sizeof(void *), "MiniHeapArray too big!"); } // namespace mesh