add random page replacement method
This commit is contained in:
25
src/kernel.c
25
src/kernel.c
@@ -5,6 +5,7 @@
|
||||
#include "kernel.h"
|
||||
#include "process.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
extern struct RunQ *runq;
|
||||
|
||||
@@ -87,5 +88,29 @@ KERNEL_page_fault(struct PageTableEntry *pt, size_t page_no)
|
||||
this_page->prev->next = this_page;
|
||||
this_page->next->prev = this_page;
|
||||
}
|
||||
} else {
|
||||
printf("[kernel:page_fault] No free pages available, trying to swap...\n");
|
||||
|
||||
#if PAGE_REPLACEMENT_ALGORITHM == 1
|
||||
printf("[kernel:page_fault:random] Selected physical page #%d for replacement\n", first_busy_page->ppn);
|
||||
|
||||
// clear presence 'bit' from old PTE
|
||||
first_busy_page->pt[first_busy_page->pt_index].p = 0;
|
||||
|
||||
// update physical page data
|
||||
first_busy_page->pt = pt;
|
||||
first_busy_page->pt_index = page_no;
|
||||
|
||||
// update PTE data
|
||||
pt[page_no].p = 1;
|
||||
pt[page_no].ppn = first_busy_page->ppn;
|
||||
|
||||
// move hand to next physical page
|
||||
first_busy_page = first_busy_page->next;
|
||||
|
||||
printf("[kernel:page_fault:random] Auto-advanced the list of busy pages to ppn %d\n", first_busy_page->ppn);
|
||||
#elif PAGE_REPLACEMENT_ALGORITHM == 2
|
||||
printf("[kernel:page_fault:wsclock] Not implemented\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user