diff --git a/ostd/src/mm/frame/segment.rs b/ostd/src/mm/frame/segment.rs index 260272e3c..6c7b15f68 100644 --- a/ostd/src/mm/frame/segment.rs +++ b/ostd/src/mm/frame/segment.rs @@ -8,7 +8,7 @@ use core::{mem::ManuallyDrop, ops::Range}; use super::{inc_page_ref_count, meta::FrameMeta, Frame}; use crate::mm::{Paddr, PAGE_SIZE}; -/// A contiguous range of physical memory pages. +/// A contiguous range of homogeneous physical memory pages. /// /// This is a handle to many contiguous pages. It will be more lightweight /// than owning an array of page handles. @@ -17,13 +17,16 @@ use crate::mm::{Paddr, PAGE_SIZE}; /// When constructing a `Segment`, the page handles are created then /// forgotten, leaving the reference count. When dropping a it, the page /// handles are restored and dropped, decrementing the reference count. +/// +/// All the metadata of the pages are homogeneous, i.e., they are of the same +/// type. #[derive(Debug)] -pub struct Segment { +pub struct Segment { range: Range, _marker: core::marker::PhantomData, } -impl Drop for Segment { +impl Drop for Segment { fn drop(&mut self) { for paddr in self.range.clone().step_by(PAGE_SIZE) { // SAFETY: for each page there would be a forgotten handle @@ -33,7 +36,7 @@ impl Drop for Segment { } } -impl Clone for Segment { +impl Clone for Segment { fn clone(&self) -> Self { for paddr in self.range.clone().step_by(PAGE_SIZE) { // SAFETY: for each page there would be a forgotten handle @@ -72,7 +75,9 @@ impl Segment { _marker: core::marker::PhantomData, } } +} +impl Segment { /// Gets the start physical address of the contiguous pages. pub fn start_paddr(&self) -> Paddr { self.range.start @@ -145,7 +150,7 @@ impl Segment { } } -impl From> for Segment { +impl From> for Segment { fn from(page: Frame) -> Self { let pa = page.paddr(); let _ = ManuallyDrop::new(page); @@ -156,7 +161,7 @@ impl From> for Segment { } } -impl From> for Vec> { +impl From> for Vec> { fn from(pages: Segment) -> Self { let vector = pages .range @@ -172,7 +177,7 @@ impl From> for Vec> { } } -impl Iterator for Segment { +impl Iterator for Segment { type Item = Frame; fn next(&mut self) -> Option {