Optimize the performance of page table un-mapping

This commit is contained in:
Zhang Junyang
2024-07-23 03:26:43 +00:00
committed by Tate, Hongliang Tian
parent 862b64b786
commit 42aac5ce8b
2 changed files with 20 additions and 1 deletions

View File

@ -528,6 +528,9 @@ where
/// Unmaps the range starting from the current address with the given length of virtual address. /// Unmaps the range starting from the current address with the given length of virtual address.
/// ///
/// Already-absent mappings encountered by the cursor will be skipped. It is valid to unmap a
/// range that is not mapped.
///
/// # Safety /// # Safety
/// ///
/// The caller should ensure that the range being unmapped does not affect kernel's memory safety. /// The caller should ensure that the range being unmapped does not affect kernel's memory safety.
@ -546,7 +549,7 @@ where
let cur_pte = self.0.read_cur_pte(); let cur_pte = self.0.read_cur_pte();
let is_tracked = self.0.in_tracked_range(); let is_tracked = self.0.in_tracked_range();
// Skip if it is already invalid. // Skip if it is already absent.
if !cur_pte.is_present() { if !cur_pte.is_present() {
if self.0.va + page_size::<C>(self.0.level) > end { if self.0.va + page_size::<C>(self.0.level) > end {
break; break;
@ -565,6 +568,19 @@ where
{ {
if cur_pte.is_present() && !cur_pte.is_last(self.0.level) { if cur_pte.is_present() && !cur_pte.is_last(self.0.level) {
self.0.level_down(); self.0.level_down();
// We have got down a level. If there's no mapped PTEs in
// the current node, we can go back and skip to save time.
if self.0.guards[(self.0.level - 1) as usize]
.as_ref()
.unwrap()
.nr_children()
== 0
{
self.0.level_up();
self.0.move_forward();
continue;
}
} else if !is_tracked { } else if !is_tracked {
self.level_down_split(); self.level_down_split();
} else { } else {

View File

@ -288,6 +288,9 @@ impl CursorMut<'_> {
/// This method will bring the cursor forward by `len` bytes in the virtual /// This method will bring the cursor forward by `len` bytes in the virtual
/// address space after the modification. /// address space after the modification.
/// ///
/// Already-absent mappings encountered by the cursor will be skipped. It
/// is valid to unmap a range that is not mapped.
///
/// # Panics /// # Panics
/// ///
/// This method will panic if `len` is not page-aligned. /// This method will panic if `len` is not page-aligned.