Merge remote-tracking branch 'origin/vm/page-swap-synch' into vm/virtual-memory/saleh

# Conflicts:
#	.gitlab-ci.yml
#	src/Makefile.build
#	src/threads/thread.c
#	src/userprog/exception.c
#	src/userprog/process.c
#	src/vm/frame.c
#	src/vm/page.c
#	src/vm/page.h
#	src/vm/stackgrowth.c
#	src/vm/stackgrowth.h
This commit is contained in:
sBubshait
2024-12-05 02:21:53 +00:00
11 changed files with 222 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
#include "userprog/exception.h"
#include <inttypes.h>
#include <stdio.h>
#include "stdbool.h"
#include "userprog/gdt.h"
#include "userprog/pagedir.h"
#include "userprog/process.h"
@@ -8,11 +9,13 @@
#include "threads/palloc.h"
#include "threads/thread.h"
#include "threads/vaddr.h"
#include "vm/frame.h"
#include "vm/page.h"
#include "devices/swap.h"
#include "userprog/pagedir.h"
#define MAX_STACK_SIZE (8 * 1024 * 1024) // 8MB
#define MAX_STACK_OFFSET 32 // 32 bytes offset below stack pointer (ESP)
/* Number of page faults processed. */
static long long page_fault_cnt;
@@ -164,9 +167,24 @@ page_fault (struct intr_frame *f)
be just that the stack needs to grow or that it needs to be lazily loaded.
So we attempt to grow the stack. If this does not work, we check our SPT to
see if the page is expected to have data loaded in memory. */
struct thread *t = thread_current ();
void *upage = pg_round_down (fault_addr);
if (not_present && is_user_vaddr (upage) && upage != NULL)
{
/* Check if the non-present user page is in the swap partition.
If so, swap it back into main memory, updating the PTE for
the faulted virtual address to point to the newly allocated
frame. */
if (page_in_swap (t, fault_addr))
{
size_t swap_slot = page_get_swap (t, fault_addr);
void *kpage = frame_alloc (0, upage, t);
swap_in (kpage, swap_slot);
bool writeable = pagedir_is_writable (t->pagedir, upage);
if (pagedir_set_page (t->pagedir, upage, kpage, writeable)) return;
}
if (is_valid_stack_access (fault_addr, esp))
if (grow_stack (upage))
return;