[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
vm.h File Reference
#include <stdbool.h>
#include "threads/palloc.h"
#include <hash.h>
#include "vm/uninit.h"
#include "vm/anon.h"
#include "vm/file.h"
#include "threads/thread.h"
Include dependency graph for vm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  page
 
struct  frame
 
struct  page_operations
 
struct  supplemental_page_table
 

Macros

#define VM_TYPE(type)   ((type) & 7)
 
#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)
 
#define vm_alloc_page(type, upage, writable)    vm_alloc_page_with_initializer ((type), (upage), (writable), NULL, NULL)
 

Enumerations

enum  vm_type {
  VM_UNINIT = 0 , VM_ANON = 1 , VM_FILE = 2 , VM_PAGE_CACHE = 3 ,
  VM_MARKER_0 = (1 << 3) , VM_MARKER_1 = (1 << 4) , VM_MARKER_END = (1 << 31)
}
 

Functions

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 pagespt_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)
 
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)
 

Macro Definition Documentation

◆ destroy

#define destroy (   page)     if ((page)->operations->destroy) (page)->operations->destroy (page)

◆ swap_in

#define swap_in (   page,
 
)    (page)->operations->swap_in ((page), v)

◆ swap_out

#define swap_out (   page)    (page)->operations->swap_out (page)

◆ vm_alloc_page

#define vm_alloc_page (   type,
  upage,
  writable 
)     vm_alloc_page_with_initializer ((type), (upage), (writable), NULL, NULL)

◆ VM_TYPE

#define VM_TYPE (   type)    ((type) & 7)

Enumeration Type Documentation

◆ vm_type

enum vm_type
Enumerator
VM_UNINIT 
VM_ANON 
VM_FILE 
VM_PAGE_CACHE 
VM_MARKER_0 
VM_MARKER_1 
VM_MARKER_END 
8 {
9 /* page not initialized */
10 /* uninit.c */
11 VM_UNINIT = 0,
12 /* page not related to the file, aka anonymous page */
13 /* anon.c */
14 VM_ANON = 1,
15 /* page that realated to the file */
16 /* file.c */
17 VM_FILE = 2,
18 /* page that hold the page cache, for project 4 */
19 /* 프로젝트 4에서 다룰 것 */
20 VM_PAGE_CACHE = 3,
21
22 /* Bit flags to store state */
23
24 /* Auxillary bit flag marker for store information. You can add more
25 * markers, until the value is fit in the int. */
26 VM_MARKER_0 = (1 << 3),
27 VM_MARKER_1 = (1 << 4),
28
29 /* DO NOT EXCEED THIS VALUE. */
30 VM_MARKER_END = (1 << 31),
31};
@ VM_UNINIT
Definition: vm.h:11
@ VM_MARKER_0
Definition: vm.h:26
@ VM_MARKER_END
Definition: vm.h:30
@ VM_PAGE_CACHE
Definition: vm.h:20
@ VM_FILE
Definition: vm.h:17
@ VM_ANON
Definition: vm.h:14
@ VM_MARKER_1
Definition: vm.h:27

Function Documentation

◆ page_get_type()

enum vm_type page_get_type ( struct page page)
43 {
44 int ty = VM_TYPE (page->operations->type);
45 switch (ty) {
46 case VM_UNINIT:
47 return VM_TYPE (page->uninit.type);
48 default:
49 return ty;
50 }
51}
enum vm_type type
Definition: vm.h:103
Definition: vm.h:51
const struct page_operations * operations
Definition: vm.h:52
struct uninit_page uninit
Definition: vm.h:67
enum vm_type type
Definition: uninit.h:15
#define VM_TYPE(type)
Definition: vm.h:43
Here is the caller graph for this function:

◆ spt_find_page()

struct page * spt_find_page ( struct supplemental_page_table spt,
void *  va 
)
Here is the caller graph for this function:

◆ spt_insert_page()

bool spt_insert_page ( struct supplemental_page_table spt,
struct page page 
)

◆ spt_remove_page()

void spt_remove_page ( struct supplemental_page_table spt,
struct page page 
)
163 {
165 return true;
166}
void vm_dealloc_page(struct page *page)
Definition: vm.c:309
Here is the call graph for this function:

◆ supplemental_page_table_copy()

bool supplemental_page_table_copy ( struct supplemental_page_table dst,
struct supplemental_page_table src 
)
Here is the caller graph for this function:

◆ supplemental_page_table_init()

void supplemental_page_table_init ( struct supplemental_page_table spt)
Here is the caller graph for this function:

◆ supplemental_page_table_kill()

void supplemental_page_table_kill ( struct supplemental_page_table spt)
Here is the caller graph for this function:

◆ vm_alloc_page_with_initializer()

bool vm_alloc_page_with_initializer ( enum vm_type  type,
void *  upage,
bool  writable,
vm_initializer init,
void *  aux 
)
76{
77 ASSERT (VM_TYPE(type) != VM_UNINIT) // vm_type은 VM_ANON과 VM_FILE만 가능하다.
78
80
81 /* Check wheter the upage is already occupied or not. */
82 if (spt_find_page (spt, upage) == NULL) {
83 // ↳ upage라는 가상 메모리에 매핑되는 페이지 존재 x -> 새로 만들어야함
84 /* TODO: Create the page, fetch the initialier according to the VM type,
85 * TODO: and then create "uninit" page struct by calling uninit_new. You
86 * TODO: should modify the field after calling the uninit_new.
87 * 페이지를 만들고 vm유형에 따라 이니셜을 가져온 다음 uninit_new를 호출하여 uninit 페이지 구조를 만듦
88 * uninit_new를 호출한 후 필드를 수정해야 함*/
89 /*-------------------------[P3]Anonoymous page---------------------------------*/
90 struct page* pg = calloc(1, sizeof(struct page)); // ! malloc -> calloc
91
92 // 페이지 타입에 따라 initializer가 될 초기화 함수를 매칭해준다.
93 typedef bool (*initializer_by_type)(struct page *, enum vm_type, void *);
94 initializer_by_type initializer = NULL;
95
96 if(VM_TYPE(type) == VM_ANON)
97 initializer = anon_initializer;
98 else if(VM_TYPE(type) == VM_FILE)
99 initializer = file_backed_initializer;
100
101 uninit_new(pg, upage, init, type, aux, initializer); // UNINIT 페이지 생성
102 // ↳ page를 uninit으로 만들어서 spt에 올려두는 과정(실제 type을 올림)
103 // page 구조체의 pg,upage: 주소, init: lazy_load, type: 타입, initializer: 타입에 따른 함수(anon_initializer 또는 file_backed_initializer)
104
105 /* TODO: Insert the page into the spt. */
106 pg->writable = writable;
107 spt_insert_page(spt, pg);
108 return true;
109 /*-------------------------[P3]Anonoymous page---------------------------------*/
110 }
111err:
112 return false;
113}
bool anon_initializer(struct page *page, enum vm_type type, void *kva)
Definition: anon.c:37
#define ASSERT(CONDITION)
Definition: debug.h:30
void * calloc(size_t, size_t) __attribute__((malloc))
Definition: malloc.c:149
#define bool
Definition: stdbool.h:4
#define NULL
Definition: stddef.h:4
bool writable
Definition: vm.h:60
Definition: vm.h:115
struct supplemental_page_table spt
Definition: thread.h:143
struct thread * thread_current(void)
Definition: thread.c:301
void uninit_new(struct page *page, void *va, vm_initializer *init, enum vm_type type, void *aux, bool(*initializer)(struct page *, enum vm_type, void *kva))
static void init(void)
Definition: vga.c:36
bool file_backed_initializer(struct page *page, enum vm_type type, void *kva)
Definition: file.c:26
struct page * spt_find_page(struct supplemental_page_table *spt UNUSED, void *va UNUSED)
Definition: vm.c:117
bool spt_insert_page(struct supplemental_page_table *spt UNUSED, struct page *page UNUSED)
Definition: vm.c:157
vm_type
Definition: vm.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vm_claim_page()

bool vm_claim_page ( void *  va)

◆ vm_dealloc_page()

void vm_dealloc_page ( struct page page)
309 {
310 destroy (page);
311 free (page);
312}
void free(void *)
Definition: malloc.c:202
#define destroy(page)
Definition: vm.h:108
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vm_init()

void vm_init ( void  )
25 {
26 vm_anon_init ();
27 vm_file_init ();
28#ifdef EFILESYS /* For project 4 */
30#endif
32 /* DO NOT MODIFY UPPER LINES. */
33 /* TODO: Your code goes here. */
34 list_init(&frame_table); // frame_table에 대한 초기화
35}
void vm_anon_init(void)
Definition: anon.c:28
void register_inspect_intr(void)
Definition: inspect.c:21
void list_init(struct list *)
Definition: list.c:58
void pagecache_init(void)
Definition: page_cache.c:20
void vm_file_init(void)
Definition: file.c:21
static struct list frame_table
Definition: vm.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vm_try_handle_fault()

bool vm_try_handle_fault ( struct intr_frame f,
void *  addr,
bool  user,
bool  write,
bool  not_present 
)
Here is the caller graph for this function: