diff --git a/velox/common/memory/MemoryPool.cpp b/velox/common/memory/MemoryPool.cpp index 7d5c0816b42d..9a833bcf1dc0 100644 --- a/velox/common/memory/MemoryPool.cpp +++ b/velox/common/memory/MemoryPool.cpp @@ -426,6 +426,12 @@ size_t MemoryPool::getPreferredSize(size_t size) { return lower * 2; } +void MemoryPool::setPreferredSize( + std::function getPreferredSizeFunc) { + VELOX_CHECK_NOT_NULL(getPreferredSizeFunc); + getPreferredSize_ = getPreferredSizeFunc; +} + MemoryPoolImpl::MemoryPoolImpl( MemoryManager* memoryManager, const std::string& name, diff --git a/velox/common/memory/MemoryPool.h b/velox/common/memory/MemoryPool.h index 699f3c91547c..77cd1110c9c3 100644 --- a/velox/common/memory/MemoryPool.h +++ b/velox/common/memory/MemoryPool.h @@ -473,6 +473,9 @@ class MemoryPool : public std::enable_shared_from_this { return bits::roundUp(size, 8 * kMB); } + // Overrides getPreferredSize to allow specializing behavior for this pool. + void setPreferredSize(std::function getPreferredSizeFunc); + protected: static constexpr uint64_t kMB = 1 << 20; @@ -530,7 +533,7 @@ class MemoryPool : public std::enable_shared_from_this { const bool threadSafe_; const bool debugEnabled_; const bool coreOnAllocationFailureEnabled_; - const std::function getPreferredSize_; + std::function getPreferredSize_; /// Indicates if the memory pool has been aborted by the memory arbitrator or /// not.