From 72a54c9eb186735cad3f9e0b98cc2b2385220fee Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 16 Mar 2026 13:55:09 +0100 Subject: kernel/heap: improve large alignment handling --- kernel/include/kernel/memory/block_list_allocator.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'kernel/include') diff --git a/kernel/include/kernel/memory/block_list_allocator.hpp b/kernel/include/kernel/memory/block_list_allocator.hpp index 977ce89..5e81c44 100644 --- a/kernel/include/kernel/memory/block_list_allocator.hpp +++ b/kernel/include/kernel/memory/block_list_allocator.hpp @@ -42,12 +42,21 @@ namespace kernel::memory private: struct block_header final { - std::size_t size; + std::size_t usable_size; bool free; block_header * next; block_header * prev; }; + //! The size of the metadata required for each allocated block. + //! + //! Each allocated block carries a block header, like any unallocated one, but in addition also has a back-pointer + //! to the block header to support padding due to alignment. + constexpr auto static allocated_metadata_size = sizeof(block_header) + sizeof(block_header *); + + //! The minimum number of bytes for an allocation. + constexpr auto static minimum_allocation_size = 16uz; + //! Try to expand the heap to accommodate the given size. //! //! @param delta The size to expand the heap by. -- cgit v1.2.3