Rename various concepts related to memory management

This commit is contained in:
Zhang Junyang
2024-05-26 17:53:44 +00:00
committed by Tate, Hongliang Tian
parent 03a39c94ca
commit 14e1b1a9fc
97 changed files with 331 additions and 353 deletions

View File

@ -2,8 +2,8 @@
use align_ext::AlignExt;
use aster_frame::{
mm::{Frame, Segment, VmReader, VmWriter},
sync::WaitQueue,
vm::{VmFrame, VmReader, VmSegment, VmWriter},
};
use int_to_c_enum::TryFromInt;
@ -359,7 +359,7 @@ pub enum BioStatus {
#[derive(Debug, Clone)]
pub struct BioSegment {
/// The contiguous pages on which this segment resides.
pages: VmSegment,
pages: Segment,
/// The starting offset (in bytes) within the first page.
/// The offset should always be aligned to the sector size and
/// must not exceed the size of a single page.
@ -373,8 +373,8 @@ pub struct BioSegment {
const SECTOR_SIZE: u16 = super::SECTOR_SIZE as u16;
impl<'a> BioSegment {
/// Constructs a new `BioSegment` from `VmSegment`.
pub fn from_segment(segment: VmSegment, offset: usize, len: usize) -> Self {
/// Constructs a new `BioSegment` from `Segment`.
pub fn from_segment(segment: Segment, offset: usize, len: usize) -> Self {
assert!(offset + len <= segment.nbytes());
Self {
@ -384,12 +384,12 @@ impl<'a> BioSegment {
}
}
/// Constructs a new `BioSegment` from `VmFrame`.
pub fn from_frame(frame: VmFrame, offset: usize, len: usize) -> Self {
/// Constructs a new `BioSegment` from `Frame`.
pub fn from_frame(frame: Frame, offset: usize, len: usize) -> Self {
assert!(offset + len <= super::BLOCK_SIZE);
Self {
pages: VmSegment::from(frame),
pages: Segment::from(frame),
offset: AlignedUsize::<SECTOR_SIZE>::new(offset).unwrap(),
len: AlignedUsize::<SECTOR_SIZE>::new(len).unwrap(),
}
@ -411,7 +411,7 @@ impl<'a> BioSegment {
}
/// Returns the contiguous pages on which this segment resides.
pub fn pages(&self) -> &VmSegment {
pub fn pages(&self) -> &Segment {
&self.pages
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use aster_frame::vm::{VmAllocOptions, VmFrame, VmIo, VmSegment};
use aster_frame::mm::{Frame, Segment, VmAllocOptions, VmIo};
use super::{
bio::{Bio, BioEnqueueError, BioSegment, BioStatus, BioType, BioWaiter, SubmittedBio},
@ -16,7 +16,7 @@ impl dyn BlockDevice {
pub fn read_blocks_sync(
&self,
bid: Bid,
segment: &VmSegment,
segment: &Segment,
) -> Result<BioStatus, BioEnqueueError> {
let bio = create_bio_from_segment(BioType::Read, bid, segment);
let status = bio.submit_sync(self)?;
@ -24,20 +24,20 @@ impl dyn BlockDevice {
}
/// Asynchronously reads contiguous blocks starting from the `bid`.
pub fn read_blocks(&self, bid: Bid, segment: &VmSegment) -> Result<BioWaiter, BioEnqueueError> {
pub fn read_blocks(&self, bid: Bid, segment: &Segment) -> Result<BioWaiter, BioEnqueueError> {
let bio = create_bio_from_segment(BioType::Read, bid, segment);
bio.submit(self)
}
/// Synchronously reads one block indicated by the `bid`.
pub fn read_block_sync(&self, bid: Bid, frame: &VmFrame) -> Result<BioStatus, BioEnqueueError> {
pub fn read_block_sync(&self, bid: Bid, frame: &Frame) -> Result<BioStatus, BioEnqueueError> {
let bio = create_bio_from_frame(BioType::Read, bid, frame);
let status = bio.submit_sync(self)?;
Ok(status)
}
/// Asynchronously reads one block indicated by the `bid`.
pub fn read_block(&self, bid: Bid, frame: &VmFrame) -> Result<BioWaiter, BioEnqueueError> {
pub fn read_block(&self, bid: Bid, frame: &Frame) -> Result<BioWaiter, BioEnqueueError> {
let bio = create_bio_from_frame(BioType::Read, bid, frame);
bio.submit(self)
}
@ -46,7 +46,7 @@ impl dyn BlockDevice {
pub fn write_blocks_sync(
&self,
bid: Bid,
segment: &VmSegment,
segment: &Segment,
) -> Result<BioStatus, BioEnqueueError> {
let bio = create_bio_from_segment(BioType::Write, bid, segment);
let status = bio.submit_sync(self)?;
@ -54,28 +54,20 @@ impl dyn BlockDevice {
}
/// Asynchronously writes contiguous blocks starting from the `bid`.
pub fn write_blocks(
&self,
bid: Bid,
segment: &VmSegment,
) -> Result<BioWaiter, BioEnqueueError> {
pub fn write_blocks(&self, bid: Bid, segment: &Segment) -> Result<BioWaiter, BioEnqueueError> {
let bio = create_bio_from_segment(BioType::Write, bid, segment);
bio.submit(self)
}
/// Synchronously writes one block indicated by the `bid`.
pub fn write_block_sync(
&self,
bid: Bid,
frame: &VmFrame,
) -> Result<BioStatus, BioEnqueueError> {
pub fn write_block_sync(&self, bid: Bid, frame: &Frame) -> Result<BioStatus, BioEnqueueError> {
let bio = create_bio_from_frame(BioType::Write, bid, frame);
let status = bio.submit_sync(self)?;
Ok(status)
}
/// Asynchronously writes one block indicated by the `bid`.
pub fn write_block(&self, bid: Bid, frame: &VmFrame) -> Result<BioWaiter, BioEnqueueError> {
pub fn write_block(&self, bid: Bid, frame: &Frame) -> Result<BioWaiter, BioEnqueueError> {
let bio = create_bio_from_frame(BioType::Write, bid, frame);
bio.submit(self)
}
@ -202,7 +194,7 @@ impl dyn BlockDevice {
}
// TODO: Maybe we should have a builder for `Bio`.
fn create_bio_from_segment(type_: BioType, bid: Bid, segment: &VmSegment) -> Bio {
fn create_bio_from_segment(type_: BioType, bid: Bid, segment: &Segment) -> Bio {
let bio_segment = BioSegment::from_segment(segment.clone(), 0, segment.nbytes());
Bio::new(
type_,
@ -213,7 +205,7 @@ fn create_bio_from_segment(type_: BioType, bid: Bid, segment: &VmSegment) -> Bio
}
// TODO: Maybe we should have a builder for `Bio`.
fn create_bio_from_frame(type_: BioType, bid: Bid, frame: &VmFrame) -> Bio {
fn create_bio_from_frame(type_: BioType, bid: Bid, frame: &Frame) -> Bio {
let bio_segment = BioSegment::from_frame(frame.clone(), 0, BLOCK_SIZE);
Bio::new(
type_,

View File

@ -49,7 +49,7 @@ use self::{
prelude::*,
};
pub const BLOCK_SIZE: usize = aster_frame::vm::PAGE_SIZE;
pub const BLOCK_SIZE: usize = aster_frame::mm::PAGE_SIZE;
pub const SECTOR_SIZE: usize = 512;
pub trait BlockDevice: Send + Sync + Any + Debug {

View File

@ -10,7 +10,7 @@ extern crate alloc;
use alloc::{collections::BTreeMap, fmt::Debug, string::String, sync::Arc, vec::Vec};
use core::any::Any;
use aster_frame::{sync::SpinLock, vm::VmReader};
use aster_frame::{mm::VmReader, sync::SpinLock};
use component::{init_component, ComponentInitError};
use spin::Once;

View File

@ -16,8 +16,8 @@ use core::{
use aster_frame::{
boot,
io_mem::IoMem,
mm::{VmIo, PAGE_SIZE},
sync::SpinLock,
vm::{VmIo, PAGE_SIZE},
};
use component::{init_component, ComponentInitError};
use font8x8::UnicodeFonts;
@ -39,7 +39,7 @@ pub(crate) fn init() {
let mut writer = {
let framebuffer = boot::framebuffer_arg();
let mut size = 0;
for i in aster_frame::vm::FRAMEBUFFER_REGIONS.get().unwrap().iter() {
for i in aster_frame::mm::FRAMEBUFFER_REGIONS.get().unwrap().iter() {
size = i.len();
}

View File

@ -4,8 +4,8 @@ use alloc::{collections::LinkedList, sync::Arc};
use align_ext::AlignExt;
use aster_frame::{
mm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE},
sync::SpinLock,
vm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE},
};
use pod::Pod;
use spin::Once;

View File

@ -9,8 +9,8 @@ use alloc::{
use core::ops::Range;
use aster_frame::{
mm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE},
sync::{RwLock, SpinLock},
vm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE},
};
use bitvec::{array::BitArray, prelude::Lsb0};
use ktest::ktest;

View File

@ -2,7 +2,7 @@
use alloc::vec;
use aster_frame::vm::VmWriter;
use aster_frame::mm::VmWriter;
use smoltcp::{phy, time::Instant};
use crate::{buffer::RxBuffer, AnyNetworkDevice};

View File

@ -9,9 +9,9 @@ use aster_block::{
};
use aster_frame::{
io_mem::IoMem,
mm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmIo},
sync::SpinLock,
trap::TrapFrame,
vm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmIo},
};
use aster_util::safe_ptr::SafePtr;
use id_alloc::IdAlloc;

View File

@ -6,9 +6,9 @@ use core::hint::spin_loop;
use aster_console::{AnyConsoleDevice, ConsoleCallback};
use aster_frame::{
io_mem::IoMem,
mm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmReader},
sync::{RwLock, SpinLock},
trap::TrapFrame,
vm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmReader},
};
use aster_util::safe_ptr::SafePtr;
use log::debug;

View File

@ -10,10 +10,10 @@ use core::{fmt::Debug, iter, mem};
use aster_frame::{
io_mem::IoMem,
mm::{DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmIo, PAGE_SIZE},
offset_of,
sync::{RwLock, SpinLock},
trap::TrapFrame,
vm::{DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmIo, PAGE_SIZE},
};
use aster_input::{
key::{Key, KeyStatus},

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use aster_frame::vm::{DmaCoherent, DmaStream, DmaStreamSlice, HasDaddr};
use aster_frame::mm::{DmaCoherent, DmaStream, DmaStreamSlice, HasDaddr};
use aster_network::{DmaSegment, RxBuffer, TxBuffer};
/// A DMA-capable buffer.

View File

@ -10,8 +10,8 @@ use core::{
use aster_frame::{
io_mem::IoMem,
mm::{DmaCoherent, VmAllocOptions},
offset_of,
vm::{DmaCoherent, VmAllocOptions},
};
use aster_rights::{Dup, TRightSet, TRights, Write};
use aster_util::{field_ptr, safe_ptr::SafePtr};
@ -74,7 +74,7 @@ impl VirtQueue {
let (descriptor_ptr, avail_ring_ptr, used_ring_ptr) = if transport.is_legacy_version() {
// FIXME: How about pci legacy?
// Currently, we use one VmFrame to place the descriptors and avaliable rings, one VmFrame to place used rings
// Currently, we use one Frame to place the descriptors and avaliable rings, one Frame to place used rings
// because the virtio-mmio legacy required the address to be continuous. The max queue size is 128.
if size > 128 {
return Err(QueueError::InvalidArgs);

View File

@ -9,10 +9,10 @@ use aster_frame::{
device::{MmioCommonDevice, VirtioMmioVersion},
},
io_mem::IoMem,
mm::{DmaCoherent, PAGE_SIZE},
offset_of,
sync::RwLock,
trap::IrqCallbackFunction,
vm::{DmaCoherent, PAGE_SIZE},
};
use aster_rights::{ReadOp, WriteOp};
use aster_util::{field_ptr, safe_ptr::SafePtr};

View File

@ -3,7 +3,7 @@
use alloc::boxed::Box;
use core::fmt::Debug;
use aster_frame::{io_mem::IoMem, trap::IrqCallbackFunction, vm::DmaCoherent};
use aster_frame::{io_mem::IoMem, mm::DmaCoherent, trap::IrqCallbackFunction};
use aster_util::safe_ptr::SafePtr;
use self::{mmio::virtio_mmio_init, pci::virtio_pci_init};

View File

@ -11,9 +11,9 @@ use aster_frame::{
BusProbeError,
},
io_mem::IoMem,
mm::DmaCoherent,
offset_of,
trap::IrqCallbackFunction,
vm::DmaCoherent,
};
use aster_util::{field_ptr, safe_ptr::SafePtr};
use log::{info, warn};