Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

tanjialiang
Copy link
Contributor

@tanjialiang tanjialiang commented Aug 14, 2023

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.

@netlify
Copy link

netlify bot commented Aug 14, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 262f97a
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/64dd0d65f50ec5000831760e

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 14, 2023
Copy link
Contributor

@xiaoxmeng xiaoxmeng left a 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.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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);

Copy link
Contributor Author

@tanjialiang tanjialiang Aug 16, 2023

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.

Copy link
Contributor

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
Copy link
Contributor

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()}
Copy link
Contributor

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()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@facebook-github-bot
Copy link
Contributor

@tanjialiang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@kgpai
Copy link
Contributor

kgpai commented Aug 16, 2023

@tanjialiang can you investigate why we see an inf loop during the presto fuzzer runs ?

@kgpai
Copy link
Contributor

kgpai commented Aug 16, 2023

@tanjialiang Command to use :

./_build/debug/velox/expression/tests/velox_expression_fuzzer_test --seed 604401866 --lazy_vector_generation_ratio 0.2 \
--duration_sec 600 \
--enable_variadic_signatures \
--velox_fuzzer_enable_complex_types \
--velox_fuzzer_enable_column_reuse \
--velox_fuzzer_enable_expression_reuse \
--max_expression_trees_per_step 2 \
--retry_with_try \
--enable_dereference \
--logtostderr=1 --minloglevel=0 \
--repro_persist_path=/tmp/fuzzer_repro

@facebook-github-bot
Copy link
Contributor

@tanjialiang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@tanjialiang merged this pull request in d2ebb4e.

@conbench-facebook
Copy link

Conbench analyzed the 1 benchmark run on commit d2ebb4e3.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

unigof pushed a commit to unigof/velox that referenced this pull request Aug 18, 2023
…or#6102)

Summary: Pull Request resolved: facebookincubator#6102

Reviewed By: xiaoxmeng

Differential Revision: D48362262

Pulled By: tanjialiang

fbshipit-source-id: 5ac3d1deef75cb6a745a4d8644d2f7fc398d5469
facebook-github-bot pushed a commit that referenced this pull request Aug 23, 2023
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
ericyuliu pushed a commit to ericyuliu/velox that referenced this pull request Oct 12, 2023
…or#6102)

Summary: Pull Request resolved: facebookincubator#6102

Reviewed By: xiaoxmeng

Differential Revision: D48362262

Pulled By: tanjialiang

fbshipit-source-id: 5ac3d1deef75cb6a745a4d8644d2f7fc398d5469
ericyuliu pushed a commit to ericyuliu/velox that referenced this pull request Oct 12, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants