Disable IRQ during page allocation

This commit is contained in:
Chen Chengjun
2024-11-01 10:15:32 +08:00
committed by Tate, Hongliang Tian
parent 846b3ba169
commit c7b3a596dd

View File

@ -65,10 +65,16 @@ pub(in crate::mm) static PAGE_ALLOCATOR: Once<SpinLock<CountingFrameAllocator>>
/// ///
/// The metadata of the page is initialized with the given metadata. /// The metadata of the page is initialized with the given metadata.
pub(crate) fn alloc_single<M: PageMeta>(metadata: M) -> Option<Page<M>> { pub(crate) fn alloc_single<M: PageMeta>(metadata: M) -> Option<Page<M>> {
PAGE_ALLOCATOR.get().unwrap().lock().alloc(1).map(|idx| { PAGE_ALLOCATOR
let paddr = idx * PAGE_SIZE; .get()
Page::from_unused(paddr, metadata) .unwrap()
}) .disable_irq()
.lock()
.alloc(1)
.map(|idx| {
let paddr = idx * PAGE_SIZE;
Page::from_unused(paddr, metadata)
})
} }
/// Allocate a contiguous range of pages of a given length in bytes. /// Allocate a contiguous range of pages of a given length in bytes.
@ -88,6 +94,7 @@ where
PAGE_ALLOCATOR PAGE_ALLOCATOR
.get() .get()
.unwrap() .unwrap()
.disable_irq()
.lock() .lock()
.alloc(len / PAGE_SIZE) .alloc(len / PAGE_SIZE)
.map(|start| { .map(|start| {
@ -113,7 +120,7 @@ where
{ {
assert!(len % PAGE_SIZE == 0); assert!(len % PAGE_SIZE == 0);
let nframes = len / PAGE_SIZE; let nframes = len / PAGE_SIZE;
let mut allocator = PAGE_ALLOCATOR.get().unwrap().lock(); let mut allocator = PAGE_ALLOCATOR.get().unwrap().disable_irq().lock();
let mut vector = Vec::new(); let mut vector = Vec::new();
for _ in 0..nframes { for _ in 0..nframes {
let paddr = allocator.alloc(1)? * PAGE_SIZE; let paddr = allocator.alloc(1)? * PAGE_SIZE;