support low ram machine
Some checks failed
Check / Build ISO (nightly-2025-04-27) (push) Failing after 43s

This commit is contained in:
Masato Imai
2025-08-22 12:59:05 +00:00
parent ecad19bb5e
commit b215f0010f
4 changed files with 21 additions and 10 deletions

View File

@ -6,7 +6,7 @@ EFI_BINARY="$1"
./create-iso.sh "$EFI_BINARY"
qemu-system-x86_64 -enable-kvm \
-m 4G \
-m 512M \
-serial mon:stdio \
-nographic \
-no-reboot \

View File

@ -13,7 +13,4 @@ pub const HEAP_START: usize = 0x4444_4444_0000;
pub const HEAP_SIZE: usize = 128 * 1024;
pub const PAGE_SIZE: usize = 4096;
pub const MAX_MEMORY: usize = 256 * 1024 * 1024 * 1024;
pub const FRAME_COUNT: usize = MAX_MEMORY / PAGE_SIZE;
pub const BITS_PER_ENTRY: usize = 8 * core::mem::size_of::<usize>();
pub const ENTRY_COUNT: usize = FRAME_COUNT / BITS_PER_ENTRY;

View File

@ -98,10 +98,13 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
let ranges = boot_info.usable_memory.ranges();
let mut count = 0;
let mut max_range = 0;
for range in ranges {
count += range.end - range.start;
max_range = max_range.max(range.end);
}
info!("Usable memory: {}MiB", count / 1024 / 1024);
memory::memory::MAX_MEMORY.call_once(|| max_range as usize * 2);
let mut bitmap_table = BitmapMemoryTable::init(&boot_info.usable_memory);
info!(

View File

@ -1,12 +1,22 @@
use core::slice;
use nel_os_common::memory::{self, UsableMemory};
use spin::Once;
use x86_64::{
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
PhysAddr,
};
use crate::constant::{BITS_PER_ENTRY, ENTRY_COUNT, PAGE_SIZE};
use crate::{
constant::{BITS_PER_ENTRY, PAGE_SIZE},
info,
};
pub static MAX_MEMORY: Once<usize> = Once::new();
pub fn get_entry_count() -> usize {
MAX_MEMORY.get().unwrap_or(&0) / PAGE_SIZE / BITS_PER_ENTRY
}
pub struct BitmapMemoryTable {
pub used_map: &'static mut [usize],
@ -21,16 +31,17 @@ impl BitmapMemoryTable {
max_addr = max_addr.max(range.end);
}
let bitmap_size = ENTRY_COUNT * core::mem::size_of::<usize>();
let entry_count = get_entry_count();
let bitmap_size = entry_count * core::mem::size_of::<usize>();
let bitmap_addr = ((max_addr as usize).saturating_sub(bitmap_size)) & !(PAGE_SIZE - 1);
let used_map = unsafe {
let ptr = bitmap_addr as *mut usize;
slice::from_raw_parts_mut(ptr, ENTRY_COUNT)
slice::from_raw_parts_mut(ptr, entry_count)
};
(0..ENTRY_COUNT).for_each(|i| {
(0..entry_count).for_each(|i| {
used_map[i] = 0;
});
@ -50,8 +61,8 @@ impl BitmapMemoryTable {
table.set_frame(bitmap_start_frame + i, false);
}
for i in 0..ENTRY_COUNT {
let index = ENTRY_COUNT - i - 1;
for i in 0..entry_count {
let index = entry_count - i - 1;
if table.used_map[index] != 0 {
let offset = 63 - table.used_map[index].leading_zeros();
table.end = index * BITS_PER_ENTRY + (BITS_PER_ENTRY - offset as usize);