From dae7674ca98e7e63e7644cac96d424179ca8bd43 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 2 Aug 2021 15:04:15 -0400 Subject: [PATCH] AK: Allow configuring the BumpAllocator chunk size --- AK/BumpAllocator.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/AK/BumpAllocator.h b/AK/BumpAllocator.h index 94af3b251c..9f67fe4627 100644 --- a/AK/BumpAllocator.h +++ b/AK/BumpAllocator.h @@ -13,15 +13,15 @@ namespace AK { -template +template class BumpAllocator { public: BumpAllocator() { if constexpr (use_mmap) - m_chunk_size = 4 * MiB; + m_chunk_size = chunk_size; else - m_chunk_size = kmalloc_good_size(4 * KiB); + m_chunk_size = kmalloc_good_size(chunk_size); } ~BumpAllocator() @@ -137,8 +137,10 @@ protected: // size_t m_allocations_in_previous_chunk { 0 }; }; -template -class UniformBumpAllocator : protected BumpAllocator { +template +class UniformBumpAllocator : protected BumpAllocator { + using Allocator = BumpAllocator; + public: UniformBumpAllocator() = default; ~UniformBumpAllocator() @@ -148,19 +150,19 @@ public: T* allocate() { - return BumpAllocator::template allocate(); + return Allocator::template allocate(); } void deallocate_all() { destroy_all(); - BumpAllocator::deallocate_all(); + Allocator::deallocate_all(); } void destroy_all() { this->for_each_chunk([&](auto chunk) { - auto base_ptr = align_up_to(chunk + sizeof(typename BumpAllocator::ChunkHeader), alignof(T)); + auto base_ptr = align_up_to(chunk + sizeof(typename Allocator::ChunkHeader), alignof(T)); FlatPtr end_offset = this->m_chunk_size; if (chunk == this->m_current_chunk) end_offset = this->m_byte_offset_into_current_chunk;