fix: synchronise destruction of page directories with frame table
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "threads/init.h"
|
#include "threads/init.h"
|
||||||
#include "threads/pte.h"
|
#include "threads/pte.h"
|
||||||
#include "threads/palloc.h"
|
#include "threads/palloc.h"
|
||||||
|
#include "threads/synch.h"
|
||||||
#include "vm/frame.h"
|
#include "vm/frame.h"
|
||||||
#include "vm/page.h"
|
#include "vm/page.h"
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ pagedir_destroy (uint32_t *pd)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ASSERT (pd != init_page_dir);
|
ASSERT (pd != init_page_dir);
|
||||||
|
lock_acquire (&lru_lock);
|
||||||
for (pde = pd; pde < pd + pd_no (PHYS_BASE); pde++)
|
for (pde = pd; pde < pd + pd_no (PHYS_BASE); pde++)
|
||||||
if (*pde & PTE_P)
|
if (*pde & PTE_P)
|
||||||
{
|
{
|
||||||
@@ -53,6 +55,7 @@ pagedir_destroy (uint32_t *pd)
|
|||||||
palloc_free_page (pt);
|
palloc_free_page (pt);
|
||||||
}
|
}
|
||||||
palloc_free_page (pd);
|
palloc_free_page (pd);
|
||||||
|
lock_release (&lru_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the address of the page table entry for virtual
|
/* Returns the address of the page table entry for virtual
|
||||||
|
|||||||
@@ -209,8 +209,13 @@ frame_free (void *frame)
|
|||||||
"but this address is not allocated!\n",
|
"but this address is not allocated!\n",
|
||||||
frame);
|
frame);
|
||||||
|
|
||||||
|
bool lock_held = lock_held_by_current_thread (&lru_lock);
|
||||||
|
|
||||||
free_owners (&frame_metadata->owners);
|
free_owners (&frame_metadata->owners);
|
||||||
lock_acquire (&lru_lock);
|
|
||||||
|
if (!lock_held)
|
||||||
|
lock_acquire (&lru_lock);
|
||||||
|
|
||||||
hash_delete (&frame_table, &frame_metadata->hash_elem);
|
hash_delete (&frame_table, &frame_metadata->hash_elem);
|
||||||
list_remove (&frame_metadata->list_elem);
|
list_remove (&frame_metadata->list_elem);
|
||||||
|
|
||||||
@@ -224,7 +229,9 @@ frame_free (void *frame)
|
|||||||
else
|
else
|
||||||
next_victim = lru_next (next_victim);
|
next_victim = lru_next (next_victim);
|
||||||
}
|
}
|
||||||
lock_release (&lru_lock);
|
|
||||||
|
if (!lock_held)
|
||||||
|
lock_release (&lru_lock);
|
||||||
|
|
||||||
free (frame_metadata);
|
free (frame_metadata);
|
||||||
palloc_free_page (frame);
|
palloc_free_page (frame);
|
||||||
|
|||||||
Reference in New Issue
Block a user