diff --git a/src/vm/mmap.c b/src/vm/mmap.c index 64ad28f..4e5a620 100644 --- a/src/vm/mmap.c +++ b/src/vm/mmap.c @@ -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); }