Skip to content

Commit a34e1b2

Browse files
joegfacebook-github-bot
authored andcommitted
misc(memory) - Enable preferred memory size override for MemoryPool (#12712)
Summary: Pull Request resolved: #12712 Enable overrides for getPreferredSize behavior on a per memory pool basis Reviewed By: xiaoxmeng Differential Revision: D71427371 fbshipit-source-id: ce4e1c9682de7d00af97ca7eb9a6323c4c8ffd02
1 parent 74b451a commit a34e1b2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

velox/common/memory/MemoryPool.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ size_t MemoryPool::getPreferredSize(size_t size) {
426426
return lower * 2;
427427
}
428428

429+
void MemoryPool::setPreferredSize(
430+
std::function<size_t(size_t)> getPreferredSizeFunc) {
431+
VELOX_CHECK_NOT_NULL(getPreferredSizeFunc);
432+
getPreferredSize_ = getPreferredSizeFunc;
433+
}
434+
429435
MemoryPoolImpl::MemoryPoolImpl(
430436
MemoryManager* memoryManager,
431437
const std::string& name,

velox/common/memory/MemoryPool.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ class MemoryPool : public std::enable_shared_from_this<MemoryPool> {
473473
return bits::roundUp(size, 8 * kMB);
474474
}
475475

476+
// Overrides getPreferredSize to allow specializing behavior for this pool.
477+
void setPreferredSize(std::function<size_t(size_t)> getPreferredSizeFunc);
478+
476479
protected:
477480
static constexpr uint64_t kMB = 1 << 20;
478481

@@ -530,7 +533,7 @@ class MemoryPool : public std::enable_shared_from_this<MemoryPool> {
530533
const bool threadSafe_;
531534
const bool debugEnabled_;
532535
const bool coreOnAllocationFailureEnabled_;
533-
const std::function<size_t(size_t)> getPreferredSize_;
536+
std::function<size_t(size_t)> getPreferredSize_;
534537

535538
/// Indicates if the memory pool has been aborted by the memory arbitrator or
536539
/// not.

0 commit comments

Comments
 (0)