Compare commits
3 Commits
vm/merged/
...
bad-synch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0084d12fb1 | ||
|
|
6943c77630 | ||
|
|
d389c15828 |
@@ -6,6 +6,7 @@
|
||||
#include "threads/init.h"
|
||||
#include "threads/pte.h"
|
||||
#include "threads/palloc.h"
|
||||
#include "threads/synch.h"
|
||||
#include "vm/frame.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
@@ -35,6 +36,7 @@ pagedir_destroy (uint32_t *pd)
|
||||
return;
|
||||
|
||||
ASSERT (pd != init_page_dir);
|
||||
lock_acquire (&lru_lock);
|
||||
for (pde = pd; pde < pd + pd_no (PHYS_BASE); pde++)
|
||||
if (*pde & PTE_P)
|
||||
{
|
||||
@@ -53,6 +55,7 @@ pagedir_destroy (uint32_t *pd)
|
||||
palloc_free_page (pt);
|
||||
}
|
||||
palloc_free_page (pd);
|
||||
lock_release (&lru_lock);
|
||||
}
|
||||
|
||||
/* Returns the address of the page table entry for virtual
|
||||
|
||||
@@ -28,9 +28,6 @@ struct list lru_list;
|
||||
victim. Otherwise, the next element in the queue is similarly considered. */
|
||||
struct list_elem *next_victim = NULL;
|
||||
|
||||
/* Synchronisation variables. */
|
||||
/* Protects access to 'lru_list'. */
|
||||
struct lock lru_lock;
|
||||
|
||||
struct frame_metadata
|
||||
{
|
||||
@@ -175,23 +172,29 @@ frame_alloc (enum palloc_flags flags, void *upage, struct thread *owner)
|
||||
void
|
||||
frame_pin (void *frame)
|
||||
{
|
||||
ASSERT (frame != NULL);
|
||||
lock_acquire (&lru_lock);
|
||||
struct frame_metadata *frame_metadata = frame_metadata_get (frame);
|
||||
if (frame_metadata == NULL)
|
||||
PANIC ("Attempted to pin a frame at an unallocated kernel address '%p'\n",
|
||||
frame);
|
||||
|
||||
frame_metadata->pinned = true;
|
||||
lock_release (&lru_lock);
|
||||
}
|
||||
|
||||
void
|
||||
frame_unpin (void *frame)
|
||||
{
|
||||
ASSERT (frame != NULL);
|
||||
lock_acquire (&lru_lock);
|
||||
struct frame_metadata *frame_metadata = frame_metadata_get (frame);
|
||||
if (frame_metadata == NULL)
|
||||
PANIC ("Attempted to unpin a frame at an unallocated kernel address '%p'\n",
|
||||
frame);
|
||||
|
||||
frame_metadata->pinned = false;
|
||||
lock_release (&lru_lock);
|
||||
}
|
||||
|
||||
/* Attempt to deallocate a frame for a user process by removing it from the
|
||||
@@ -206,8 +209,13 @@ frame_free (void *frame)
|
||||
"but this address is not allocated!\n",
|
||||
frame);
|
||||
|
||||
bool lock_held = lock_held_by_current_thread (&lru_lock);
|
||||
|
||||
free_owners (&frame_metadata->owners);
|
||||
|
||||
if (!lock_held)
|
||||
lock_acquire (&lru_lock);
|
||||
|
||||
hash_delete (&frame_table, &frame_metadata->hash_elem);
|
||||
list_remove (&frame_metadata->list_elem);
|
||||
|
||||
@@ -221,6 +229,8 @@ frame_free (void *frame)
|
||||
else
|
||||
next_victim = lru_next (next_victim);
|
||||
}
|
||||
|
||||
if (!lock_held)
|
||||
lock_release (&lru_lock);
|
||||
|
||||
free (frame_metadata);
|
||||
@@ -372,7 +382,6 @@ frame_metadata_get (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);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,11 @@ struct frame_owner
|
||||
struct list_elem elem; /* List element for the list of owners. */
|
||||
};
|
||||
|
||||
/* Synchronisation variables. */
|
||||
/* Protects access to 'lru_list'. */
|
||||
struct lock lru_lock;
|
||||
void frame_init (void);
|
||||
|
||||
void *frame_alloc (enum palloc_flags, void *, struct thread *);
|
||||
void frame_pin (void *frame);
|
||||
void frame_unpin (void *frame);
|
||||
|
||||
@@ -183,7 +183,6 @@ page_load_file (struct page_entry *page)
|
||||
panics as this should not happen if eviction is working correctly. */
|
||||
struct thread *t = thread_current ();
|
||||
bool shareable = !page->writable && file_compare (page->file, t->exec_file);
|
||||
shareable = false;
|
||||
if (shareable)
|
||||
{
|
||||
lock_acquire (&shared_file_pages_lock);
|
||||
|
||||
Reference in New Issue
Block a user