Skip to content

Commit ce02869

Browse files
authored
[k2] request extra memory in power-of-two multiples (#1624)
Signed-off-by: Petr Shumilov <p.shumilov@vkteam.ru>
1 parent 5e9b9bb commit ce02869

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

runtime-light/allocator/runtime-light-allocator.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the GPL v3 License, see LICENSE.notice.txt
44

55
#include <algorithm>
6+
#include <bit>
67
#include <cstddef>
78
#include <cstring>
89

@@ -105,11 +106,11 @@ void RuntimeAllocator::request_extra_memory(size_t requested_size) noexcept {
105106
// Extra mem size have to be greater than max chunk block
106107
const auto min_size{std::max(m_min_extra_mem_size, memory_resource::unsynchronized_pool_resource::MAX_CHUNK_BLOCK_SIZE)};
107108

108-
// 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.
109-
size_t extra_mem_size{std::max(min_size, 2 * requested_size)};
110-
109+
size_t extra_mem_size{std::max(min_size, requested_size)};
111110
// Take into account internal layout of `memory_resource::extra_memory_pool`
112111
extra_mem_size += sizeof(memory_resource::extra_memory_pool);
112+
// The smallest power of two that is not smaller than `extra_mem_size`
113+
extra_mem_size = std::bit_ceil(extra_mem_size);
113114

114115
// kphp::log::debug("requested extra memory pool with size {} bytes, will be allocated {} bytes", requested_size, extra_mem_size);
115116

0 commit comments

Comments
 (0)