pub struct MergeMemoryPool { /* private fields */ }Expand description
Shares reserved merge workspace across child reservations and temporary loans.
This pool charges a single reservation to its parent MemoryPool. After
acquiring workspace through a child MemoryReservation, call Self::retain
to keep that capacity available even when children release their reservations.
Children and WorkspaceLoans share this capacity; only usage above the
existing parent reservation requires additional parent memory. Call
Self::release_unused when no further merge needs the idle workspace.
Live children and loans keep the pool and their reserved memory alive.
All parent accounting and allocation policy uses the MemoryConsumer
supplied to Self::new. Child consumers are not registered with the parent,
so their names and MemoryConsumer::can_spill flags do not affect the
parent’s accounting or fair shares. Consumers that need a separate parent
allocation policy should register directly with the parent. They can borrow
already-acquired workspace with Self::borrow and request any additional
capacity through their own reservation.
§Example
let parent: Arc<dyn MemoryPool> = Arc::new(GreedyMemoryPool::new(100));
let workspace = Arc::new(MergeMemoryPool::new(
Arc::clone(&parent),
MemoryConsumer::new("merge workspace"),
));
let pool: Arc<dyn MemoryPool> = Arc::clone(&workspace) as _;
let reservation = MemoryConsumer::new("merge children").register(&pool);
reservation.try_grow(60)?;
workspace.retain(60);
reservation.free();
// Another operator can use only the space outside the retained workspace.
let contender = MemoryConsumer::new("contender").register(&parent);
contender.try_grow(40)?;
assert_eq!(parent.reserved(), 100);
// Children and loans reuse that workspace without another parent grant.
let cursor = reservation.new_empty();
cursor.try_grow(20)?;
let loan = workspace.borrow(60);
assert_eq!(loan.size(), 40);
workspace.release_unused();
assert_eq!(parent.reserved(), 100); // Both the cursor and loan remain charged.
drop(loan);
assert_eq!(parent.reserved(), 60); // Only the cursor and contender remain.Implementations§
Source§impl MergeMemoryPool
impl MergeMemoryPool
Sourcepub fn new(parent: Arc<dyn MemoryPool>, consumer: MemoryConsumer) -> Self
pub fn new(parent: Arc<dyn MemoryPool>, consumer: MemoryConsumer) -> Self
Creates a pool whose memory is charged to consumer in parent.
Registers the consumer without reserving any memory. The consumer’s allocation policy applies to the combined usage of all children and loans.
Sourcepub fn retain(&self, size: usize)
pub fn retain(&self, size: usize)
Sets the amount of acquired workspace to retain when children release it.
The workspace must first be acquired through a child reservation. This
method sets the retained floor without changing the parent reservation.
Use Self::release_unused to stop retaining idle workspace immediately.
§Panics
Panics if size exceeds this pool’s current reservation in the parent,
as reported by its MemoryPool::reserved method.
Sourcepub fn borrow(self: &Arc<Self>, size: usize) -> WorkspaceLoan
pub fn borrow(self: &Arc<Self>, size: usize) -> WorkspaceLoan
Lends up to size unused bytes without acquiring more parent memory.
Returns a smaller loan if less workspace is available, including an empty loan if all capacity is in use. The loan is counted alongside child reservations so they cannot spend the same credit. Dropping it returns any outstanding bytes.
Sourcepub fn release_unused(&self)
pub fn release_unused(&self)
Stops retaining idle workspace and returns unused capacity to the parent.
Live child reservations and loans remain charged. Their future releases
also return memory to the parent, unless Self::retain is called again.
Trait Implementations§
Source§impl Debug for MergeMemoryPool
impl Debug for MergeMemoryPool
Source§impl Display for MergeMemoryPool
impl Display for MergeMemoryPool
Source§impl MemoryPool for MergeMemoryPool
impl MemoryPool for MergeMemoryPool
Source§fn grow(&self, _reservation: &MemoryReservation, additional: usize)
fn grow(&self, _reservation: &MemoryReservation, additional: usize)
Source§fn shrink(&self, _reservation: &MemoryReservation, subtractive: usize)
fn shrink(&self, _reservation: &MemoryReservation, subtractive: usize)
reservation by shrink bytesSource§fn memory_limit(&self) -> MemoryLimit
fn memory_limit(&self) -> MemoryLimit
Source§fn register(&self, _consumer: &MemoryConsumer)
fn register(&self, _consumer: &MemoryConsumer)
MemoryConsumer Read moreSource§fn unregister(&self, _consumer: &MemoryConsumer)
fn unregister(&self, _consumer: &MemoryConsumer)
Auto Trait Implementations§
impl !Freeze for MergeMemoryPool
impl !RefUnwindSafe for MergeMemoryPool
impl !UnwindSafe for MergeMemoryPool
impl Forget for MergeMemoryPool
impl Move for MergeMemoryPool
impl Send for MergeMemoryPool
impl Sync for MergeMemoryPool
impl Unpin for MergeMemoryPool
impl UnsafeUnpin for MergeMemoryPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more