From 08db5fe1f7ff72b67ef6482172f764f68d8c12e9 Mon Sep 17 00:00:00 2001 From: Nathan Giddings Date: Sat, 2 Sep 2023 21:51:19 -0500 Subject: [PATCH] Kernel heap now allocates all required pages at once As opposed to allocating pages individually --- src/heap.c | 22 +++++++++++++++++++--- src/mmgr.c | 18 +----------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/heap.c b/src/heap.c index a955aae..d6a335e 100644 --- a/src/heap.c +++ b/src/heap.c @@ -41,18 +41,34 @@ int kminit(void *base, size_t heap_size) .size = 0 }; memmap_insert_region(&map, base, heap_size, M_AVAILABLE); - for(void *p = base; p < (base + heap_size); p += page_size) + physaddr_t phys_addr = reserve_pages(heap_size); + if(phys_addr == ENOMEM) + { + return ENOMEM; + } + for(unsigned long off = 0; off < heap_size; off += page_size) + { + if((page_type(base + off) & PAGE_PRESENT)) + { + continue; + } + else if(map_page(base + off, phys_addr + off, PAGE_RW)) + { + return ENOMEM; + } + } + /*for(void *p = base; p < (base + heap_size); p += page_size) { if((page_type(p) & PAGE_PRESENT)) { continue; } - physaddr_t frame = reserve_page(); + //physaddr_t frame = reserve_page(); if(frame == ENOMEM || map_page(p, frame, PAGE_RW)) { return ENOMEM; } - } + }*/ return list_alloc_init(&system_heap, &map); } diff --git a/src/mmgr.c b/src/mmgr.c index 1957076..35c814e 100644 --- a/src/mmgr.c +++ b/src/mmgr.c @@ -15,6 +15,7 @@ buddy_descriptor_t page_alloc; physaddr_t reserve_pages(size_t size) { unsigned long location = buddy_reserve(&page_alloc, size); + printf("Reserved >=%08x pages at %08x\n", size, location); if(location != NOMEM) { return location; @@ -116,8 +117,6 @@ error_t initialize_page_map(memory_map_t *map, void *base, size_t memory_size, u continue; } } - - printf("Initializing page allocator...\n"); if(buddy_alloc_init(&page_alloc, map)) { @@ -125,21 +124,6 @@ error_t initialize_page_map(memory_map_t *map, void *base, size_t memory_size, u } else { - printf("page_alloc = {\n\t" \ - "avail = %08x\n\t" \ - "block_map = %08x\n\t" \ - "block_map_size = %08x\n\t" \ - "max_kval = %i\n\t" \ - "block_size = %i\n\t" \ - "offset = %08x\n\t" \ - "free_block_count = %08x\n}", - page_alloc.avail, - page_alloc.block_map, - page_alloc.block_map_size, - page_alloc.max_kval, - page_alloc.block_size, - page_alloc.offset, - page_alloc.free_block_count); return ENONE; } }