瀏覽代碼

refactor(mm): remove anonymous flag

Heinz 8 月之前
父節點
當前提交
799e7cbf38
共有 5 個文件被更改,包括 10 次插入27 次删除
  1. 0 8
      arch/src/riscv64/mm.rs
  2. 0 12
      arch/src/x86_64/mm.rs
  3. 0 2
      crates/eonix_mm/src/page_table/pte.rs
  4. 9 2
      src/kernel/mem/mm_area.rs
  5. 1 3
      src/kernel/mem/mm_list.rs

+ 0 - 8
arch/src/riscv64/mm.rs

@@ -163,10 +163,6 @@ impl PageAttribute for PageAttribute64 {
         }
     }
 
-    fn anonymous(self, anon: bool) -> Self {
-        todo!()
-    }
-
     fn is_present(&self) -> bool {
         self.0 & PA_V != 0
     }
@@ -202,10 +198,6 @@ impl PageAttribute for PageAttribute64 {
     fn is_mapped(&self) -> bool {
         self.0 & PA_MMAP != 0
     }
-
-    fn is_anonymous(&self) -> bool {
-        todo!()
-    }
 }
 
 pub type DefaultPagingMode = PagingModeSv39;

+ 0 - 12
arch/src/x86_64/mm.rs

@@ -167,14 +167,6 @@ impl PageAttribute for PageAttribute64 {
         }
     }
 
-    fn anonymous(self, anon: bool) -> Self {
-        if anon {
-            Self(self.0 | PA_ANON)
-        } else {
-            Self(self.0 & !PA_ANON)
-        }
-    }
-
     fn is_present(&self) -> bool {
         self.0 & PA_P != 0
     }
@@ -210,10 +202,6 @@ impl PageAttribute for PageAttribute64 {
     fn is_mapped(&self) -> bool {
         self.0 & PA_MMAP != 0
     }
-
-    fn is_anonymous(&self) -> bool {
-        self.0 & PA_ANON != 0
-    }
 }
 
 pub type DefaultPagingMode = PagingMode4Levels;

+ 0 - 2
crates/eonix_mm/src/page_table/pte.rs

@@ -13,7 +13,6 @@ pub trait PageAttribute: Copy {
     fn global(self, global: bool) -> Self;
     fn copy_on_write(self, cow: bool) -> Self;
     fn mapped(self, mmap: bool) -> Self;
-    fn anonymous(self, anon: bool) -> Self;
 
     fn is_present(&self) -> bool;
     fn is_write(&self) -> bool;
@@ -24,7 +23,6 @@ pub trait PageAttribute: Copy {
     fn is_global(&self) -> bool;
     fn is_copy_on_write(&self) -> bool;
     fn is_mapped(&self) -> bool;
-    fn is_anonymous(&self) -> bool;
 }
 
 pub trait PTE: Sized {

+ 9 - 2
src/kernel/mem/mm_area.rs

@@ -5,6 +5,8 @@ use crate::KResult;
 use core::{borrow::Borrow, cell::UnsafeCell, cmp::Ordering};
 use eonix_mm::address::{AddrOps as _, VAddr, VRange};
 use eonix_mm::page_table::{PageAttribute, PTE};
+use eonix_mm::paging::PFN;
+use super::mm_list::EMPTY_PAGE;
 
 #[derive(Debug)]
 pub struct MMArea {
@@ -97,7 +99,7 @@ impl MMArea {
         }
 
         let new_page;
-        if page_attr.is_anonymous() {
+        if is_anonymous(pfn) {
             new_page = Page::zeroed();
         } else {
             new_page = Page::alloc();
@@ -114,7 +116,6 @@ impl MMArea {
         }
 
         page_attr = page_attr.accessed(false);
-        page_attr = page_attr.anonymous(false);
 
         pte.set(new_page.into_raw(), page_attr);
 
@@ -174,6 +175,12 @@ impl MMArea {
     }
 }
 
+/// check pfn with EMPTY_PAGE's pfn
+fn is_anonymous(pfn: PFN) -> bool {
+    let empty_pfn = EMPTY_PAGE.pfn();
+    pfn == empty_pfn
+}
+
 impl Eq for MMArea {}
 impl PartialEq for MMArea {
     fn eq(&self, other: &Self) -> bool {

+ 1 - 3
src/kernel/mem/mm_list.rs

@@ -26,7 +26,7 @@ use eonix_sync::{LazyLock, Mutex};
 pub use mapping::{FileMapping, Mapping};
 pub use page_fault::handle_page_fault;
 
-static EMPTY_PAGE: LazyLock<Page> = LazyLock::new(|| Page::zeroed());
+pub static EMPTY_PAGE: LazyLock<Page> = LazyLock::new(|| Page::zeroed());
 static KERNEL_ROOT_TABLE_PAGE: LazyLock<PageUnmanaged> = LazyLock::new(|| unsafe {
     // SAFETY: The kernel page table is always valid.
     PageUnmanaged::from_raw_unchecked(DefaultPagingMode::KERNEL_ROOT_TABLE_PFN)
@@ -591,7 +591,6 @@ where
             .present(true)
             .user(true)
             .copy_on_write(true)
-            .anonymous(true)
             .execute(execute);
 
         self.set(EMPTY_PAGE.clone().into_raw(), attr);
@@ -603,7 +602,6 @@ where
         let attr = <Self as PTE>::Attr::new()
             .user(true)
             .copy_on_write(true)
-            .anonymous(true)
             .mapped(true)
             .execute(execute);