Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 68 additions & 65 deletions pintos/include/vm/vm.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
#ifndef VM_VM_H
#define VM_VM_H
#include <stdbool.h>
#include "threads/palloc.h"

#include "lib/kernel/hash.h"
#include "threads/palloc.h"

enum vm_type {
/* page not initialized */
VM_UNINIT = 0,
/* page not related to the file, aka anonymous page */
VM_ANON = 1,
/* page that realated to the file */
VM_FILE = 2,
/* page that hold the page cache, for project 4 */
VM_PAGE_CACHE = 3,

/* Bit flags to store state */

/* Auxillary bit flag marker for store information. You can add more
* markers, until the value is fit in the int. */
VM_MARKER_0 = (1 << 3),
VM_MARKER_1 = (1 << 4),

/* DO NOT EXCEED THIS VALUE. */
VM_MARKER_END = (1 << 31),
/* page not initialized */
VM_UNINIT = 0,
/* page not related to the file, aka anonymous page */
VM_ANON = 1,
/* page that realated to the file */
VM_FILE = 2,
/* page that hold the page cache, for project 4 */
VM_PAGE_CACHE = 3,

/* Bit flags to store state */

/* Auxillary bit flag marker for store information. You can add more
* markers, until the value is fit in the int. */
VM_MARKER_0 = (1 << 3),
VM_MARKER_1 = (1 << 4),

/* DO NOT EXCEED THIS VALUE. */
VM_MARKER_END = (1 << 31),
};

#include "vm/uninit.h"
#include "vm/anon.h"
#include "vm/file.h"
#include "vm/uninit.h"
#ifdef EFILESYS
#include "filesys/page_cache.h"
#endif
Expand All @@ -42,74 +43,76 @@ struct thread;
* uninit_page, file_page, anon_page, and page cache (project4).
* DO NOT REMOVE/MODIFY PREDEFINED MEMBER OF THIS STRUCTURE. */
struct page {
const struct page_operations *operations;
void *va; /* Address in terms of user space */
struct frame *frame; /* Back reference for frame */

/* Your implementation */
struct hash_elem hash_elem;

/* Per-type data are binded into the union.
* Each function automatically detects the current union */
union {
struct uninit_page uninit;
struct anon_page anon;
struct file_page file;
const struct page_operations* operations;
void* va; /* Address in terms of user space */
struct frame* frame; /* Back reference for frame */

/* Your implementation */
struct hash_elem hash_elem;

bool writable;

/* Per-type data are binded into the union.
* Each function automatically detects the current union */
union {
struct uninit_page uninit;
struct anon_page anon;
struct file_page file;
#ifdef EFILESYS
struct page_cache page_cache;
struct page_cache page_cache;
#endif
};
};
};

/* The representation of "frame" */
struct frame {
void *kva;
struct page *page;
void* kva;
struct page* page;
// 추가 : 리스트 연결을 위한 멤버
struct list_elem frame_elem;
};

/* The function table for page operations.
* This is one way of implementing "interface" in C.
* Put the table of "method" into the struct's member, and
* call it whenever you needed. */
struct page_operations {
bool (*swap_in) (struct page *, void *);
bool (*swap_out) (struct page *);
void (*destroy) (struct page *);
enum vm_type type;
bool (*swap_in)(struct page*, void*);
bool (*swap_out)(struct page*);
void (*destroy)(struct page*);
enum vm_type type;
};

#define swap_in(page, v) (page)->operations->swap_in ((page), v)
#define swap_out(page) (page)->operations->swap_out (page)
#define swap_in(page, v) (page)->operations->swap_in((page), v)
#define swap_out(page) (page)->operations->swap_out(page)
#define destroy(page) \
if ((page)->operations->destroy) (page)->operations->destroy (page)
if ((page)->operations->destroy) (page)->operations->destroy(page)

/* Representation of current process's memory space.
* We don't want to force you to obey any specific design for this struct.
* All designs up to you for this. */
struct supplemental_page_table {
struct hash hash_table;
struct hash hash_table;
};

#include "threads/thread.h"
void supplemental_page_table_init (struct supplemental_page_table *spt);
bool supplemental_page_table_copy (struct supplemental_page_table *dst,
struct supplemental_page_table *src);
void supplemental_page_table_kill (struct supplemental_page_table *spt);
struct page *spt_find_page (struct supplemental_page_table *spt,
void *va);
bool spt_insert_page (struct supplemental_page_table *spt, struct page *page);
void spt_remove_page (struct supplemental_page_table *spt, struct page *page);

void vm_init (void);
bool vm_try_handle_fault (struct intr_frame *f, void *addr, bool user,
bool write, bool not_present);
void supplemental_page_table_init(struct supplemental_page_table* spt);
bool supplemental_page_table_copy(struct supplemental_page_table* dst,
struct supplemental_page_table* src);
void supplemental_page_table_kill(struct supplemental_page_table* spt);
struct page* spt_find_page(struct supplemental_page_table* spt, void* va);
bool spt_insert_page(struct supplemental_page_table* spt, struct page* page);
void spt_remove_page(struct supplemental_page_table* spt, struct page* page);

void vm_init(void);
bool vm_try_handle_fault(struct intr_frame* f, void* addr, bool user, bool write, bool not_present);

#define vm_alloc_page(type, upage, writable) \
vm_alloc_page_with_initializer ((type), (upage), (writable), NULL, NULL)
bool vm_alloc_page_with_initializer (enum vm_type type, void *upage,
bool writable, vm_initializer *init, void *aux);
void vm_dealloc_page (struct page *page);
bool vm_claim_page (void *va);
enum vm_type page_get_type (struct page *page);

#endif /* VM_VM_H */
vm_alloc_page_with_initializer((type), (upage), (writable), NULL, NULL)
bool vm_alloc_page_with_initializer(enum vm_type type, void* upage, bool writable,
vm_initializer* init, void* aux);
void vm_dealloc_page(struct page* page);
bool vm_claim_page(void* va);
enum vm_type page_get_type(struct page* page);

#endif /* VM_VM_H */
51 changes: 20 additions & 31 deletions pintos/vm/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,46 @@

#include "vm/vm.h"

static bool file_backed_swap_in (struct page *page, void *kva);
static bool file_backed_swap_out (struct page *page);
static void file_backed_destroy (struct page *page);
static bool file_backed_swap_in(struct page* page, void* kva);
static bool file_backed_swap_out(struct page* page);
static void file_backed_destroy(struct page* page);

/* DO NOT MODIFY this struct */
static const struct page_operations file_ops = {
.swap_in = file_backed_swap_in,
.swap_out = file_backed_swap_out,
.destroy = file_backed_destroy,
.type = VM_FILE,
.swap_in = file_backed_swap_in,
.swap_out = file_backed_swap_out,
.destroy = file_backed_destroy,
.type = VM_FILE,
};

/* The initializer of file vm */
void
vm_file_init (void) {
}
void vm_file_init(void) {}

/* Initialize the file backed page */
bool
file_backed_initializer (struct page *page, enum vm_type type, void *kva) {
/* Set up the handler */
page->operations = &file_ops;
bool file_backed_initializer(struct page* page, enum vm_type type, void* kva) {
/* Set up the handler */
page->operations = &file_ops;

struct file_page *file_page = &page->file;
struct file_page* file_page = &page->file;
}

/* Swap in the page by read contents from the file. */
static bool
file_backed_swap_in (struct page *page, void *kva) {
struct file_page *file_page UNUSED = &page->file;
static bool file_backed_swap_in(struct page* page, void* kva) {
struct file_page* file_page UNUSED = &page->file;
}

/* Swap out the page by writeback contents to the file. */
static bool
file_backed_swap_out (struct page *page) {
struct file_page *file_page UNUSED = &page->file;
static bool file_backed_swap_out(struct page* page) {
struct file_page* file_page UNUSED = &page->file;
}

/* Destory the file backed page. PAGE will be freed by the caller. */
static void
file_backed_destroy (struct page *page) {
struct file_page *file_page UNUSED = &page->file;
static void file_backed_destroy(struct page* page) {
struct file_page* file_page UNUSED = &page->file;
}

/* Do the mmap */
void *
do_mmap (void *addr, size_t length, int writable,
struct file *file, off_t offset) {
}
void* do_mmap(void* addr, size_t length, int writable, struct file* file, off_t offset) {}

/* Do the munmap */
void
do_munmap (void *addr) {
}
void do_munmap(void* addr) {}
Loading