Skip to main content

PageAllocator

Struct PageAllocator 

Source
pub struct PageAllocator { /* private fields */ }
Expand description

Page allocator for dynamic page allocation

Manages free list and bitmap tracking for efficient page reuse.

Implementations§

Source§

impl PageAllocator

Source

pub fn new(header: &PersistentHeaderV3) -> Self

Create a new page allocator

§Arguments
  • header - V3 persistent header with free_page_list_head and total_pages
§Returns

Initialized PageAllocator with sparse bitmap for O(1) initialization

§Optimization

The bitmap is SPARSE: only pages 0 and 1 (reserved) are pre-initialized. Pages 2+ are “implicitly free” until actually allocated. This eliminates the O(N) bitmap initialization on open.

See get_page_state() for how pages beyond bitmap.len() are handled.

Source

pub fn allocate(&mut self) -> NativeResult<u64>

Allocate a new page

§Strategy
  1. Check free list for reusable page
  2. If none, append new page to file
  3. Mark page as allocated in bitmap
§Returns

Allocated page_id

Source

pub fn deallocate(&mut self, page_id: u64) -> NativeResult<()>

Deallocate a page (add to free list)

§Arguments
  • page_id - Page ID to free
§Errors

Returns error if:

  • Page is already free (double-free detection)
  • Page ID 0 (header page cannot be freed)
Source

pub fn get_page_state(&self, page_id: u64) -> NativeResult<PageState>

Get page state

§Arguments
  • page_id - Page ID to query
§Returns

PageState (Free, Allocated, or Pinned)

Source

pub fn pin_page(&mut self, page_id: u64) -> NativeResult<()>

Pin a page (prevent deallocation during WAL operations)

§Arguments
  • page_id - Page ID to pin
§Note

Full implementation would track pinned pages separately. For Phase 64, this is a stub that validates the page exists.

Source

pub fn unpin_page(&mut self, page_id: u64) -> NativeResult<()>

Unpin a page (allow deallocation)

§Arguments
  • page_id - Page ID to unpin
§Note

Full implementation would remove from pinned set. For Phase 64, this is a stub that validates the page exists.

Source

pub fn stats(&self) -> (u64, u64, u64)

Get current allocation statistics

§Returns

Tuple of (allocated_pages, free_pages, total_pages)

Source

pub fn free_list_head(&self) -> u64

Get free list head (for persistence)

§Returns

Top of the free list stack page ID (0 if empty)

Source

pub fn total_pages(&self) -> u64

Get total pages (for persistence)

§Returns

Total pages allocated

Source

pub fn page_offset(page_id: u64) -> NativeResult<u64>

Calculate page offset in file

§Arguments
  • page_id - Page ID
§Returns

Byte offset of page in file

§Formula

offset = V3_HEADER_SIZE + (page_id - 1) * PAGE_SIZE

Note: page_id 0 is the header (not a data page) Data pages start at page_id = 1

Source

pub fn validate_checksum( page_data: &[u8], stored_checksum: u64, ) -> NativeResult<()>

Validate page checksum

§Arguments
  • page_data - Raw page bytes
  • stored_checksum - Checksum from page header
§Returns

Ok(()) if checksum valid, Err otherwise

Trait Implementations§

Source§

impl Clone for PageAllocator

Source§

fn clone(&self) -> PageAllocator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V