Add MemoryReservation::{split_off, take, new_empty}#7184
Merged
alamb merged 2 commits intoapache:mainfrom Aug 3, 2023
Merged
Conversation
6519c23 to
de90257
Compare
alamb
commented
Aug 2, 2023
| if consumer.can_spill { | ||
| self.state.lock().num_spill -= 1; | ||
| let mut state = self.state.lock(); | ||
| state.num_spill = state.num_spill.checked_sub(1).unwrap(); |
Contributor
Author
There was a problem hiding this comment.
this will now panic rather than silently underflow
| r1.grow(2000); | ||
| assert_eq!(pool.reserved(), 2000); | ||
|
|
||
| let mut r2 = MemoryConsumer::new("s1") |
Contributor
Author
There was a problem hiding this comment.
I renamed the names to match the local variable names as the indirection of a different number was very confusing to me when debugging this test.
| /// the underlying pool. | ||
| #[derive(Debug)] | ||
| pub struct MemoryReservation { | ||
| struct SharedRegistration { |
Contributor
Author
There was a problem hiding this comment.
This structure allows different MemoryReservations to share the same consumer
| /// # Panics | ||
| /// | ||
| /// Panics if `capacity` exceeds [`Self::size`] | ||
| pub fn split(&mut self, capacity: usize) -> MemoryReservation { |
| impl Drop for MemoryReservation { | ||
| fn drop(&mut self) { | ||
| self.free(); | ||
| self.policy.unregister(&self.consumer); |
Contributor
Author
There was a problem hiding this comment.
This is moved to SharedReservation::drop
tustvold
approved these changes
Aug 2, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Part of #5885
Rationale for this change
This PR contains new MemoryReservation APIs used in #7130. They were originally written by @tustvold and I polished them up, fixed a bug, and added tests
I broke it into its own PR for ease in reviewing. You can see the usecase in #7130.
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?