mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-18 20:16:42 +00:00
Optimize trim_mappings
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
cd9e5d11d2
commit
acb4833aae
@ -323,8 +323,8 @@ impl Vmar_ {
|
||||
.child_vmar_s
|
||||
.retain(|_, child_vmar_| !child_vmar_.is_destroyed());
|
||||
|
||||
let mut mappings_to_remove = BTreeSet::new();
|
||||
let mut mappings_to_append = BTreeMap::new();
|
||||
let mut mappings_to_remove = LinkedList::new();
|
||||
let mut mappings_to_append = LinkedList::new();
|
||||
|
||||
for vm_mapping in inner.vm_mappings.find(&range) {
|
||||
let vm_mapping_range = vm_mapping.range();
|
||||
@ -666,9 +666,9 @@ impl Vmar_ {
|
||||
|
||||
fn trim_existing_mappings(&self, trim_range: Range<usize>) -> Result<()> {
|
||||
let mut inner = self.inner.lock();
|
||||
let mut mappings_to_remove = BTreeSet::new();
|
||||
let mut mappings_to_append = BTreeMap::new();
|
||||
for vm_mapping in inner.vm_mappings.values() {
|
||||
let mut mappings_to_remove = LinkedList::new();
|
||||
let mut mappings_to_append = LinkedList::new();
|
||||
for vm_mapping in inner.vm_mappings.find(&trim_range) {
|
||||
vm_mapping.trim_mapping(
|
||||
&trim_range,
|
||||
&mut mappings_to_remove,
|
||||
|
@ -409,8 +409,8 @@ impl VmMapping {
|
||||
pub fn trim_mapping(
|
||||
self: &Arc<Self>,
|
||||
trim_range: &Range<usize>,
|
||||
mappings_to_remove: &mut BTreeSet<Vaddr>,
|
||||
mappings_to_append: &mut BTreeMap<Vaddr, Arc<VmMapping>>,
|
||||
mappings_to_remove: &mut LinkedList<Vaddr>,
|
||||
mappings_to_append: &mut LinkedList<(Vaddr, Arc<VmMapping>)>,
|
||||
) -> Result<()> {
|
||||
let map_to_addr = self.map_to_addr();
|
||||
let map_size = self.map_size();
|
||||
@ -421,15 +421,15 @@ impl VmMapping {
|
||||
if trim_range.start <= map_to_addr && trim_range.end >= map_to_addr + map_size {
|
||||
// Fast path: the whole mapping was trimed.
|
||||
self.unmap(trim_range, true)?;
|
||||
mappings_to_remove.insert(map_to_addr);
|
||||
mappings_to_remove.push_back(map_to_addr);
|
||||
return Ok(());
|
||||
}
|
||||
if trim_range.start <= range.start {
|
||||
mappings_to_remove.insert(map_to_addr);
|
||||
mappings_to_remove.push_back(map_to_addr);
|
||||
if trim_range.end <= range.end {
|
||||
// Overlap vm_mapping from left.
|
||||
let new_map_addr = self.trim_left(trim_range.end)?;
|
||||
mappings_to_append.insert(new_map_addr, self.clone());
|
||||
mappings_to_append.push_back((new_map_addr, self.clone()));
|
||||
} else {
|
||||
// The mapping was totally destroyed.
|
||||
}
|
||||
@ -438,7 +438,7 @@ impl VmMapping {
|
||||
// The trim range was totally inside the old mapping.
|
||||
let another_mapping = Arc::new(self.try_clone()?);
|
||||
let another_map_to_addr = another_mapping.trim_left(trim_range.end)?;
|
||||
mappings_to_append.insert(another_map_to_addr, another_mapping);
|
||||
mappings_to_append.push_back((another_map_to_addr, another_mapping));
|
||||
} else {
|
||||
// Overlap vm_mapping from right.
|
||||
}
|
||||
|
Reference in New Issue
Block a user