Update frame: When evicting an mmapped file page, write it back to the file if it is dirty
This commit is contained in:
@@ -2,12 +2,13 @@
|
|||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <list.h>
|
#include <list.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
|
#include "filesys/file.h"
|
||||||
#include "threads/malloc.h"
|
#include "threads/malloc.h"
|
||||||
#include "threads/vaddr.h"
|
#include "threads/vaddr.h"
|
||||||
#include "userprog/pagedir.h"
|
#include "userprog/pagedir.h"
|
||||||
|
#include "userprog/syscall.h"
|
||||||
#include "threads/synch.h"
|
#include "threads/synch.h"
|
||||||
|
|
||||||
/* Hash table that maps every active frame's kernel virtual address
|
/* Hash table that maps every active frame's kernel virtual address
|
||||||
@@ -91,9 +92,26 @@ frame_alloc (enum palloc_flags flags, void *upage, struct thread *owner)
|
|||||||
struct frame_metadata *victim = get_victim ();
|
struct frame_metadata *victim = get_victim ();
|
||||||
ASSERT (victim != NULL); /* get_victim () should never return null. */
|
ASSERT (victim != NULL); /* get_victim () should never return null. */
|
||||||
|
|
||||||
/* 2. Swap out victim into disk. */
|
/* 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);
|
page_insert_swapped (victim->upage, victim->frame, victim->owner);
|
||||||
|
|
||||||
|
|
||||||
/* If zero flag is set, zero out the victim page. */
|
/* If zero flag is set, zero out the victim page. */
|
||||||
if (flags & PAL_ZERO)
|
if (flags & PAL_ZERO)
|
||||||
memset (victim->frame, 0, PGSIZE);
|
memset (victim->frame, 0, PGSIZE);
|
||||||
|
|||||||
Reference in New Issue
Block a user