From 1a5c518ee1536db50dccd8766ce78c3790aec059 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 2 Mar 2015 18:21:59 +0100 Subject: More uses of free_some_memory() --- src/kernel/core/paging.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/kernel/core/paging.c') diff --git a/src/kernel/core/paging.c b/src/kernel/core/paging.c index 0b46be1..38e8407 100644 --- a/src/kernel/core/paging.c +++ b/src/kernel/core/paging.c @@ -6,6 +6,7 @@ #include #include #include +#include #define PAGE_OF_ADDR(x) (((size_t)(x) >> PAGE_SHIFT) % N_PAGES_IN_PT) #define PT_OF_ADDR(x) ((size_t)(x) >> (PAGE_SHIFT + PT_SHIFT)) @@ -210,10 +211,17 @@ bool pd_map_page(void* vaddr, uint32_t frame_id, bool rw) { mutex_lock(&pdd->mutex); if (!(pd->page[pt] & PTE_PRESENT)) { - uint32_t new_pt_frame = frame_alloc(1); + + uint32_t new_pt_frame; + int tries = 0; + while ((new_pt_frame = frame_alloc(1)) == 0 && (tries++) < 3) { + mutex_unlock(&pdd->mutex); + free_some_memory(); + mutex_lock(&pdd->mutex); + } if (new_pt_frame == 0) { mutex_unlock(&pdd->mutex); - return false; // OOM + return false; } current_pd->page[pt] = pd->page[pt] = -- cgit v1.2.3