Compare commits

..

4 Commits

Author SHA1 Message Date
Demetriades, Themis
96b350d623 Merge branch 'vm/mmap-write-back-on-eviction' into 'vm/virtual-memory/themis-synch'
Write back mmap file pages to file upon eviction

See merge request lab2425_autumn/pintos_22!59
2024-12-06 01:01:50 +00:00
Themis Demetriades
31403ac7cb fix: obtain correct page table entry when performing eviction 2024-12-06 00:56:03 +00:00
Demetriades, Themis
8220b931a9 Merge branch 'vm/virtual-memory/frame-synch/saleh' into 'vm/virtual-memory/themis-synch'
Merge frame pinning to themis-synch

See merge request lab2425_autumn/pintos_22!60
2024-12-06 00:21:02 +00:00
sBubshait
a34bbbed08 Update frame: When evicting an mmapped file page, write it back to the file if it is dirty 2024-12-05 22:53:48 +00:00
6 changed files with 29 additions and 10 deletions

View File

@@ -252,7 +252,7 @@ fetch_page (void *upage, bool write)
{
/* Check if the page is in the supplemental page table. That is, it is a page
that is expected to be in memory. */
struct page_entry *page = page_get (upage);
struct page_entry *page = page_get (thread_current (), upage);
if (page == NULL)
return false;

View File

@@ -462,7 +462,7 @@ syscall_mmap (int fd, void *addr)
hold the entire file. */
for (off_t ofs = 0; ofs < file_size; ofs += PGSIZE)
{
if (page_get (addr + ofs) != NULL)
if (page_get (thread_current (), addr + ofs) != NULL)
return MMAP_FAILURE;
}

View File

@@ -2,12 +2,13 @@
#include <hash.h>
#include <list.h>
#include <string.h>
#include "frame.h"
#include "page.h"
#include "filesys/file.h"
#include "threads/malloc.h"
#include "threads/vaddr.h"
#include "userprog/pagedir.h"
#include "userprog/syscall.h"
#include "threads/synch.h"
/* Hash table that maps every active frame's kernel virtual address
@@ -94,8 +95,25 @@ frame_alloc (enum palloc_flags flags, void *upage, struct thread *owner)
struct frame_metadata *victim = get_victim ();
ASSERT (victim != NULL); /* get_victim () should never return null. */
/* 2. Swap out victim into disk. */
page_insert_swapped (victim->upage, victim->frame, victim->owner);
/* 2. Handle victim page writing based on its type. */
struct page_entry *victim_page = page_get (victim->upage);
if (victim_page != NULL && victim_page->type == PAGE_MMAP)
{
/* If it was a memory-mapped file page, we just write it back
to the file if it was dirty. */
if (pagedir_is_dirty(owner->pagedir, victim->upage))
{
lock_acquire (&filesys_lock);
file_write_at (victim_page->file, victim->upage,
victim_page->read_bytes, victim_page->offset);
lock_release (&filesys_lock);
}
}
else
/* Otherwise, insert the page into swap. */
page_insert_swapped (victim->upage, victim->frame, victim->owner);
/* If zero flag is set, zero out the victim page. */
if (flags & PAL_ZERO)

View File

@@ -1,5 +1,6 @@
#include "mmap.h"
#include "page.h"
#include "threads/thread.h"
#include "threads/vaddr.h"
#include "threads/malloc.h"
#include "userprog/syscall.h"
@@ -70,7 +71,7 @@ mmap_unmap (struct mmap_entry *mmap)
void *upage = mmap->upage + ofs;
/* Get the SPT page entry for this page. */
struct page_entry *page = page_get(upage);
struct page_entry *page = page_get(thread_current (), upage);
if (page == NULL)
continue;

View File

@@ -47,7 +47,7 @@ struct page_entry *
page_insert_swapped (void *upage, void *kpage, struct thread *owner)
{
/* 1. Initialize swapped page entry. */
struct page_entry *page = page_get (upage);
struct page_entry *page = page_get (thread_current (), upage);
if (page == NULL)
{
page = malloc (sizeof (struct page_entry));
@@ -103,13 +103,13 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
/* Gets a page_entry from the starting address of the page. Returns NULL if no
such page_entry exists in the hash map.*/
struct page_entry *
page_get (void *upage)
page_get (struct thread *thread, void *upage)
{
struct page_entry fake_page_entry;
fake_page_entry.upage = upage;
struct hash_elem *e
= hash_find (&thread_current ()->pages, &fake_page_entry.elem);
= hash_find (&thread->pages, &fake_page_entry.elem);
if (e == NULL)
return NULL;

View File

@@ -37,7 +37,7 @@ struct page_entry *page_insert_swapped (void *upage, void* kpage,
struct page_entry *page_insert_file (struct file *file, off_t ofs, void *upage,
uint32_t read_bytes, uint32_t zero_bytes,
bool writable, enum page_type);
struct page_entry *page_get (void *upage);
struct page_entry *page_get (struct thread *thread, void *upage);
bool page_load_file (struct page_entry *page, bool writable);
void page_cleanup (struct hash_elem *e, void *aux);