From 38883485c80841f15365d0502418dcc224f01d45 Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Wed, 5 Jun 2024 23:01:19 +0200 Subject: mm: use linked-list-allocator as kmalloc I'll implement my own allocator later. Currently using linked-list allocator [1] to manage the kernel heap (as in kmalloc, not vmalloc). It manages the ID-mapped region (from VA 0xffff_8000_0000_0000). This allocator is initialized to use the _largest_ physical memory block. If the kernel image (text and data) live in this zone then skip the occupied part. Key difference between kmalloc and vmalloc: - kmalloc pretty much manages the physical memory: the allocated address are within the id-mapped region (see above) therefore the allocated memory must also be contigous in physical memory. Such memory MUST NOT page fault. This is prone to fragmentation, so do not use kmalloc to allocate big objects (e.g. bigger than one 4k page). - vmalloc manages kernel heap memory and the mapping is managed by paging. Such memory could trigger pagefault in kernel mode. Note that the kmalloc conflicts with the previous used stack based PMA as they operates on the same VM zone. References: [1] https://github.com/rust-osdev/linked-list-allocator Signed-off-by: Tianhao Wang --- src/mm/pma.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/mm/pma.rs') diff --git a/src/mm/pma.rs b/src/mm/pma.rs index 7111137..359e406 100644 --- a/src/mm/pma.rs +++ b/src/mm/pma.rs @@ -8,6 +8,12 @@ extern "C" { fn ___FREE_PAGE_STACK__(); } +// disabled for now +// lazy_static! { +// pub static ref GLOBAL_PMA: Mutex = +// Mutex::new(pma::PageStackAllocator::new()); +// } + /// There should only be one global instance of this. pub struct PageStackAllocator { page_stack: &'static mut [u64], -- cgit v1.2.3-70-g09d2