Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

PagePool

Struct PagePool 

Source
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>

Source

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.

Source

pub const fn capacity_pages(&self) -> u32

Total pages in the pool.

Source

pub const fn used_pages(&self) -> u32

Pages held by live allocations.

Source

pub const fn free_pages(&self) -> u32

Pages not held by any allocation (possibly scattered).

Source

pub const fn live_count(&self) -> usize

Number of live allocations.

Source

pub const fn placement(&self) -> Placement

Placement policy for new runs.

Source

pub fn set_placement(&mut self, placement: Placement)

Change the placement policy; existing runs stay where they are.

Source

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.

Source

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.

Source

pub fn find_fit(&self, page_count: u32) -> Option<u32>

First page of the gap a run of page_count pages would get.

Source

pub fn free(&mut self, handle: Handle) -> bool

Free handle. false (and no change) when the handle is stale.

Source

pub fn is_current(&self, handle: Handle) -> bool

Whether handle still names the allocation it was issued for.

Source

pub fn try_run(&self, handle: Handle) -> Option<PageRun>

The pages handle names, or None when it is stale.

Source

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.

Source

pub fn is_locked(&self, handle: Handle) -> bool

Whether the run is locked (false for a stale handle).

Source

pub fn iter_runs(&self) -> impl Iterator<Item = (u16, PageRun, bool)> + '_

Live allocations in address order as (slot, run, locked).

Source

pub fn handle_of_slot(&self, slot: u16) -> Option<Handle>

Handle of the live allocation in slot.

Source

pub fn gaps(&self) -> impl Iterator<Item = (u32, u32)> + '_

Free gaps in address order as (first_page, page_count).

Source

pub fn fragmentation(&self) -> Fragmentation

Shape of the free space.

Source

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.

Source

pub fn check_invariants(&self)

Check the structural invariants (host tests and debug assertions).

Auto Trait Implementations§

§

impl<const SLOTS: usize> Freeze for PagePool<SLOTS>

§

impl<const SLOTS: usize> RefUnwindSafe for PagePool<SLOTS>

§

impl<const SLOTS: usize> Send for PagePool<SLOTS>

§

impl<const SLOTS: usize> Sync for PagePool<SLOTS>

§

impl<const SLOTS: usize> Unpin for PagePool<SLOTS>

§

impl<const SLOTS: usize> UnsafeUnpin for PagePool<SLOTS>

§

impl<const SLOTS: usize> UnwindSafe for PagePool<SLOTS>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.