page_cache: split unlink() out of detach()

The unlink function removes an entry from the LRU.

The detach function removes an entry in the cache and clears page
contents.
This commit is contained in:
Alecco 2025-04-15 12:44:34 +02:00 committed by Pere Diaz Bou
parent 6763aa0cd5
commit c8beddab09

View file

@ -109,7 +109,7 @@ impl DumbLruPageCache {
let mut ptr = self.get_ptr(key)?;
let page = unsafe { ptr.as_mut().page.clone() };
if touch {
self.detach(ptr, false);
self.unlink(ptr);
self.touch(ptr);
}
Some(page)
@ -128,7 +128,10 @@ impl DumbLruPageCache {
debug!("cleaning up page {}", page.get().id);
let _ = page.get().contents.take();
}
self.unlink(entry);
}
fn unlink(&mut self, mut entry: NonNull<PageCacheEntry>) {
let (next, prev) = unsafe {
let c = entry.as_mut();
let next = c.next;
@ -138,7 +141,6 @@ impl DumbLruPageCache {
(next, prev)
};
// detach
match (prev, next) {
(None, None) => {
self.head.replace(None);