Compare commits
11 Commits
vm/merged/
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad4eda5385 | ||
|
|
8d1b4c4994 | ||
|
|
07c0219058 | ||
|
|
5fbabdcec9 | ||
|
|
5e8bdc68e7 | ||
|
|
d039b59b7c | ||
|
|
29c0b93711 | ||
|
77fedd6666
|
|||
|
|
eba8c1ffa8 | ||
|
|
7611090253 | ||
|
|
c68fea5249 |
@@ -736,6 +736,8 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->recent_cpu = recent_cpu;
|
||||
t->priority = t->base_priority;
|
||||
|
||||
lock_init (&t->pages_lock);
|
||||
|
||||
old_level = intr_disable ();
|
||||
list_push_back (&all_list, &t->allelem);
|
||||
intr_set_level (old_level);
|
||||
|
||||
@@ -136,6 +136,7 @@ struct thread
|
||||
struct list_elem elem; /* List element. */
|
||||
|
||||
struct hash pages; /* Table of open user pages. */
|
||||
struct lock pages_lock; /* Lock for the supplementary page table. */
|
||||
|
||||
/* Memory mapped files for user virtual memory. */
|
||||
struct hash mmap_files; /* List of memory mapped files. */
|
||||
|
||||
@@ -181,11 +181,11 @@ page_fault (struct intr_frame *f)
|
||||
/* If the page fault occurred in kernel mode, then we intentionally indicate
|
||||
a fault (for get_user() etc). */
|
||||
if (!user)
|
||||
{
|
||||
f->eip = (void *)f->eax;
|
||||
f->eax = 0xffffffff;
|
||||
return;
|
||||
}
|
||||
{
|
||||
f->eip = (void *)f->eax;
|
||||
f->eax = 0xffffffff;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* To implement virtual memory, delete the rest of the function
|
||||
|
||||
@@ -371,7 +371,9 @@ process_exit (void)
|
||||
hash_destroy (&cur->open_files, fd_cleanup);
|
||||
|
||||
/* Clean up the thread's supplemental page table. */
|
||||
lock_acquire (&cur->pages_lock);
|
||||
hash_destroy (&cur->pages, page_cleanup);
|
||||
lock_release (&cur->pages_lock);
|
||||
|
||||
/* Close the executable file, implicitly allowing it to be written to. */
|
||||
if (cur->exec_file != NULL)
|
||||
|
||||
@@ -241,6 +241,7 @@ frame_owner_insert (void *frame, struct thread *owner)
|
||||
struct frame_owner *frame_owner = malloc (sizeof (struct frame_owner));
|
||||
if (frame_owner == NULL)
|
||||
return false;
|
||||
|
||||
frame_owner->owner = owner;
|
||||
list_push_back (&frame_metadata->owners, &frame_owner->elem);
|
||||
return true;
|
||||
@@ -263,6 +264,7 @@ frame_owner_remove (void *frame, struct thread *owner)
|
||||
{
|
||||
struct frame_owner *frame_owner
|
||||
= list_entry (oe, struct frame_owner, elem);
|
||||
|
||||
oe = list_next (oe);
|
||||
if (frame_owner->owner == owner)
|
||||
{
|
||||
@@ -284,6 +286,7 @@ frame_metadata_find (void *frame)
|
||||
struct hash_elem *e = hash_find (&frame_table, &key_metadata.hash_elem);
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
return hash_entry (e, struct frame_metadata, hash_elem);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,26 +67,27 @@ mmap_unmap (struct mmap_entry *mmap)
|
||||
if necessary. */
|
||||
off_t length = file_length (mmap->file);
|
||||
for (off_t ofs = 0; ofs < length; ofs += PGSIZE)
|
||||
{
|
||||
void *upage = mmap->upage + ofs;
|
||||
|
||||
/* Get the SPT page entry for this page. */
|
||||
struct page_entry *page = page_get(thread_current (), upage);
|
||||
if (page == NULL)
|
||||
continue;
|
||||
|
||||
/* Write the page back to the file if it is dirty. */
|
||||
if (pagedir_is_dirty (thread_current ()->pagedir, upage))
|
||||
{
|
||||
lock_acquire (&filesys_lock);
|
||||
file_write_at (mmap->file, upage, page->read_bytes, ofs);
|
||||
lock_release (&filesys_lock);
|
||||
void *upage = mmap->upage + ofs;
|
||||
|
||||
/* Get the SPT page entry for this page. */
|
||||
struct page_entry *page = page_get(thread_current (), upage);
|
||||
if (page == NULL)
|
||||
continue;
|
||||
|
||||
/* Write the page back to the file if it is dirty. */
|
||||
if (pagedir_is_dirty (thread_current ()->pagedir, upage))
|
||||
{
|
||||
lock_acquire (&filesys_lock);
|
||||
file_write_at (mmap->file, upage, page->read_bytes, ofs);
|
||||
lock_release (&filesys_lock);
|
||||
}
|
||||
|
||||
/* Remove the page from the supplemental page table. */
|
||||
hash_delete (&thread_current ()->pages, &page->elem);
|
||||
}
|
||||
|
||||
/* Remove the page from the supplemental page table. */
|
||||
hash_delete (&thread_current ()->pages, &page->elem);
|
||||
}
|
||||
|
||||
/* Close the file and free the mmap entry. */
|
||||
file_close (mmap->file);
|
||||
free (mmap);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ page_insert_swapped (void *upage, void *kpage, struct list *owners)
|
||||
|
||||
/* 1. Initialize swapped page entry. */
|
||||
struct page_entry *page = page_get (owner, upage);
|
||||
lock_acquire (&owner->pages_lock);
|
||||
if (page == NULL)
|
||||
{
|
||||
page = malloc (sizeof (struct page_entry));
|
||||
@@ -113,6 +114,7 @@ page_insert_swapped (void *upage, void *kpage, struct list *owners)
|
||||
page_set_swap (owner, pte, swap_slot);
|
||||
|
||||
lock_release (&page->lock);
|
||||
lock_release (&owner->pages_lock);
|
||||
}
|
||||
if (exec_file != NULL)
|
||||
{
|
||||
@@ -155,7 +157,10 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
||||
page->writable = writable;
|
||||
lock_init (&page->lock);
|
||||
|
||||
hash_insert (&thread_current ()->pages, &page->elem);
|
||||
struct thread *t = thread_current ();
|
||||
lock_acquire (&t->pages_lock);
|
||||
hash_insert (&t->pages, &page->elem);
|
||||
lock_release (&t->pages_lock);
|
||||
return page;
|
||||
}
|
||||
|
||||
@@ -167,8 +172,10 @@ page_get (struct thread *thread, void *upage)
|
||||
struct page_entry fake_page_entry;
|
||||
fake_page_entry.upage = upage;
|
||||
|
||||
lock_acquire (&thread->pages_lock);
|
||||
struct hash_elem *e
|
||||
= hash_find (&thread->pages, &fake_page_entry.elem);
|
||||
lock_release (&thread->pages_lock);
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -188,6 +195,7 @@ page_load_file (struct page_entry *page)
|
||||
lock_acquire (&shared_file_pages_lock);
|
||||
struct shared_file_page *sfp
|
||||
= shared_file_page_get (page->file, page->upage);
|
||||
|
||||
if (sfp != NULL)
|
||||
{
|
||||
/* Frame exists, just install it. */
|
||||
@@ -200,7 +208,8 @@ page_load_file (struct page_entry *page)
|
||||
}
|
||||
frame_owner_insert (sfp->frame, t);
|
||||
}
|
||||
/* Shared page is in swap. Load it. */
|
||||
|
||||
/* Otherwise, shared page is in swap. Load it. */
|
||||
else
|
||||
{
|
||||
void *frame = frame_alloc (PAL_USER, page->upage, t);
|
||||
@@ -216,6 +225,7 @@ page_load_file (struct page_entry *page)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
page_flag_shared (t, page->upage, true);
|
||||
if (page->type != PAGE_SHARED)
|
||||
{
|
||||
@@ -313,12 +323,12 @@ page_cleanup (struct hash_elem *e, void *aux UNUSED)
|
||||
/* Flags the provided page table entry as representing a swapped out page. */
|
||||
void
|
||||
page_flag_swap (uint32_t *pte, bool set)
|
||||
{
|
||||
if (set)
|
||||
*pte |= (1 << SWAP_FLAG_BIT);
|
||||
else
|
||||
*pte &= ~(1 << SWAP_FLAG_BIT);
|
||||
}
|
||||
{
|
||||
if (set)
|
||||
*pte |= (1 << SWAP_FLAG_BIT);
|
||||
else
|
||||
*pte &= ~(1 << SWAP_FLAG_BIT);
|
||||
}
|
||||
|
||||
/* Sets the address bits of the page table entry to the provided swap slot
|
||||
value. To be used for later retrieval of the swap slot when page faulting. */
|
||||
|
||||
Reference in New Issue
Block a user