⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

PerCpuPageCache

Struct PerCpuPageCache 

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

Per-CPU page frame cache to reduce global FRAME_ALLOCATOR contention.

Single-frame allocations (page faults, mmap, fork) dominate. By caching frames per-CPU, we avoid acquiring the global lock on every allocation.

When the cache is empty, it batch-refills from the global allocator. When full, it batch-drains back to the global allocator. Cache-line aligned to prevent false sharing when per-CPU caches are stored in adjacent array slots accessed by different cores.

Implementations§

Source§

impl PerCpuPageCache

Source

pub const fn new() -> Self

Source

pub fn alloc_one(&mut self) -> Option<FrameNumber>

Try to allocate a single frame from the per-CPU cache. Returns None if cache is empty (caller should refill from global).

Source

pub fn free_one(&mut self, frame: FrameNumber) -> bool

Return a single frame to the per-CPU cache. Returns false if cache is full (caller should drain to global).

Source

pub fn needs_refill(&self) -> bool

Is the cache below the low watermark?

Source

pub fn needs_drain(&self) -> bool

Is the cache above the high watermark?

Source

pub fn batch_refill(&mut self)

Batch-refill from the global frame allocator. Acquires the global lock once, filling up to BATCH_SIZE frames.

Source

pub fn batch_drain(&mut self)

Batch-drain excess frames back to the global allocator. Acquires the global lock once, returning BATCH_SIZE frames.

Source

pub fn cached_count(&self) -> usize

Number of cached frames

Trait Implementations§

Source§

impl Default for PerCpuPageCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for PerCpuPageCache

§

impl RefUnwindSafe for PerCpuPageCache

§

impl Send for PerCpuPageCache

§

impl Sync for PerCpuPageCache

§

impl Unpin for PerCpuPageCache

§

impl UnwindSafe for PerCpuPageCache

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.