pub struct BlockAllocator { /* private fields */ }Expand description
Block allocator with extent-based free-list tracking.
Manages space within a .luci file as fixed 256 KB blocks. The header
occupies the first 4 KB of the file; blocks start immediately after.
Allocation searches the free list first (first-fit), then extends the file
if no suitable free extent exists. Deallocation returns extents to the free
list and coalesces adjacent entries.
See [[architecture-storage-format#Block Allocator]].
Implementations§
Source§impl BlockAllocator
impl BlockAllocator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an allocator for a new, empty file.
A fresh file has only the 4 KB header — no data blocks yet. All allocations extend the file.
Sourcepub fn from_state(total_blocks: u64, free_list: Vec<Extent>) -> Self
pub fn from_state(total_blocks: u64, free_list: Vec<Extent>) -> Self
Reconstruct an allocator from persisted state.
Called during recovery: the metadata root block stores total_blocks
and the serialized free list.
Sourcepub fn allocate(&mut self, count: u32) -> Result<Extent>
pub fn allocate(&mut self, count: u32) -> Result<Extent>
Allocate count contiguous blocks.
Strategy: first-fit scan of the free list. If no free extent is large enough, extends the file by appending blocks at the end.
§Errors
Returns LuciError::InvalidQuery if count is zero.
Sourcepub fn free(&mut self, extent: Extent)
pub fn free(&mut self, extent: Extent)
Return an extent to the free list.
The freed blocks become available for future allocations. Adjacent free extents are coalesced to reduce fragmentation.
§Panics
Debug-asserts that the extent falls within [0, total_blocks) and
does not overlap any existing free extent.
Sourcepub fn total_blocks(&self) -> u64
pub fn total_blocks(&self) -> u64
Total number of data blocks the file spans (excludes the header).
Sourcepub fn free_block_count(&self) -> u64
pub fn free_block_count(&self) -> u64
Total number of free (reusable) blocks.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockAllocator
impl RefUnwindSafe for BlockAllocator
impl Send for BlockAllocator
impl Sync for BlockAllocator
impl Unpin for BlockAllocator
impl UnsafeUnpin for BlockAllocator
impl UnwindSafe for BlockAllocator
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