pub struct DefragmentationContext<'allocator, 'device> { /* private fields */ }Expand description
Persistent multi-pass relocation state with one exclusive allocator borrow.
Ignored allocations stay immovable for subsequent passes in this context.
Each pass must be explicitly resolved and finished; neither context nor pass
Drop submits, waits or destroys native resources. An abandoned unresolved pass
leaks its reservations, as documented by DefragmentationPass.
Initial per-domain order, Balanced averages and Extensive evacuation/packing
phases persist across passes. Extensive holds its blocks for reuse until
explicit finish; Drop clears host holds but never frees native memory.
Implementations§
Source§impl<'allocator, 'device> DefragmentationContext<'allocator, 'device>
impl<'allocator, 'device> DefragmentationContext<'allocator, 'device>
Sourcepub fn new(
allocator: &'allocator mut Allocator<'device>,
info: &DefragmentationInfo<'_>,
) -> Result<Self, AllocError>
pub fn new( allocator: &'allocator mut Allocator<'device>, info: &DefragmentationInfo<'_>, ) -> Result<Self, AllocError>
Retain one allocator and optional TLSF pool for successive bounded passes.
No placement reservation or native effect occurs until begin_pass.
§Errors
Rejects closed/foreign/stale pools, linear-pool relocation and host metadata failure.
Sourcepub unsafe fn begin_pass(
&mut self,
) -> Result<DefragmentationPass<'_, 'device>, AllocError>
pub unsafe fn begin_pass( &mut self, ) -> Result<DefragmentationPass<'_, 'device>, AllocError>
Reserve another bounded pass, excluding previously ignored source identities.
Extensive may move into a later evacuated block to pack compatible classes.
is_empty means this pass proposed no move under its policy and copy limits.
§Errors
Preserves policy/host metadata/planning errors without changing source storage.
§Safety
Same live-source, completed-copy and explicit move-resolution obligations as
mem::begin_defragmentation. Finish/abort every pass before beginning another.
Sourcepub unsafe fn begin_pass_with_break(
&mut self,
should_break: &mut dyn FnMut() -> bool,
) -> Result<DefragmentationPass<'_, 'device>, AllocError>
pub unsafe fn begin_pass_with_break( &mut self, should_break: &mut dyn FnMut() -> bool, ) -> Result<DefragmentationPass<'_, 'device>, AllocError>
Plan the next pass with a stop predicate borrowed only for this call.
True preserves already proposed moves for resolution; was_interrupted
distinguishes a stopped empty pass from completed scheduling. A later pass
can use a different predicate; this context retains policy and ignored state.
§Safety
Same source/alias/mapped-pointer and explicit resolution contract as begin_pass.
Sourcepub fn statistics(&self) -> DefragmentationStats
pub fn statistics(&self) -> DefragmentationStats
Totals from explicitly finished passes, never uncommitted proposals.
pub fn ignored_allocations(&self) -> usize
Sourcepub fn finish(&mut self) -> Result<DefragmentationStats, AllocError>
pub fn finish(&mut self) -> Result<DefragmentationStats, AllocError>
Complete the context after all passes are resolved and finished. Extensive explicitly releases held empty blocks above pool minimums here; freed native block/byte counts are included in the returned total statistics.