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
impl PageCacheManager
Sourcepub fn global() -> &'static PageCacheManager
pub fn global() -> &'static PageCacheManager
Global singleton accessor
Sourcepub fn get_or_create_pinned<F>(
&self,
id: CacheId,
index: PageIndex,
loader: F,
) -> Result<PhysicalAddress, &'static str>where
F: FnOnce(PhysicalAddress) -> Result<(), &'static str>,
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 fileloader- 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
Sourcepub fn try_get_pinned(
&self,
id: CacheId,
index: PageIndex,
) -> Option<PhysicalAddress>
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.
Sourcepub fn unpin(&self, id: CacheId, index: PageIndex)
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).
Sourcepub fn mark_dirty(&self, id: CacheId, index: PageIndex)
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.
Sourcepub fn set_object_locked(&self, id: CacheId, locked: bool)
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.
Sourcefn is_object_locked(&self, id: CacheId) -> bool
fn is_object_locked(&self, id: CacheId) -> bool
Check if an object is locked (unevictable)
Sourcepub fn flush<F>(&self, id: CacheId, writer: F) -> Result<(), &'static str>where
F: FnMut(PageIndex, PhysicalAddress) -> Result<(), &'static str>,
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 identifierwriter- Callback to write a page. Receives (page_index, paddr)
Sourcepub fn pin_or_load<F>(
&self,
id: CacheId,
index: PageIndex,
loader: F,
) -> Result<PinnedPage, &'static str>where
F: FnOnce(PhysicalAddress) -> Result<(), &'static str>,
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.
Sourcepub fn try_pin(&self, id: CacheId, index: PageIndex) -> Option<PinnedPage>
pub fn try_pin(&self, id: CacheId, index: PageIndex) -> Option<PinnedPage>
Try to pin an already cached page and return an RAII guard.
Sourcepub fn invalidate(&self, id: CacheId)
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.