Skip to content

Commit

Permalink
[vmm] bugfix increase_heap: augmente le dernier slab libre si
Browse files Browse the repository at this point in the history
possible. ref #173
  • Loading branch information
MaximeCheramy committed Jan 20, 2015
1 parent d273c2d commit 80073d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
28 changes: 16 additions & 12 deletions kernel/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions kernel/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ; i<nb_pages ; i++)
{
if(memory_get_first_free_page() == NULL)
return -1;
if(map(memory_reserve_page_frame(), vm->vmm_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;
Expand Down

0 comments on commit 80073d4

Please sign in to comment.