#[repr(transparent)]pub struct PageCacheState(LRUCache<(InodeNumber, FileBlockNumber), Slot, 512>);Expand description
The global page cache state.
PageCacheState wraps an LRUCache mapping (InodeNumber, FileBlockNumber) to Slot entries. It enforces a bounded capacity of 512
slots, corresponding to 2 MiB of cached file data.
This state is protected by a Mutex inside PageCacheInner, allowing
concurrent access from multiple threads with safe eviction.
Tuple Fields§
§0: LRUCache<(InodeNumber, FileBlockNumber), Slot, 512>Implementations§
Source§impl PageCacheState
impl PageCacheState
Sourcepub fn readahead(&mut self, file: RegularFile, fba: FileBlockNumber)
pub fn readahead(&mut self, file: RegularFile, fba: FileBlockNumber)
Perform readahead on sequential file blocks.
Reads up to 16 consecutive blocks after the given fba
(file block address) into the cache.
Existing cached slots are not overwritten.
Sourcepub fn insert(&mut self, id: (InodeNumber, FileBlockNumber), slot: Slot)
pub fn insert(&mut self, id: (InodeNumber, FileBlockNumber), slot: Slot)
Insert a new Slot into the page cache.
Associates the given (inode, fba) pair with the slot.
If the cache is at capacity, the least-recently-used slot
will be automatically evicted (writing back its contents if dirty).
Sourcepub fn do_read(
&mut self,
file: RegularFile,
fba: FileBlockNumber,
buf: &mut [u8; 4096],
) -> Result<bool, KernelError>
pub fn do_read( &mut self, file: RegularFile, fba: FileBlockNumber, buf: &mut [u8; 4096], ) -> Result<bool, KernelError>
Read a file block into the provided buffer.
- If the block is cached, copies directly from the page cache.
- If the block is not cached, loads it synchronously from the file system, inserts it into the cache, and copies it into the buffer.
This method does not triggers the read-ahead requests.
Returns Ok(true) if there exists any byte read.
Sourcepub fn do_write(
&mut self,
file: RegularFile,
fba: FileBlockNumber,
buf: &[u8; 4096],
min_size: usize,
) -> Result<(), KernelError>
pub fn do_write( &mut self, file: RegularFile, fba: FileBlockNumber, buf: &[u8; 4096], min_size: usize, ) -> Result<(), KernelError>
Write a file block through the page cache.
Updates (or inserts) the slot corresponding to the (file, fba)
pair with the provided buffer. The slot is marked dirty, and at least
min_size bytes are scheduled for write-back.
This method does not immediately flush to disk; explicit
PageCacheState::do_writeback or eviction is required for
persistence.
Sourcepub fn do_mmap(
&mut self,
file: RegularFile,
fba: FileBlockNumber,
) -> Result<Page, KernelError>
pub fn do_mmap( &mut self, file: RegularFile, fba: FileBlockNumber, ) -> Result<Page, KernelError>
Sourcepub fn do_unlink(&mut self, file: RegularFile)
pub fn do_unlink(&mut self, file: RegularFile)
Remove all slots associated with a given file.
Slots are dropped without flushing dirty data back to the file system. This is typically used during file unlink (deletion), where data persistence is no longer required.
Sourcepub fn do_writeback(&mut self, file: RegularFile) -> Result<(), KernelError>
pub fn do_writeback(&mut self, file: RegularFile) -> Result<(), KernelError>
Write back all dirty slots belonging to the given file.
Ensures that all cached modifications to the file are persisted to the underlying file system.
Methods from Deref<Target = LRUCache<(InodeNumber, FileBlockNumber), Slot, 512>>§
fn attach(&mut self, k: K) -> &mut Node<K, V>
fn detach(&mut self, prev: Option<K>, next: Option<K>)
Sourcepub fn get(&mut self, k: K) -> Option<&mut V>
pub fn get(&mut self, k: K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key and update the last access time.
Sourcepub fn get_or_insert_with<E>(
&mut self,
k: K,
f: impl FnOnce() -> Result<V, E>,
) -> Result<&mut V, E>
pub fn get_or_insert_with<E>( &mut self, k: K, f: impl FnOnce() -> Result<V, E>, ) -> Result<&mut V, E>
Inserts the value computed with f into the LRUCache if it is not
present, then returns a reference to the value in the LRUCache.
fn __put(&mut self, k: K, v: V) -> &mut Node<K, V>
Sourcepub fn put(&mut self, k: K, v: V)
pub fn put(&mut self, k: K, v: V)
Inserts a key-value pair into the LRUCache.
If the map did have this key present, the value is updated. The key is not updated, though; this matters for types that can be == without being identical.
If the cache size is overflowed after insertion, evict the oldest accessed entry.
Sourcepub fn remove(&mut self, k: &K) -> Option<V>
pub fn remove(&mut self, k: &K) -> Option<V>
Removes a key from the LRUCache, returning the stored value if the key was previously in the LRUCache.
The key may be any borrowed form of the LRUCache’s key type, but the ordering on the borrowed form must match the ordering on the key type.