Special treat VM Space clearing

This commit is contained in:
Zhang Junyang
2024-11-03 15:34:30 +08:00
committed by Tate, Hongliang Tian
parent fda05e9e23
commit c34706603a
4 changed files with 71 additions and 13 deletions

View File

@ -92,6 +92,26 @@ impl PageTable<UserMode> {
self.root.activate();
}
}
/// Clear the page table.
///
/// # Safety
///
/// The caller must ensure that:
/// 1. No other cursors are accessing the page table.
/// 2. No other CPUs activates the page table.
pub(in crate::mm) unsafe fn clear(&self) {
let mut root_node = self.root.clone_shallow().lock();
const NR_PTES_PER_NODE: usize = nr_subpage_per_huge::<PagingConsts>();
for i in 0..NR_PTES_PER_NODE / 2 {
let root_entry = root_node.entry(i);
if !root_entry.is_none() {
let old = root_entry.replace(Child::None);
// Since no others are accessing the old child, dropping it is fine.
drop(old);
}
}
}
}
impl PageTable<KernelMode> {