feat: implement synchronisation to protecting access to PTEs of SPTs during eviction

This commit is contained in:
Themis Demetriades
2024-12-05 16:51:15 +00:00
parent e779e8ac7c
commit d03e253046
6 changed files with 114 additions and 45 deletions

View File

@@ -9,7 +9,6 @@
#include "threads/vaddr.h"
#include "userprog/pagedir.h"
#include "threads/synch.h"
#include "devices/swap.h"
/* Hash table that maps every active frame's kernel virtual address
to its corresponding 'frame_metadata'.*/
@@ -76,7 +75,7 @@ frame_alloc (enum palloc_flags flags, void *upage, struct thread *owner)
{
struct frame_metadata *frame_metadata;
flags |= PAL_USER;
lock_acquire (&lru_lock);
void *frame = palloc_get_page (flags);
@@ -93,15 +92,7 @@ frame_alloc (enum palloc_flags flags, void *upage, struct thread *owner)
ASSERT (victim != NULL); /* get_victim () should never return null. */
/* 2. Swap out victim into disk. */
/* Mark page as 'not present' and flag the page directory as having
been modified *before* eviction begins to prevent the owner of the
victim page from accessing/modifying it mid-eviction. */
pagedir_clear_page (victim->owner->pagedir, victim->upage);
// TODO: Lock PTE of victim page for victim process.
size_t swap_slot = swap_out (victim->frame);
page_set_swap (victim->owner, victim->upage, swap_slot);
page_insert_swapped (victim->upage, victim->frame, victim->owner);
/* If zero flag is set, zero out the victim page. */
if (flags & PAL_ZERO)