fix: accurate total system RAM calculation from all physical memory regions
This commit is contained in:
@@ -323,7 +323,7 @@ pub extern "C" fn kernel_syscall_dispatcher(regs: &mut SyscallRegisters) {
|
||||
let active = sched.threads.iter().filter(|t| t.state != crate::sched::thread::ThreadState::Unused).count();
|
||||
|
||||
(*out_ptr).uptime_ticks = sched.ticks;
|
||||
(*out_ptr).total_memory_bytes = pfa.usable_ram_bytes;
|
||||
(*out_ptr).total_memory_bytes = pfa.total_ram_bytes;
|
||||
(*out_ptr).free_memory_bytes = (pfa.free_frames * PAGE_SIZE) as u64;
|
||||
(*out_ptr).active_threads = active as u32;
|
||||
(*out_ptr).cpu_cores = CORES_ONLINE.load(Ordering::Relaxed) as u32;
|
||||
|
||||
@@ -12,6 +12,7 @@ pub struct FrameAllocator {
|
||||
pub total_frames: usize,
|
||||
pub free_frames: usize,
|
||||
pub usable_ram_bytes: u64,
|
||||
pub total_ram_bytes: u64,
|
||||
pub hhdm_offset: u64,
|
||||
}
|
||||
|
||||
@@ -24,6 +25,7 @@ pub static mut PFA: FrameAllocator = FrameAllocator {
|
||||
total_frames: 0,
|
||||
free_frames: 0,
|
||||
usable_ram_bytes: 0,
|
||||
total_ram_bytes: 0,
|
||||
hhdm_offset: 0,
|
||||
};
|
||||
|
||||
@@ -38,15 +40,25 @@ impl FrameAllocator {
|
||||
let entry_count = (*memmap).entry_count as usize;
|
||||
let entries_ptr = (*memmap).entries;
|
||||
let mut max_paddr: u64 = 0;
|
||||
let mut total_ram: u64 = 0;
|
||||
for i in 0..entry_count {
|
||||
let entry = *entries_ptr.add(i);
|
||||
let end = (*entry).base + (*entry).length;
|
||||
if end > max_paddr {
|
||||
max_paddr = end;
|
||||
}
|
||||
let t = (*entry).typ;
|
||||
if t == LimineMemoryType::Usable as u64
|
||||
|| t == LimineMemoryType::BootloaderReclaimable as u64
|
||||
|| t == LimineMemoryType::KernelAndModules as u64
|
||||
|| t == LimineMemoryType::AcpiReclaimable as u64
|
||||
{
|
||||
total_ram += (*entry).length;
|
||||
}
|
||||
}
|
||||
|
||||
self.total_frames = (max_paddr as usize) / PAGE_SIZE;
|
||||
self.total_ram_bytes = total_ram;
|
||||
self.bitmap_size_bytes = (self.total_frames + 7) / 8;
|
||||
|
||||
// Find a usable region large enough to place the bitmap
|
||||
|
||||
Reference in New Issue
Block a user