From ab21ff5b503a48cfabc3b453d3e9c1f9e14b9686 Mon Sep 17 00:00:00 2001
From: Petr Shumilov
Date: Wed, 29 Apr 2026 18:47:55 +0300
Subject: [PATCH] Request extra memory in power-of-two multiples
Signed-off-by: Petr Shumilov
---
runtime-light/allocator/runtime-light-allocator.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/runtime-light/allocator/runtime-light-allocator.cpp b/runtime-light/allocator/runtime-light-allocator.cpp
index ea2ceb7819..8234c5ebb7 100644
--- a/runtime-light/allocator/runtime-light-allocator.cpp
+++ b/runtime-light/allocator/runtime-light-allocator.cpp
@@ -3,6 +3,7 @@
// Distributed under the GPL v3 License, see LICENSE.notice.txt
#include
+#include
#include
#include
@@ -105,11 +106,11 @@ void RuntimeAllocator::request_extra_memory(size_t requested_size) noexcept {
// Extra mem size have to be greater than max chunk block
const auto min_size{std::max(m_min_extra_mem_size, memory_resource::unsynchronized_pool_resource::MAX_CHUNK_BLOCK_SIZE)};
- // If the requested size is greater than or equal to half of min_size, it’s more efficient to allocate a multiple of the requested size.
- size_t extra_mem_size{std::max(min_size, 2 * requested_size)};
-
+ size_t extra_mem_size{std::max(min_size, requested_size)};
// Take into account internal layout of `memory_resource::extra_memory_pool`
extra_mem_size += sizeof(memory_resource::extra_memory_pool);
+ // The smallest power of two that is not smaller than `extra_mem_size`
+ extra_mem_size = std::bit_ceil(extra_mem_size);
// kphp::log::debug("requested extra memory pool with size {} bytes, will be allocated {} bytes", requested_size, extra_mem_size);