Experimental MMIO freelist
This commit is contained in:
parent
ed4aef8978
commit
0a3d0147a8
@ -20,6 +20,7 @@ use talc::*;
|
||||
pub extern crate alloc;
|
||||
|
||||
static FREELIST: Mutex<FreeList<32>> = Mutex::new(FreeList::<32>::new());
|
||||
static HW_FREELIST: Mutex<FreeList<32>> = Mutex::new(FreeList::<32>::new());
|
||||
|
||||
lazy_static! {
|
||||
pub static ref MEMMAP_RESPONSE: &'static MemoryMapResponse = MEMMAP_REQUEST
|
||||
@ -49,6 +50,45 @@ pub fn deallocate_usable() -> Result<(), AllocError> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deallocate_hardware() -> Result<(), AllocError> {
|
||||
let mut any_error: Option<AllocError> = None;
|
||||
let mut bytes_deallocated: u64 = 0;
|
||||
for entry in MEMMAP_RESPONSE.entries() {
|
||||
if (entry.entry_type == EntryType::ACPI_NVS)
|
||||
| (entry.entry_type == EntryType::RESERVED)
|
||||
| (entry.entry_type == EntryType::FRAMEBUFFER)
|
||||
{
|
||||
if let Err(error) = {
|
||||
let adjusted_base = if (entry.length as usize) < PAGE_SIZE {
|
||||
entry.base as usize - (PAGE_SIZE - entry.length as usize)
|
||||
} else {
|
||||
entry.base as usize
|
||||
};
|
||||
let adjusted_length = if (entry.length as usize) < PAGE_SIZE {
|
||||
PAGE_SIZE
|
||||
} else {
|
||||
entry.length as usize
|
||||
};
|
||||
let range = PageRange::from_start_len(adjusted_base, adjusted_length as usize);
|
||||
log_trace!("Deallocating 0x{:x} @ 0x{:x} hardware reserved memory", adjusted_length, adjusted_base);
|
||||
match range {
|
||||
Ok(range_inner) => {unsafe { HW_FREELIST.lock().deallocate(range_inner) }},
|
||||
Err(err) => {Ok(log_error!("Failed to convert range 0x{:x} @ 0x{:x}: {}", adjusted_length, adjusted_base, err))},
|
||||
}
|
||||
} {
|
||||
any_error = Some(error);
|
||||
}
|
||||
bytes_deallocated += entry.length;
|
||||
}
|
||||
}
|
||||
log_trace!("Deallocated 0x{:x} bytes of hardware reserved memory", bytes_deallocated);
|
||||
if let Some(error) = any_error {
|
||||
Err(error)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deallocate(entry: limine::memory_map::Entry) -> Result<(), AllocError> {
|
||||
let range = PageRange::from_start_len(entry.base as usize, entry.length as usize)
|
||||
.expect("Could not convert map entry to range!");
|
||||
@ -114,6 +154,7 @@ pub fn log_memory() {
|
||||
);
|
||||
log_trace!("Deallocating available memory...");
|
||||
let _ = deallocate_usable();
|
||||
let _ = deallocate_hardware();
|
||||
let free_bytes = { FREELIST.lock().free_space() };
|
||||
log_info!(
|
||||
"Freelist: 0x{:x} bytes ({} pages)",
|
||||
@ -174,7 +215,7 @@ lazy_static! {
|
||||
}
|
||||
|
||||
// TODO: 1mb kernel heap. Need to figure out how to make this less stupid...
|
||||
static mut ARENA: [u8; 1000000] = [0; 1000000];
|
||||
static mut ARENA: [u8; 100000] = [0; 100000];
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> =
|
||||
|
Loading…
Reference in New Issue
Block a user