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
impl PerCpuPageCache
pub const fn new() -> Self
Sourcepub fn alloc_one(&mut self) -> Option<FrameNumber>
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).
Sourcepub fn free_one(&mut self, frame: FrameNumber) -> bool
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).
Sourcepub fn needs_refill(&self) -> bool
pub fn needs_refill(&self) -> bool
Is the cache below the low watermark?
Sourcepub fn needs_drain(&self) -> bool
pub fn needs_drain(&self) -> bool
Is the cache above the high watermark?
Sourcepub fn batch_refill(&mut self)
pub fn batch_refill(&mut self)
Batch-refill from the global frame allocator. Acquires the global lock once, filling up to BATCH_SIZE frames.
Sourcepub fn batch_drain(&mut self)
pub fn batch_drain(&mut self)
Batch-drain excess frames back to the global allocator. Acquires the global lock once, returning BATCH_SIZE frames.
Sourcepub fn cached_count(&self) -> usize
pub fn cached_count(&self) -> usize
Number of cached frames