PageCacheManager

Struct PageCacheManager 

Source
pub struct PageCacheManager {
    entries: RwLock<BTreeMap<(CacheId, PageIndex), PageCacheEntry>>,
    object_locks: RwLock<BTreeMap<CacheId, usize>>,
}
Expand description

Global page cache manager

Manages all cached pages for filesystem operations. Uses (CacheId, PageIndex) as the key to uniquely identify pages across the entire system.

Fields§

§entries: RwLock<BTreeMap<(CacheId, PageIndex), PageCacheEntry>>

Map from (CacheId, PageIndex) to cached page entry

§object_locks: RwLock<BTreeMap<CacheId, usize>>

Object-level lock counts for eviction prevention Maps CacheId to lock count (>0 means object is unevictable)

Implementations§

Source§

impl PageCacheManager

Source

pub const fn new() -> Self

Create a new empty page cache manager

Source

pub fn global() -> &'static PageCacheManager

Global singleton accessor

Source

pub fn get_or_create_pinned<F>( &self, id: CacheId, index: PageIndex, loader: F, ) -> Result<PhysicalAddress, &'static str>
where F: FnOnce(PhysicalAddress) -> Result<(), &'static str>,

Get a page, pinning it to prevent eviction during access

If the page is not in cache, calls the loader callback to load it. Returns the physical address of the page with pin_count incremented.

§Arguments
  • id - Cache identifier (filesystem + file)
  • index - Page index within the file
  • loader - Callback to load the page if not cached. Receives the allocated physical address and should fill it with page content.
§Returns

Physical address of the pinned page

Source

pub fn try_get_pinned( &self, id: CacheId, index: PageIndex, ) -> Option<PhysicalAddress>

Try to get a pinned page without triggering I/O

Returns Some(paddr) if the page is already cached, None otherwise. If successful, increments pin_count.

Source

pub fn unpin(&self, id: CacheId, index: PageIndex)

Unpin a page, allowing it to be evicted

Decrements the pin count. When pin_count reaches 0, the page becomes eligible for eviction (if not locked).

Source

pub fn mark_dirty(&self, id: CacheId, index: PageIndex)

Mark a page as dirty (modified)

Dirty pages will be written back to storage during flush or eviction.

Source

pub fn set_object_locked(&self, id: CacheId, locked: bool)

Set object-level lock (prevents eviction of all pages for this object)

Used during mmap to keep all mapped pages resident. Phase 0: Simple implementation - lock entire object during mmap.

Source

fn is_object_locked(&self, id: CacheId) -> bool

Check if an object is locked (unevictable)

Source

pub fn flush<F>(&self, id: CacheId, writer: F) -> Result<(), &'static str>
where F: FnMut(PageIndex, PhysicalAddress) -> Result<(), &'static str>,

Flush dirty pages for a specific cache object

Writes all dirty pages back to storage using the provided writer callback. Only flushes pages with pin_count == 0 to avoid writing pages being modified.

§Arguments
  • id - Cache identifier
  • writer - Callback to write a page. Receives (page_index, paddr)
Source

pub fn pin_or_load<F>( &self, id: CacheId, index: PageIndex, loader: F, ) -> Result<PinnedPage, &'static str>
where F: FnOnce(PhysicalAddress) -> Result<(), &'static str>,

Get or load a page and return an RAII guard that unpins on drop.

Source

pub fn try_pin(&self, id: CacheId, index: PageIndex) -> Option<PinnedPage>

Try to pin an already cached page and return an RAII guard.

Source

pub fn invalidate(&self, id: CacheId)

Invalidate (drop) all cached pages belonging to the given CacheId.

This is used when a file is removed (unlink) so that subsequent lookups / recreations do not observe stale cached content that belonged to the old incarnation of the file.

Auto Trait Implementations§

§

impl !Freeze for PageCacheManager

§

impl !RefUnwindSafe for PageCacheManager

§

impl Send for PageCacheManager

§

impl Sync for PageCacheManager

§

impl Unpin for PageCacheManager

§

impl UnwindSafe for PageCacheManager

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.