-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shrinkPool API to MemoryManager/MemoryArbitrator #6102
Conversation
✅ Deploy Preview for meta-velox canceled.
|
c3ccfaf
to
f192b70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanjialiang thanks for the change. LGTM % minors.
velox/common/memory/Memory.h
Outdated
@@ -157,6 +157,11 @@ class MemoryManager { | |||
/// 'incrementBytes'. The function returns true on success, otherwise false. | |||
bool growPool(MemoryPool* pool, uint64_t incrementBytes); | |||
|
|||
/// Invoked to shrink currently alive pools by 'targetBytes', by reducing this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "reducing this"? we can trigger memory reclaiming?
Consider
/// Invoked to shrink alive pools to free at least 'targetBytes' capacity. The function returns the actual freed memory capacity in bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed 'at least' because there might not be enough available memory to free to 'targetBytes' so the actual bytes freed might be smaller than 'targetBytes'. Also I think this is arbitrator implementation dependent so leaving more flexibility in words.
@@ -181,6 +181,11 @@ bool MemoryManager::growPool(MemoryPool* pool, uint64_t incrementBytes) { | |||
return arbitrator_->growMemory(pool, candidates, incrementBytes); | |||
} | |||
|
|||
uint64_t MemoryManager::shrinkPools(uint64_t targetBytes) { | |||
VELOX_CHECK_NOT_NULL(arbitrator_); | |||
return arbitrator_->shrinkMemory(getAlivePools(), targetBytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAlivePools() holds the memory pool while shrinking memory. So let's change to the following (as what growPool does)
// Holds a shared reference to each alive memory pool in 'pools_' to keep
// their aliveness during the memory arbitration process.
std::vector<std::shared_ptr<MemoryPool>> candidates = getAlivePools();
return arbitrator_->shrinkMemory(candidates, targetBytes);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference? Calling getAlivePools() will pass a copy of every shared_ptr to shrinkMemory() and hence keeping them alive. growPools() should make them a single line for simplicity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Could you make a change to growMemory? Thanks!
@@ -140,6 +140,13 @@ class MemoryArbitrator { | |||
const std::vector<std::shared_ptr<MemoryPool>>& candidatePools, | |||
uint64_t targetBytes) = 0; | |||
|
|||
/// Invoked by the memory manager to shrink memory for a given vector of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Invoked by the memory manager to shrink memory from a given set/list? of memory pools. The freed memory capacity is given back to the arbitrator. The function returns the actual freed memory capacity in bytes.
@@ -95,6 +95,10 @@ class FakeTestArbitrator : public MemoryArbitrator { | |||
const std::vector<std::shared_ptr<MemoryPool>>& candidatePools, | |||
uint64_t targetBytes) override{VELOX_NYI()} | |||
|
|||
uint64_t shrinkMemory( | |||
const std::vector<std::shared_ptr<MemoryPool>>& pools, | |||
uint64_t targetBytes) override{VELOX_NYI()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VELOX_NYI();
The same to the other places in this file. Thanks!
@@ -113,6 +113,10 @@ class FakeTestArbitrator : public MemoryArbitrator { | |||
const std::vector<std::shared_ptr<MemoryPool>>& candidatePools, | |||
uint64_t targetBytes) override{VELOX_NYI()} | |||
|
|||
uint64_t shrinkMemory( | |||
const std::vector<std::shared_ptr<MemoryPool>>& pools, | |||
uint64_t targetBytes) override{VELOX_NYI()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@tanjialiang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
f192b70
to
3ef57e9
Compare
@tanjialiang can you investigate why we see an inf loop during the presto fuzzer runs ? |
@tanjialiang Command to use :
|
3ef57e9
to
262f97a
Compare
@tanjialiang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@tanjialiang merged this pull request in d2ebb4e. |
Conbench analyzed the 1 benchmark run on commit There were no benchmark performance regressions. 🎉 The full Conbench report has more details. |
…or#6102) Summary: Pull Request resolved: facebookincubator#6102 Reviewed By: xiaoxmeng Differential Revision: D48362262 Pulled By: tanjialiang fbshipit-source-id: 5ac3d1deef75cb6a745a4d8644d2f7fc398d5469
Summary: Add NoopArbitrator and move the default arbitration behaviors defined in MemoryManager into it. This would make it clear to user to understand what will happen around memory pool's capacity when the arbitrator is not set explicitly. This also reduces code complexity in memory manager by removing "if (arbitrator_ == nullptr)" if-else blocks. Also, fixed some codes which may cause static initialization order issue. Based on #6102 's apporved code. Pull Request resolved: #6127 Reviewed By: tanjialiang Differential Revision: D48593508 Pulled By: xiaoxmeng fbshipit-source-id: f74cac2e096a03a523eb55afb65ca308c3d6c2ca
…or#6102) Summary: Pull Request resolved: facebookincubator#6102 Reviewed By: xiaoxmeng Differential Revision: D48362262 Pulled By: tanjialiang fbshipit-source-id: 5ac3d1deef75cb6a745a4d8644d2f7fc398d5469
…or#6127) Summary: Add NoopArbitrator and move the default arbitration behaviors defined in MemoryManager into it. This would make it clear to user to understand what will happen around memory pool's capacity when the arbitrator is not set explicitly. This also reduces code complexity in memory manager by removing "if (arbitrator_ == nullptr)" if-else blocks. Also, fixed some codes which may cause static initialization order issue. Based on facebookincubator#6102 's apporved code. Pull Request resolved: facebookincubator#6127 Reviewed By: tanjialiang Differential Revision: D48593508 Pulled By: xiaoxmeng fbshipit-source-id: f74cac2e096a03a523eb55afb65ca308c3d6c2ca
Adds shrinkPool API to MemoryManager and MemoryArbitrator to allow manual memory give back to MemoryAribitrator outside of arbitration process. This allows more flexible integration with external arbitration system for customized purposes.