Remove slab allocator

This commit is contained in:
Jeremy Soller
2025-09-19 20:29:53 -06:00
parent eb69d37323
commit 7abe4e1051
6 changed files with 55 additions and 127 deletions
-9
View File
@@ -4,18 +4,9 @@ use crate::{
};
use rmm::Flusher;
#[cfg(not(feature = "slab"))]
pub use self::linked_list::Allocator;
#[cfg(feature = "slab")]
pub use self::slab::Allocator;
#[cfg(not(feature = "slab"))]
mod linked_list;
#[cfg(feature = "slab")]
mod slab;
unsafe fn map_heap(mapper: &mut KernelMapper, offset: usize, size: usize) {
unsafe {
let mapper = mapper
-43
View File
@@ -1,43 +0,0 @@
use core::alloc::{Alloc, AllocErr, Layout};
use slab_allocator::Heap;
use spin::Mutex;
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
pub struct Allocator;
impl Allocator {
pub unsafe fn init(offset: usize, size: usize) {
*HEAP.lock() = Some(Heap::new(offset, size));
}
}
unsafe impl<'a> Alloc for &'a Allocator {
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
if let Some(ref mut heap) = *HEAP.lock() {
heap.allocate(layout)
} else {
panic!("__rust_allocate: heap not initialized");
}
}
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
if let Some(ref mut heap) = *HEAP.lock() {
heap.deallocate(ptr, layout)
} else {
panic!("__rust_deallocate: heap not initialized");
}
}
fn oom(&mut self, error: AllocErr) -> ! {
panic!("Out of memory: {:?}", error);
}
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
if let Some(ref mut heap) = *HEAP.lock() {
heap.usable_size(layout)
} else {
panic!("__rust_usable_size: heap not initialized");
}
}
}