[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
anon.c File Reference
#include "vm/vm.h"
#include "devices/disk.h"
#include "bitmap.h"
#include "threads/vaddr.h"
Include dependency graph for anon.c:

Functions

static bool anon_swap_in (struct page *page, void *kva)
 
static bool anon_swap_out (struct page *page)
 
static void anon_destroy (struct page *page)
 
void vm_anon_init (void)
 
bool anon_initializer (struct page *page, enum vm_type type, void *kva)
 

Variables

static struct diskswap_disk
 
static const struct page_operations anon_ops
 
struct bitmapswap_table
 
const size_t SECTORS_PER_PAGE = PGSIZE / DISK_SECTOR_SIZE
 

Function Documentation

◆ anon_destroy()

static void anon_destroy ( struct page page)
static
90 {
91 // 물리 메모리(프레임)가 존재하지 않는다면 anon 페이지 지정이 불가하므로 그냥 리턴한다.
92 if(&page->frame != NULL)
93 return;
94 struct anon_page *anon_page = &page->anon;
95}
#define NULL
Definition: stddef.h:4
Definition: anon.h:7
Definition: vm.h:51
struct frame * frame
Definition: vm.h:54
struct anon_page anon
Definition: vm.h:68

◆ anon_initializer()

bool anon_initializer ( struct page page,
enum vm_type  type,
void *  kva 
)
37 {
38 /* Set up the handler */
40
41 struct anon_page *anon_page = &page->anon;
42
43 return true;
44}
static const struct page_operations anon_ops
Definition: anon.c:16
const struct page_operations * operations
Definition: vm.h:52
Here is the caller graph for this function:

◆ anon_swap_in()

static bool anon_swap_in ( struct page page,
void *  kva 
)
static
48 {
49 struct anon_page *anon_page = &page->anon;
50
51 int page_no = anon_page->swap_index;
52
53 if (bitmap_test(swap_table, page_no) == false) {
54 return false;
55 }
56
57 for (int i = 0; i < SECTORS_PER_PAGE; ++i) {
58 disk_read(swap_disk, page_no * SECTORS_PER_PAGE + i, kva + DISK_SECTOR_SIZE * i);
59 }
60 bitmap_set(swap_table, page_no, false);
61 return true;
62}
struct bitmap * swap_table
Definition: anon.c:23
static struct disk * swap_disk
Definition: anon.c:10
const size_t SECTORS_PER_PAGE
Definition: anon.c:24
void bitmap_set(struct bitmap *, size_t idx, bool)
Definition: bitmap.c:132
bool bitmap_test(const struct bitmap *, size_t idx)
Definition: bitmap.c:181
void disk_read(struct disk *d, disk_sector_t sec_no, void *buffer)
Definition: disk.c:211
#define DISK_SECTOR_SIZE
Definition: disk.h:8
int swap_index
Definition: anon.h:8
Here is the call graph for this function:

◆ anon_swap_out()

static bool anon_swap_out ( struct page page)
static
66 {
67 struct anon_page *anon_page = &page->anon;
68
69 int page_no = bitmap_scan(swap_table, 0, 1, false);
70
71 if (page_no == BITMAP_ERROR) {
72 return false;
73 }
74
75 for (int i = 0; i < SECTORS_PER_PAGE; ++i) {
77 }
78 bitmap_set(swap_table, page_no, true);
79
81
82 anon_page->swap_index = page_no;
83 page->frame = NULL;
84
85 return true;
86}
size_t bitmap_scan(const struct bitmap *, size_t start, size_t cnt, bool)
Definition: bitmap.c:271
#define BITMAP_ERROR
Definition: bitmap.h:36
void disk_write(struct disk *d, disk_sector_t sec_no, const void *buffer)
Definition: disk.c:235
void pml4_clear_page(uint64_t *pml4, void *upage)
Definition: mmu.c:258
void * va
Definition: vm.h:53
struct thread * thread_current(void)
Definition: thread.c:301
Here is the call graph for this function:

◆ vm_anon_init()

void vm_anon_init ( void  )
28 {
29 /* TODO: Set up the swap_disk. */
30 swap_disk = disk_get(1, 1);
31 size_t swap_size = disk_size(swap_disk) / SECTORS_PER_PAGE; // 8개의 disk sector
32 swap_table = bitmap_create(swap_size);
33}
struct bitmap * bitmap_create(size_t bit_cnt)
Definition: bitmap.c:73
disk_sector_t disk_size(struct disk *d)
Definition: disk.c:200
struct disk * disk_get(int chan_no, int dev_no)
Definition: disk.c:186
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ anon_ops

const struct page_operations anon_ops
static
Initial value:
= {
.swap_in = anon_swap_in,
.swap_out = anon_swap_out,
.destroy = anon_destroy,
.type = VM_ANON,
}
static void anon_destroy(struct page *page)
Definition: anon.c:90
static bool anon_swap_in(struct page *page, void *kva)
Definition: anon.c:48
static bool anon_swap_out(struct page *page)
Definition: anon.c:66
@ VM_ANON
Definition: vm.h:14

◆ SECTORS_PER_PAGE

const size_t SECTORS_PER_PAGE = PGSIZE / DISK_SECTOR_SIZE

◆ swap_disk

struct disk* swap_disk
static

◆ swap_table

struct bitmap* swap_table