pub struct UsmSuballocator { /* private fields */ }Expand description
First-fit free-list sub-allocator over a single USM block.
Mirrors the device-memory-allocator pattern: tracks free spans, splits on allocation, coalesces adjacent spans on free, and honours arbitrary power-of-two alignment (accounting for the introduced leading padding).
The UsmKind is carried so a backend can keep separate suballocators per
memory flavour and never mix host and device offsets.
Implementations§
Source§impl UsmSuballocator
impl UsmSuballocator
Sourcepub fn new(kind: UsmKind, block_size: u64) -> LevelZeroResult<Self>
pub fn new(kind: UsmKind, block_size: u64) -> LevelZeroResult<Self>
Create a suballocator managing block_size bytes of kind memory.
Sourcepub fn block_size(&self) -> u64
pub fn block_size(&self) -> u64
Total managed size in bytes.
Sourcepub fn free_bytes(&self) -> u64
pub fn free_bytes(&self) -> u64
Sum of all currently-free bytes (possibly fragmented).
Sourcepub fn largest_free_span(&self) -> u64
pub fn largest_free_span(&self) -> u64
The largest single contiguous free span.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of live allocations.
Sourcepub fn alloc(
&mut self,
size: u64,
alignment: u64,
) -> LevelZeroResult<UsmSubAllocation>
pub fn alloc( &mut self, size: u64, alignment: u64, ) -> LevelZeroResult<UsmSubAllocation>
Allocate size bytes aligned to alignment (a power of two).
Sourcepub fn alloc_default(&mut self, size: u64) -> LevelZeroResult<UsmSubAllocation>
pub fn alloc_default(&mut self, size: u64) -> LevelZeroResult<UsmSubAllocation>
Allocate size bytes using the default USM alignment.
Sourcepub fn free(&mut self, offset: u64) -> LevelZeroResult<()>
pub fn free(&mut self, offset: u64) -> LevelZeroResult<()>
Free a previously-returned allocation by its offset.