Fix the concurrency bug when multiple threads committing the same page

This commit is contained in:
Yingdi Shan
2024-06-07 13:55:18 +08:00
committed by Tate, Hongliang Tian
parent 840729d960
commit cea4fd7777

View File

@ -167,9 +167,9 @@ impl Pager for PageCacheManager {
} else {
Page::alloc_zero()?
};
let frame = page.frame().clone();
self.pages.lock().put(idx, page);
Ok(frame)
// If multiple threads commit the same page, only the first allocated page will be perserved.
Ok(self.pages.lock().get_or_insert(idx, || page).frame.clone())
}
fn update_page(&self, idx: usize) -> Result<()> {