From 853dfe3c65cf3db7d761fe5bbb103d3e45dbf898 Mon Sep 17 00:00:00 2001 From: Gareth Lloyd Date: Mon, 11 Mar 2024 13:23:27 +0000 Subject: [PATCH] Tune multipool sizes --- src/utils/memory.cpp | 12 ++++++------ src/utils/memory.hpp | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp index e5df27664..f46d6bb79 100644 --- a/src/utils/memory.cpp +++ b/src/utils/memory.cpp @@ -154,13 +154,13 @@ Pool::Pool(size_t block_size, unsigned char blocks_per_chunk, MemoryResource *ch : blocks_per_chunk_(blocks_per_chunk), block_size_(block_size), data_size_{blocks_per_chunk_ * block_size_}, - alignment_{Ceil2(block_size_)}, chunks_(chunk_memory) { // Use the next pow2 of block_size_ as alignment, so that we cover alignment // requests between 1 and block_size_. Users of this class should make sure // that requested alignment of particular blocks is never greater than the // block itself. if (block_size_ > std::numeric_limits::max() / blocks_per_chunk_) throw BadAlloc("Allocation size overflow"); + alignment_ = Ceil2(block_size_); if (alignment_ < block_size_) throw BadAlloc("Allocation alignment overflow"); } @@ -381,10 +381,10 @@ void *PoolResource2::DoAllocate(size_t bytes, size_t alignment) { // as malloc/free. if (block_size % alignment != 0) throw BadAlloc("Requested bytes must be a multiple of alignment"); - if (pools_4bit_.is_above_upper_bound(block_size)) return unpooled_memory_->Allocate(bytes, alignment); - if (pools_2bit_.is_size_handled(block_size)) return pools_2bit_.allocate(block_size); + if (pools_5bit_.is_above_upper_bound(block_size)) return unpooled_memory_->Allocate(bytes, alignment); if (pools_3bit_.is_size_handled(block_size)) return pools_3bit_.allocate(block_size); if (pools_4bit_.is_size_handled(block_size)) return pools_4bit_.allocate(block_size); + if (pools_5bit_.is_size_handled(block_size)) return pools_5bit_.allocate(block_size); DMG_ASSERT(block_size <= 8); return pool_8_.Allocate(); } @@ -392,14 +392,14 @@ void PoolResource2::DoDeallocate(void *p, size_t bytes, size_t alignment) { size_t block_size = std::max(bytes, alignment); DMG_ASSERT(block_size % alignment == 0); - if (pools_4bit_.is_above_upper_bound(block_size)) { + if (pools_5bit_.is_above_upper_bound(block_size)) { unpooled_memory_->Deallocate(p, bytes, alignment); - } else if (pools_2bit_.is_size_handled(block_size)) { - pools_2bit_.deallocate(p, block_size); } else if (pools_3bit_.is_size_handled(block_size)) { pools_3bit_.deallocate(p, block_size); } else if (pools_4bit_.is_size_handled(block_size)) { pools_4bit_.deallocate(p, block_size); + } else if (pools_5bit_.is_size_handled(block_size)) { + pools_5bit_.deallocate(p, block_size); } else { DMG_ASSERT(block_size <= 8); pool_8_.Deallocate(p); diff --git a/src/utils/memory.hpp b/src/utils/memory.hpp index 3013b1b73..b454c7073 100644 --- a/src/utils/memory.hpp +++ b/src/utils/memory.hpp @@ -595,9 +595,9 @@ class PoolResource2 final : public MemoryResource { PoolResource2(uint8_t blocks_per_chunk, MemoryResource *memory = NewDeleteResource(), MemoryResource *internal_memory = NewDeleteResource()) : pool_8_(8, blocks_per_chunk, memory), - pools_2bit_(blocks_per_chunk, memory, internal_memory), pools_3bit_(blocks_per_chunk, memory, internal_memory), pools_4bit_(blocks_per_chunk, memory, internal_memory), + pools_5bit_(blocks_per_chunk, memory, internal_memory), unpooled_memory_{internal_memory} {} ~PoolResource2() override = default; @@ -608,9 +608,9 @@ class PoolResource2 final : public MemoryResource { private: impl::Pool pool_8_; - impl::MultiPool<2, 8, 128> pools_2bit_; - impl::MultiPool<3, 128, 512> pools_3bit_; - impl::MultiPool<4, 512, 1024> pools_4bit_; + impl::MultiPool<3, 8, 128> pools_3bit_; + impl::MultiPool<4, 128, 512> pools_4bit_; + impl::MultiPool<5, 512, 1024> pools_5bit_; MemoryResource *unpooled_memory_; };