From 80073d46d9466615fa3815ea33cc30e63ba3c24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Ch=C3=A9ramy?= Date: Tue, 20 Jan 2015 18:09:19 +0100 Subject: [PATCH] [vmm] bugfix increase_heap: augmente le dernier slab libre si possible. ref #173 --- kernel/memory.c | 28 ++++++++++++++++------------ kernel/vmm.c | 15 +++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/kernel/memory.c b/kernel/memory.c index 1c32fd59..5b066899 100644 --- a/kernel/memory.c +++ b/kernel/memory.c @@ -197,19 +197,23 @@ void memory_setup(size_t ram_size) { paddr_t memory_reserve_page_frame() { struct physical_page_descr *p = free_frame_pages; - - // pop it from free page stack - free_frame_pages = free_frame_pages->next; - if(free_frame_pages != NULL) - free_frame_pages->prev = NULL; - - // put the new reserved on used page stack - used_frame_pages->prev = p; - p->next = used_frame_pages; - used_frame_pages = p; - p->prev = NULL; - return p->addr; + if (p != NULL) { + // pop it from free page stack + free_frame_pages = free_frame_pages->next; + if(free_frame_pages != NULL) + free_frame_pages->prev = NULL; + + // put the new reserved on used page stack + used_frame_pages->prev = p; + p->next = used_frame_pages; + used_frame_pages = p; + p->prev = NULL; + + return p->addr; + } else { + return 0; + } } int memory_free_page_frame(paddr_t addr) diff --git a/kernel/vmm.c b/kernel/vmm.c index 323152fb..4a82b580 100644 --- a/kernel/vmm.c +++ b/kernel/vmm.c @@ -254,20 +254,15 @@ static int increase_heap(struct virtual_mem *vm, unsigned int nb_pages, int u_s) /* vaddr_t top_last_slab; unused */ struct slab *slab = (struct slab *) vm->vmm_top; - for(i=0 ; ivmm_top, u_s) == -1) + for (i = 0; i < nb_pages; i++){ + paddr_t paddr = memory_reserve_page_frame(); + if(!paddr || map(paddr, vm->vmm_top, u_s) == -1) return -1; vm->vmm_top += PAGE_SIZE; } - /* Il semble que si on calcul cette ligne à cet endroit, et que on a !is_empty(&(vm->free_slabs)), ça plante, alors - * je commente et j'insert directement la ligne dans le if - * top_last_slab = (vaddr_t) vm->free_slabs.end + vm->free_slabs.end->nb_pages*PAGE_SIZE;*/ - - if(!is_empty(&(vm->free_slabs)) && ((vaddr_t) vm->free_slabs.end + vm->free_slabs.end->nb_pages*PAGE_SIZE) == vm->vmm_top) + // S'il y a un free slab et que la fin correspond à la fin du heap: + if(!is_empty(&(vm->free_slabs)) && ((vaddr_t) vm->free_slabs.end + vm->free_slabs.end->nb_pages*PAGE_SIZE) == (vaddr_t)slab) { // agrandit juste le dernier free slab vm->free_slabs.end->nb_pages += nb_pages;