From 082d65446f0db10cef72f84e22a63df09f6c6f31 Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Thu, 8 Jun 2023 15:45:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0remove=5Farea=5Fwith=5Fstart?= =?UTF-8?q?=5Fvpn=20=E5=92=8C=20recycle=5Fdata=5Fpages=20=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E9=87=8A=E6=94=BE=E5=9C=B0=E5=9D=80=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch5/os/src/mm/memory_set.rs | 16 ++++++++++++++++ ch5/os/src/mm/page_table.rs | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ch5/os/src/mm/memory_set.rs b/ch5/os/src/mm/memory_set.rs index 87b9cc1..bee9770 100644 --- a/ch5/os/src/mm/memory_set.rs +++ b/ch5/os/src/mm/memory_set.rs @@ -309,6 +309,22 @@ impl MemorySet { self.page_table.token() } + // 从当前地址空间中,根据start 虚拟页 找到逻辑段, 取消映射 一个逻辑段, 并把这个逻辑段 从 areas中删除 + pub fn remove_area_with_start_vpn(&mut self, start_vpn: VirtPageNum) { + if let Some((idx, area)) = self.areas.iter_mut().enumerate().find(|(_, area)| { + area.vpn_range.l == start_vpn + }) { + area.unmap(&mut self.page_table); + self.areas.remove(idx); + } + } + + // 释放当前地址空间的 逻辑页帧areas, 把对应的物理页帧通过RAII 归还给全局物理页帧管理器 + pub fn recycle_data_pages(&mut self) { + //*self = Self::new_bare(); + self.areas.clear(); + } + // 激活当前地址空间 pub fn activate(&self) { // let satp = self.page_table.token(); diff --git a/ch5/os/src/mm/page_table.rs b/ch5/os/src/mm/page_table.rs index fce9cf9..c2aa4e3 100644 --- a/ch5/os/src/mm/page_table.rs +++ b/ch5/os/src/mm/page_table.rs @@ -5,7 +5,6 @@ use crate::config::TRAMPOLINE; use crate::mm::address::{PhysPageNum, VirtAddr, VirtPageNum}; use crate::mm::frame_allocator::{frame_alloc, FrameTracker}; use crate::println; -use crate::task::TASK_MANAGER; bitflags! {