mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 09:23:25 +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 {
|
} else {
|
||||||
let mut frame_list = Vec::new();
|
let mut frame_list = Vec::new();
|
||||||
for _ in 0..self.nframes {
|
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)
|
FrameVec(frame_list)
|
||||||
};
|
};
|
||||||
@ -73,7 +75,8 @@ impl FrameAllocOptions {
|
|||||||
return Err(Error::InvalidArgs);
|
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 {
|
if !self.uninit {
|
||||||
frame.writer().fill(0);
|
frame.writer().fill(0);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,10 @@ use buddy_system_allocator::FrameAllocator;
|
|||||||
use log::info;
|
use log::info;
|
||||||
use spin::Once;
|
use spin::Once;
|
||||||
|
|
||||||
use super::{meta::FrameMeta, Page};
|
use super::{
|
||||||
|
meta::{FrameMeta, PageMeta},
|
||||||
|
Page,
|
||||||
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
boot::memory_region::MemoryRegionType,
|
boot::memory_region::MemoryRegionType,
|
||||||
mm::{Frame, FrameVec, Segment, PAGE_SIZE},
|
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| {
|
FRAME_ALLOCATOR.get().unwrap().lock().alloc(1).map(|idx| {
|
||||||
let paddr = idx * PAGE_SIZE;
|
let paddr = idx * PAGE_SIZE;
|
||||||
Frame {
|
Page::<T>::from_unused(paddr)
|
||||||
page: Page::<FrameMeta>::from_unused(paddr),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user