-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 MemoryReservation::{split_off, take, new_empty} #7184
Conversation
6519c23
to
de90257
Compare
@@ -159,21 +163,22 @@ impl MemoryPool for FairSpillPool { | |||
|
|||
fn unregister(&self, consumer: &MemoryConsumer) { | |||
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(); |
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.
this will now panic rather than silently underflow
@@ -247,7 +252,7 @@ mod tests { | |||
r1.grow(2000); | |||
assert_eq!(pool.reserved(), 2000); | |||
|
|||
let mut r2 = MemoryConsumer::new("s1") |
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 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.
#[derive(Debug)] | ||
pub struct MemoryReservation { | ||
struct SharedRegistration { |
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.
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 { |
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.
here are the new APIs
} | ||
|
||
impl Drop for MemoryReservation { | ||
fn drop(&mut self) { | ||
self.free(); | ||
self.policy.unregister(&self.consumer); |
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.
This is moved to SharedReservation::drop
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?