pub struct PagePool<const SLOTS: usize> { /* private fields */ }Expand description
Allocation map of capacity_pages pages shared by up to SLOTS runs.
Pure bookkeeping: the pool never touches page contents. All state is plain
integers, so a static pool can live in .bss.
Implementations§
Source§impl<const SLOTS: usize> PagePool<SLOTS>
impl<const SLOTS: usize> PagePool<SLOTS>
Sourcepub const fn new(pool: u8, capacity_pages: u32, placement: Placement) -> Self
pub const fn new(pool: u8, capacity_pages: u32, placement: Placement) -> Self
An empty pool numbered pool (stamped into its handles) of
capacity_pages pages.
Sourcepub const fn capacity_pages(&self) -> u32
pub const fn capacity_pages(&self) -> u32
Total pages in the pool.
Sourcepub const fn used_pages(&self) -> u32
pub const fn used_pages(&self) -> u32
Pages held by live allocations.
Sourcepub const fn free_pages(&self) -> u32
pub const fn free_pages(&self) -> u32
Pages not held by any allocation (possibly scattered).
Sourcepub const fn live_count(&self) -> usize
pub const fn live_count(&self) -> usize
Number of live allocations.
Sourcepub fn set_placement(&mut self, placement: Placement)
pub fn set_placement(&mut self, placement: Placement)
Change the placement policy; existing runs stay where they are.
Sourcepub const fn layout_generation(&self) -> u32
pub const fn layout_generation(&self) -> u32
Bumped every time compaction moves a run. A byte view taken before a bump may point at the wrong pages: re-resolve it.
Sourcepub fn allocate(&mut self, page_count: u32) -> Option<(Handle, PageRun)>
pub fn allocate(&mut self, page_count: u32) -> Option<(Handle, PageRun)>
Allocate a contiguous run of page_count pages, or None when no gap
is large enough or every slot is taken. Never moves another run.
Sourcepub fn find_fit(&self, page_count: u32) -> Option<u32>
pub fn find_fit(&self, page_count: u32) -> Option<u32>
First page of the gap a run of page_count pages would get.
Sourcepub fn free(&mut self, handle: Handle) -> bool
pub fn free(&mut self, handle: Handle) -> bool
Free handle. false (and no change) when the handle is stale.
Sourcepub fn is_current(&self, handle: Handle) -> bool
pub fn is_current(&self, handle: Handle) -> bool
Whether handle still names the allocation it was issued for.
Sourcepub fn try_run(&self, handle: Handle) -> Option<PageRun>
pub fn try_run(&self, handle: Handle) -> Option<PageRun>
The pages handle names, or None when it is stale.
Sourcepub fn set_locked(&mut self, handle: Handle, locked: bool) -> bool
pub fn set_locked(&mut self, handle: Handle, locked: bool) -> bool
Lock or unlock the run. A locked run is never moved by
PagePool::compact_step (a transfer is landing in it, or a consumer
holds a raw view of it). false when the handle is stale.
Sourcepub fn is_locked(&self, handle: Handle) -> bool
pub fn is_locked(&self, handle: Handle) -> bool
Whether the run is locked (false for a stale handle).
Sourcepub fn iter_runs(&self) -> impl Iterator<Item = (u16, PageRun, bool)> + '_
pub fn iter_runs(&self) -> impl Iterator<Item = (u16, PageRun, bool)> + '_
Live allocations in address order as (slot, run, locked).
Sourcepub fn handle_of_slot(&self, slot: u16) -> Option<Handle>
pub fn handle_of_slot(&self, slot: u16) -> Option<Handle>
Handle of the live allocation in slot.
Sourcepub fn gaps(&self) -> impl Iterator<Item = (u32, u32)> + '_
pub fn gaps(&self) -> impl Iterator<Item = (u32, u32)> + '_
Free gaps in address order as (first_page, page_count).
Sourcepub fn fragmentation(&self) -> Fragmentation
pub fn fragmentation(&self) -> Fragmentation
Shape of the free space.
Sourcepub fn compact_step(&mut self, copy: impl FnMut(PageRun, u32)) -> Option<Moved>
pub fn compact_step(&mut self, copy: impl FnMut(PageRun, u32)) -> Option<Moved>
Slide the lowest unlocked run that has free space below it down to the
lowest page it can reach, calling copy(from, to_page) so the owner of
the bytes moves them (the destination may overlap the source; copy as
memmove). Locked runs stay put and act as barriers. One run per call,
so a caller can spend a CPU budget on it. None when nothing can move.
Sourcepub fn check_invariants(&self)
pub fn check_invariants(&self)
Check the structural invariants (host tests and debug assertions).