mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 01:13:23 +00:00
Refactor alloc_single API for page and frame
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
bd1d076e8c
commit
2ceba78d47
@ -54,7 +54,9 @@ impl FrameAllocOptions {
|
||||
} else {
|
||||
let mut frame_list = Vec::new();
|
||||
for _ in 0..self.nframes {
|
||||
frame_list.push(allocator::alloc_single().ok_or(Error::NoMemory)?);
|
||||
let page = allocator::alloc_single().ok_or(Error::NoMemory)?;
|
||||
let frame = Frame { page };
|
||||
frame_list.push(frame);
|
||||
}
|
||||
FrameVec(frame_list)
|
||||
};
|
||||
@ -73,7 +75,8 @@ impl FrameAllocOptions {
|
||||
return Err(Error::InvalidArgs);
|
||||
}
|
||||
|
||||
let frame = allocator::alloc_single().ok_or(Error::NoMemory)?;
|
||||
let page = allocator::alloc_single().ok_or(Error::NoMemory)?;
|
||||
let frame = Frame { page };
|
||||
if !self.uninit {
|
||||
frame.writer().fill(0);
|
||||
}
|
||||
|
@ -12,7 +12,10 @@ use buddy_system_allocator::FrameAllocator;
|
||||
use log::info;
|
||||
use spin::Once;
|
||||
|
||||
use super::{meta::FrameMeta, Page};
|
||||
use super::{
|
||||
meta::{FrameMeta, PageMeta},
|
||||
Page,
|
||||
};
|
||||
use crate::{
|
||||
boot::memory_region::MemoryRegionType,
|
||||
mm::{Frame, FrameVec, Segment, PAGE_SIZE},
|
||||
@ -40,12 +43,10 @@ pub(crate) fn alloc(nframes: usize) -> Option<FrameVec> {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn alloc_single() -> Option<Frame> {
|
||||
pub(crate) fn alloc_single<T: PageMeta>() -> Option<Page<T>> {
|
||||
FRAME_ALLOCATOR.get().unwrap().lock().alloc(1).map(|idx| {
|
||||
let paddr = idx * PAGE_SIZE;
|
||||
Frame {
|
||||
page: Page::<FrameMeta>::from_unused(paddr),
|
||||
}
|
||||
Page::<T>::from_unused(paddr)
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user