Compare commits

...

7 Commits

Author SHA1 Message Date
Saleh Bubshait
ad4eda5385 Merge branch 'vm/syscall-mmap/styling' into 'master'
Refactor page to follow pintos styling for indentation and add spacing for readability

See merge request lab2425_autumn/pintos_22!69
2024-12-06 18:37:18 +00:00
sBubshait
8d1b4c4994 Refactor page to follow pintos styling for indentation and add spacing for readability 2024-12-06 18:36:54 +00:00
Saleh Bubshait
07c0219058 Merge branch 'vm/syscall-mmap/styling' into 'master'
Refactor frame to add spacing and exception for indentation to follow pintos styling

See merge request lab2425_autumn/pintos_22!68
2024-12-06 18:28:39 +00:00
sBubshait
5fbabdcec9 Refactor frame to add spacing and exception for indentation to follow pintos styling 2024-12-06 18:27:50 +00:00
Saleh Bubshait
5e8bdc68e7 Merge branch 'vm/syscall-mmap/styling' into 'master'
Refactor mmap system call code to follow pintos style in indentation

See merge request lab2425_autumn/pintos_22!67
2024-12-06 18:15:47 +00:00
sBubshait
d039b59b7c Refactor mmap system call code to follow pintos style in indentation 2024-12-06 18:14:47 +00:00
Saleh Bubshait
29c0b93711 Merge branch 'vm/pagedir-spt-synch' into 'master'
fix: synchronise threads' SPTs with locks

See merge request lab2425_autumn/pintos_22!66
2024-12-06 17:44:33 +00:00
4 changed files with 36 additions and 29 deletions

View File

@@ -181,11 +181,11 @@ page_fault (struct intr_frame *f)
/* If the page fault occurred in kernel mode, then we intentionally indicate /* If the page fault occurred in kernel mode, then we intentionally indicate
a fault (for get_user() etc). */ a fault (for get_user() etc). */
if (!user) if (!user)
{ {
f->eip = (void *)f->eax; f->eip = (void *)f->eax;
f->eax = 0xffffffff; f->eax = 0xffffffff;
return; return;
} }
/* To implement virtual memory, delete the rest of the function /* To implement virtual memory, delete the rest of the function

View File

@@ -241,6 +241,7 @@ frame_owner_insert (void *frame, struct thread *owner)
struct frame_owner *frame_owner = malloc (sizeof (struct frame_owner)); struct frame_owner *frame_owner = malloc (sizeof (struct frame_owner));
if (frame_owner == NULL) if (frame_owner == NULL)
return false; return false;
frame_owner->owner = owner; frame_owner->owner = owner;
list_push_back (&frame_metadata->owners, &frame_owner->elem); list_push_back (&frame_metadata->owners, &frame_owner->elem);
return true; return true;
@@ -263,6 +264,7 @@ frame_owner_remove (void *frame, struct thread *owner)
{ {
struct frame_owner *frame_owner struct frame_owner *frame_owner
= list_entry (oe, struct frame_owner, elem); = list_entry (oe, struct frame_owner, elem);
oe = list_next (oe); oe = list_next (oe);
if (frame_owner->owner == owner) 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); struct hash_elem *e = hash_find (&frame_table, &key_metadata.hash_elem);
if (e == NULL) if (e == NULL)
return NULL; return NULL;
return hash_entry (e, struct frame_metadata, hash_elem); return hash_entry (e, struct frame_metadata, hash_elem);
} }

View File

@@ -67,26 +67,27 @@ mmap_unmap (struct mmap_entry *mmap)
if necessary. */ if necessary. */
off_t length = file_length (mmap->file); off_t length = file_length (mmap->file);
for (off_t ofs = 0; ofs < length; ofs += PGSIZE) 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); void *upage = mmap->upage + ofs;
file_write_at (mmap->file, upage, page->read_bytes, ofs);
lock_release (&filesys_lock); /* 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. */ /* Close the file and free the mmap entry. */
hash_delete (&thread_current ()->pages, &page->elem);
}
file_close (mmap->file); file_close (mmap->file);
free (mmap); free (mmap);
} }

View File

@@ -195,6 +195,7 @@ page_load_file (struct page_entry *page)
lock_acquire (&shared_file_pages_lock); lock_acquire (&shared_file_pages_lock);
struct shared_file_page *sfp struct shared_file_page *sfp
= shared_file_page_get (page->file, page->upage); = shared_file_page_get (page->file, page->upage);
if (sfp != NULL) if (sfp != NULL)
{ {
/* Frame exists, just install it. */ /* Frame exists, just install it. */
@@ -207,7 +208,8 @@ page_load_file (struct page_entry *page)
} }
frame_owner_insert (sfp->frame, t); frame_owner_insert (sfp->frame, t);
} }
/* Shared page is in swap. Load it. */
/* Otherwise, shared page is in swap. Load it. */
else else
{ {
void *frame = frame_alloc (PAL_USER, page->upage, t); void *frame = frame_alloc (PAL_USER, page->upage, t);
@@ -223,6 +225,7 @@ page_load_file (struct page_entry *page)
return false; return false;
} }
} }
page_flag_shared (t, page->upage, true); page_flag_shared (t, page->upage, true);
if (page->type != PAGE_SHARED) if (page->type != PAGE_SHARED)
{ {
@@ -320,12 +323,12 @@ page_cleanup (struct hash_elem *e, void *aux UNUSED)
/* Flags the provided page table entry as representing a swapped out page. */ /* Flags the provided page table entry as representing a swapped out page. */
void void
page_flag_swap (uint32_t *pte, bool set) page_flag_swap (uint32_t *pte, bool set)
{ {
if (set) if (set)
*pte |= (1 << SWAP_FLAG_BIT); *pte |= (1 << SWAP_FLAG_BIT);
else else
*pte &= ~(1 << SWAP_FLAG_BIT); *pte &= ~(1 << SWAP_FLAG_BIT);
} }
/* Sets the address bits of the page table entry to the provided swap slot /* 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. */ value. To be used for later retrieval of the swap slot when page faulting. */