mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 01:43:22 +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());
|
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 backend = self.backend();
|
||||||
let page = if idx < backend.npages() {
|
let page = if idx < backend.npages() {
|
||||||
let mut page = Page::alloc()?;
|
let mut page = Page::alloc()?;
|
||||||
@ -167,9 +167,9 @@ impl Pager for PageCacheManager {
|
|||||||
} else {
|
} else {
|
||||||
Page::alloc_zero()?
|
Page::alloc_zero()?
|
||||||
};
|
};
|
||||||
let frame = page.frame().clone();
|
|
||||||
self.pages.lock().put(idx, page);
|
// If multiple threads commit the same page, only the first allocated page will be perserved.
|
||||||
Ok(frame)
|
Ok(self.pages.lock().get_or_insert(idx, || page).frame.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_page(&self, idx: usize) -> Result<()> {
|
fn update_page(&self, idx: usize) -> Result<()> {
|
||||||
|
Reference in New Issue
Block a user