forked from arceos-org/arceos
-
Notifications
You must be signed in to change notification settings - Fork 17
feat: support COW #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4468909
Add basc COW
mingzi47 4df0a03
Squash merge cow-backend into cow
mingzi47 c5ea6ae
refactor: replace Arc-based frame tracking with frame info table
mingzi47 c479c34
refactor: simplify address space handling logic
mingzi47 2199488
refactor: improve memory management safety
mingzi47 5a06d2e
Merge branch 'oscomp:main' into cow
mingzi47 db0ab69
Merge branch 'oscomp:main' into cow-mem_map
mingzi47 92d0fce
Merge branch 'cow-mem_map' into cow
mingzi47 d497a21
chore: clean up
mingzi47 1262090
refactor: Rename `populate_area` to `ensure_region_mapped` with COW s…
mingzi47 44d596e
chore: Modify according to comment
mingzi47 41fba7a
Merge branch 'main' into cow
mingzi47 74519d3
refactor: replace PageIter4K with PageIterWrapper in AddrSpace
mingzi47 05a17be
refactor: simplify frame reference counting
mingzi47 172657f
refactor: (populate_area) use a iterator to walk through the area cov…
mingzi47 e9a3c03
feat: add COW feature for memory management
mingzi47 a4a4658
refactor: simplify COW handling and frame table initialization
mingzi47 459349f
refactor: reorganize memory management modules
mingzi47 639278d
doc: fix doc link
mingzi47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//! FrameInfo | ||
//! | ||
//! A simple physical FrameInfo manager is provided to track and manage | ||
//! the reference count for every 4KB memory page frame in the system. | ||
//! | ||
//! There is a [' FrameInfo '] struct for each physical page frame | ||
Azure-stars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
//! that keeps track of its reference count. | ||
//! NOTE: If the page is huge page, its [`FrameInfo`] is placed at the | ||
//! starting physical address. | ||
use core::{ | ||
array, | ||
sync::atomic::{AtomicUsize, Ordering}, | ||
}; | ||
|
||
use alloc::boxed::Box; | ||
use lazy_static::lazy_static; | ||
use memory_addr::PhysAddr; | ||
// 4 kb page | ||
const FRAME_SHIFT: usize = 12; | ||
|
||
pub const MAX_FRAME_NUM: usize = axconfig::plat::PHYS_MEMORY_SIZE >> FRAME_SHIFT; | ||
|
||
lazy_static! { | ||
static ref FRAME_INFO_TABLE: FrameRefTable = FrameRefTable::default(); | ||
} | ||
|
||
pub(crate) fn frame_table() -> &'static FrameRefTable { | ||
&FRAME_INFO_TABLE | ||
} | ||
|
||
pub(crate) struct FrameRefTable { | ||
data: Box<[FrameInfo; MAX_FRAME_NUM]>, | ||
} | ||
mingzi47 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl Default for FrameRefTable { | ||
fn default() -> Self { | ||
FrameRefTable { | ||
data: Box::new(array::from_fn(|_| FrameInfo::default())), | ||
} | ||
} | ||
} | ||
|
||
impl FrameRefTable { | ||
fn info(&self, paddr: PhysAddr) -> &FrameInfo { | ||
let index = (paddr.as_usize() - axconfig::plat::PHYS_MEMORY_BASE) >> FRAME_SHIFT; | ||
&self.data[index] | ||
} | ||
|
||
/// Increases the reference count of the frame associated with a physical address. | ||
/// | ||
/// # Parameters | ||
/// - `paddr`: It must be an aligned physical address; if it's a huge page, | ||
/// it must be the starting physical address. | ||
pub fn inc_ref(&self, paddr: PhysAddr) { | ||
self.info(paddr).ref_count.fetch_add(1, Ordering::SeqCst); | ||
} | ||
|
||
/// Decreases the reference count of the frame associated with a physical address. | ||
/// | ||
/// - `paddr`: It must be an aligned physical address; if it's a huge page, | ||
/// it must be the starting physical address. | ||
/// | ||
/// # Returns | ||
/// The updated reference count after decrementing. | ||
pub fn dec_ref(&self, paddr: PhysAddr) -> usize { | ||
self.info(paddr).ref_count.fetch_sub(1, Ordering::SeqCst) | ||
} | ||
|
||
/// Returns the `FrameInfo` structure associated with a given physical address. | ||
/// | ||
/// # Parameters | ||
/// - `paddr`: It must be an aligned physical address; if it's a huge page, | ||
/// it must be the starting physical address. | ||
/// | ||
/// # Returns | ||
/// A reference to the `FrameInfo` associated with the given physical address. | ||
pub fn ref_count(&self, paddr: PhysAddr) -> usize { | ||
self.info(paddr).ref_count.load(Ordering::SeqCst) | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub(crate) struct FrameInfo { | ||
ref_count: AtomicUsize, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mingzi47 Sorry to bother you, I was wondering if this change is necessary? Because I'm porting these to
axcpu
.