mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
Fix the concurrency bug when multiple threads committing the same page
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
840729d960
commit
cea4fd7777
@ -156,7 +156,7 @@ impl Pager for PageCacheManager {
|
||||
return Ok(page.frame.clone());
|
||||
}
|
||||
|
||||
//Multiple threads may commit the same page, but the result is ok.
|
||||
// Multiple threads may commit the same page, but the result is ok.
|
||||
let backend = self.backend();
|
||||
let page = if idx < backend.npages() {
|
||||
let mut page = Page::alloc()?;
|
||||
@ -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<()> {
|
||||
|
Reference in New Issue
Block a user