add random page replacement method

This commit is contained in:
ІО-23 Шмуляр Олег 2025-03-07 10:35:51 +02:00
parent 9fd901eaa0
commit 06cd3a04a5
3 changed files with 29 additions and 3 deletions

View File

@ -4,10 +4,10 @@ CCFLAGS = -g -O0 -Iinc/ -I.
main: main.o kernel.o mmu.o process.o random.o
gcc $(CCFLAGS) -o main main.o kernel.o mmu.o process.o random.o
main.o: src/main.c
main.o: src/main.c config.h
gcc $(CCFLAGS) -c -o main.o src/main.c
kernel.o: src/kernel.c
kernel.o: src/kernel.c config.h
gcc $(CCFLAGS) -c -o kernel.o src/kernel.c
mmu.o: src/mmu.c

View File

@ -1 +1,2 @@
#define PHYSICAL_PAGE_AMOUNT 128
#define PHYSICAL_PAGE_AMOUNT 64
#define PAGE_REPLACEMENT_ALGORITHM 1

View File

@ -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
}
}