Compare commits
4 Commits
vm/virtual
...
vm/virtual
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96b350d623 | ||
|
|
31403ac7cb | ||
|
|
8220b931a9 | ||
|
|
a34bbbed08 |
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user