From ad20a71b66121469db9774f0e57375afa6eee8de Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Mon, 4 May 2020 22:38:31 +0800 Subject: [PATCH] zcore: update and lock bitmap-allocator. increase heap size and remove rescue. --- kernel-hal-bare/Cargo.toml | 2 +- kernel-hal/Cargo.toml | 2 +- zCore/Cargo.toml | 9 ++++----- zCore/src/memory.rs | 34 +++------------------------------- 4 files changed, 9 insertions(+), 38 deletions(-) diff --git a/kernel-hal-bare/Cargo.toml b/kernel-hal-bare/Cargo.toml index 07ad7f108..21fbb9b22 100644 --- a/kernel-hal-bare/Cargo.toml +++ b/kernel-hal-bare/Cargo.toml @@ -11,7 +11,7 @@ description = "Kernel HAL implementation for bare metal environment." log = "0.4" spin = "0.5" executor = { git = "https://github.com/PanQL/executor.git", rev="c86db90" } -trapframe = "0.1.6" +trapframe = "0.1.7" kernel-hal = { path = "../kernel-hal" } naive-timer= { git = "https://github.com/rcore-os/naive-timer.git", rev="cd44f4c" } lazy_static = { version = "1.4", features = ["spin_no_std" ] } diff --git a/kernel-hal/Cargo.toml b/kernel-hal/Cargo.toml index 8c3696b3e..068292c35 100644 --- a/kernel-hal/Cargo.toml +++ b/kernel-hal/Cargo.toml @@ -9,6 +9,6 @@ description = "Kernel HAL interface definations." [dependencies] bitflags = "1.2" -trapframe = "0.1.6" +trapframe = "0.1.7" git-version = "0.3" numeric-enum-macro = "0.2" diff --git a/zCore/Cargo.toml b/zCore/Cargo.toml index 6ea05f494..85c178304 100644 --- a/zCore/Cargo.toml +++ b/zCore/Cargo.toml @@ -12,17 +12,16 @@ graphic = [] [dependencies] log = "0.4" spin = "0.5" -buddy_system_allocator = "0.3.9" +buddy_system_allocator = "0.4.0" rlibc = "1.0" rboot = { path = "../rboot", default-features = false } kernel-hal-bare = { path = "../kernel-hal-bare" } lazy_static = { version = "1.4", features = ["spin_no_std" ] } -bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" } -trapframe = "0.1.6" -executor = { git = "https://github.com/PanQL/executor.git", rev="c86db90" } +bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator", rev = "03bd9909" } +trapframe = "0.1.7" +executor = { git = "https://github.com/PanQL/executor.git", rev = "c86db90" } zircon-loader = { path = "../zircon-loader", default-features = false } zircon-object = { path = "../zircon-object" } [target.'cfg(target_arch = "x86_64")'.dependencies] x86_64 = "0.10" -uart_16550 = "0.2" diff --git a/zCore/src/memory.rs b/zCore/src/memory.rs index 2503ebaaa..6db9828d3 100644 --- a/zCore/src/memory.rs +++ b/zCore/src/memory.rs @@ -3,7 +3,7 @@ use { bitmap_allocator::BitAlloc, - buddy_system_allocator::{Heap, LockedHeapWithRescue}, + buddy_system_allocator::LockedHeap, rboot::{BootInfo, MemoryType}, spin::Mutex, x86_64::structures::paging::page_table::{PageTable, PageTableFlags as EF}, @@ -17,7 +17,7 @@ static FRAME_ALLOCATOR: Mutex = Mutex::new(FrameAlloc::DEFAULT); const MEMORY_OFFSET: usize = 0; const KERNEL_OFFSET: usize = 0xffffff00_00000000; const PHYSICAL_MEMORY_OFFSET: usize = 0xffff8000_00000000; -const KERNEL_HEAP_SIZE: usize = 8 * 1024 * 1024; // 8 MB +const KERNEL_HEAP_SIZE: usize = 16 * 1024 * 1024; // 16 MB const KERNEL_PM4: usize = (KERNEL_OFFSET >> 39) & 0o777; const PHYSICAL_MEMORY_PM4: usize = (PHYSICAL_MEMORY_OFFSET >> 39) & 0o777; @@ -79,36 +79,8 @@ pub extern "C" fn hal_pt_map_kernel(pt: &mut PageTable, current: &PageTable) { pt[PHYSICAL_MEMORY_PM4].set_addr(ephysical.addr(), ephysical.flags() | EF::GLOBAL); } -fn enlarge_heap(heap: &mut Heap) { - error!("Enlarging heap to avoid oom"); - - let mut addrs = [(0, 0); 32]; - let mut addr_len = 0; - let va_offset = PMEM_BASE; - for _ in 0..16384 { - let page = hal_frame_alloc().unwrap(); - let va = va_offset + page; - if addr_len > 0 { - let (ref mut addr, ref mut len) = addrs[addr_len - 1]; - if *addr - PAGE_SIZE == va { - *len += PAGE_SIZE; - *addr -= PAGE_SIZE; - continue; - } - } - addrs[addr_len] = (va, PAGE_SIZE); - addr_len += 1; - } - for (addr, len) in addrs[..addr_len].iter() { - info!("Adding {:#X} {:#X} to heap", addr, len); - unsafe { - heap.init(*addr, *len); - } - } -} - /// Global heap allocator /// /// Available after `memory::init_heap()`. #[global_allocator] -static HEAP_ALLOCATOR: LockedHeapWithRescue = LockedHeapWithRescue::new(enlarge_heap); +static HEAP_ALLOCATOR: LockedHeap = LockedHeap::new();