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 arbitration participant and operation objects to support global memory arbitration optimization #11074

Closed
wants to merge 1 commit into from

Conversation

xiaoxmeng
Copy link
Contributor

Summary:
Add arbitration participant object to provide all the required arbitration operations and state management on a
query memory pool inside the memory arbitrator, such as arbitration queue to serialize the arbitration request execution
from the same query and the serialize the reclaim, shrink, grow and abort from either arbitration request and the
background memory arbitrations.

Add arbitration operation object to manage a memory arbitration request execution

Differential Revision: D63055730

@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 Sep 23, 2024
Copy link

netlify bot commented Sep 23, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit cd51932
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/66f248e33e781c0008364836

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D63055730

Comment on lines +58 to +77
uint64_t fastExponentialGrowthCapacityLimit;
double slowCapacityGrowRatio;

/// When shrinking a memory pool capacity, the shrink bytes will be adjusted
/// in a way such that AFTER shrink, the stricter (whichever is smaller) of
/// the following conditions is met, in order to better fit the query memory
/// pool's current memory usage:
/// - Free capacity is greater or equal to capacity *
/// 'minFreeCapacityRatio'
/// - Free capacity is greater or equal to 'minFreeCapacity'
///
/// NOTE: in the conditions when original requested shrink bytes ends up
/// with more free capacity than above 2 conditions, the adjusted shrink
/// bytes is not respected.
///
/// NOTE: capacity shrink adjustment is enabled when both
/// 'minFreeCapacityRatio' and 'minFreeCapacity' are set.
uint64_t minFreeCapacity;
double minFreeCapacityRatio;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we make the names consistent with other code locations? Here are the names in SharedArbitrator

  const uint64_t fastExponentialGrowthCapacityLimit_;
  const double slowCapacityGrowPct_;
  const uint64_t memoryPoolMinFreeCapacity_;
  const double memoryPoolMinFreeCapacityPct_;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This are the configs defined in ArbitrationParticipant for memory pool so we don't need memory pool prefix, and we shall change slowCapacityGrowPct_ to slowCapacityGrowRatio_

velox/common/memory/ArbitrationParticipant.h Outdated Show resolved Hide resolved
velox/common/memory/ArbitrationParticipant.h Show resolved Hide resolved
velox/common/memory/ArbitrationParticipant.h Outdated Show resolved Hide resolved
/// capacity growth target is set to have a coarser granularity. It can help
/// to reduce the number of future grow calls, and hence reducing the number
/// of unnecessary memory arbitration requests.
void getGrowTargets(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are doing the refactoring, could you also help to add documentations on the 2 return values? max and min grow bytes. Thanks

velox/common/memory/ArbitrationParticipant.h Outdated Show resolved Hide resolved
velox/common/memory/ArbitrationParticipant.h Outdated Show resolved Hide resolved
ArbitrationParticipant::Config::Config(
uint64_t _minCapacity,
uint64_t _fastExponentialGrowthCapacityLimit,
double _slowCapacityGrowRatio,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, shall we align these names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replied

}

uint64_t ArbitrationParticipant::maxShrinkCapacity() const {
const uint64_t capacity = pool_->capacity();
Copy link
Contributor

Choose a reason for hiding this comment

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

this local v is only used once

/// for the prior arbitration operations to finish first before executing to
/// ensure the serialized execution of arbitration operations from the same
/// query memory pool.
void startArbitration(ArbitrationOperation* op);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we rename this method to enqueueArbitration() as technically the arbitration is not started by this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the function returns, the operation is started so I think it is better to call this startArbitration.

/// latter ensures the serialized execution of arbitration operations from the
/// same query with one at a time. So this method blocks until all the prior
/// arbitration operations finish.
void start();
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly, start() method does not technically start the arbitration. Shall we rename it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replied

Comment on lines +82 to +93
uint64_t maxGrowBytes() const {
return maxGrowBytes_;
}

/// Returns the min grow bytes for this arbitration operation to ensure the
/// arbitration participant has the minimum amount of memory capacity. The
/// arbitrator might allocate memory from the reserved memory capacity pool
/// for the min grow bytes.
uint64_t minGrowBytes() const {
return minGrowBytes_;
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 methods going to be used in the followup PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes


/// Returns the allocated bytes by this arbitration operation.
uint64_t& allocatedBytes() {
return allocatedBytes_;
Copy link
Contributor

Choose a reason for hiding this comment

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

just make it public or protected if needed to be accessed like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in followup.

xiaoxmeng added a commit to xiaoxmeng/velox that referenced this pull request Sep 24, 2024
…emory arbitration optimization (facebookincubator#11074)

Summary:
Pull Request resolved: facebookincubator#11074

Add arbitration participant object to provide all the required arbitration operations and state management on a
query memory pool inside the memory arbitrator, such as arbitration queue to serialize the arbitration request execution
from the same query and the serialize the reclaim, shrink, grow and abort from either arbitration request and the
background memory arbitrations.

Add arbitration operation object to manage a memory arbitration request execution

Reviewed By: tanjialiang

Differential Revision: D63055730
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D63055730

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D63055730

xiaoxmeng added a commit to xiaoxmeng/velox that referenced this pull request Sep 24, 2024
…emory arbitration optimization (facebookincubator#11074)

Summary:
Pull Request resolved: facebookincubator#11074

Add arbitration participant object to provide all the required arbitration operations and state management on a
query memory pool inside the memory arbitrator, such as arbitration queue to serialize the arbitration request execution
from the same query and the serialize the reclaim, shrink, grow and abort from either arbitration request and the
background memory arbitrations.

Add arbitration operation object to manage a memory arbitration request execution

Reviewed By: tanjialiang

Differential Revision: D63055730
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D63055730

xiaoxmeng added a commit to xiaoxmeng/velox that referenced this pull request Sep 24, 2024
…emory arbitration optimization (facebookincubator#11074)

Summary:
Pull Request resolved: facebookincubator#11074

Add arbitration participant object to provide all the required arbitration operations and state management on a
query memory pool inside the memory arbitrator, such as arbitration queue to serialize the arbitration request execution
from the same query and the serialize the reclaim, shrink, grow and abort from either arbitration request and the
background memory arbitrations.

Add arbitration operation object to manage a memory arbitration request execution

Reviewed By: tanjialiang

Differential Revision: D63055730
…emory arbitration optimization (facebookincubator#11074)

Summary:
Pull Request resolved: facebookincubator#11074

Add arbitration participant object to provide all the required arbitration operations and state management on a
query memory pool inside the memory arbitrator, such as arbitration queue to serialize the arbitration request execution
from the same query and the serialize the reclaim, shrink, grow and abort from either arbitration request and the
background memory arbitrations.

Add arbitration operation object to manage a memory arbitration request execution

Reviewed By: tanjialiang

Differential Revision: D63055730
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D63055730

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in dcaae29.

Copy link

Conbench analyzed the 1 benchmark run on commit dcaae293.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

@xiaoxmeng xiaoxmeng deleted the export-D63055730 branch September 24, 2024 14:54
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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants