๊ด€๋ฆฌ ๋ฉ”๋‰ด

๋ง๊ฐ๋กœ๊ทธ

ํฌ๋ž˜ํ”„ํ†ค ์ •๊ธ€ WEEK11 DAY 87 - PintOS Project3 - Memory Mapped Files (mmap) ๋ณธ๋ฌธ

Krafton jungle

ํฌ๋ž˜ํ”„ํ†ค ์ •๊ธ€ WEEK11 DAY 87 - PintOS Project3 - Memory Mapped Files (mmap)

habbn 2024. 4. 3. 01:20
728x90

๐Ÿ“†2024. 04.02

 

Memory Mapped Files๋Š” ํŒŒ์ผ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งคํ•‘ํ•˜๋Š” ํŽ˜์ด์ง€๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 

ํŒŒ์ผ๊ณผ ๋ฉ”๋ชจ๋ฆฌ ๋งคํ•‘์€ System Call์ธ mmap()์„ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง„๋‹ค.

Pintos์—์„œ๋Š” vm/file.c์˜ do_mmap()์„ ์ด์šฉํ•ด์„œ ๋งคํ•‘์„ ์ˆ˜ํ–‰ํ•˜๋Š”๋ฐ, ๊ทธ ์ด์ „์— mmap()์— ์ „๋‹ฌ๋œ ์ธ์ž๋“ค์— ๋Œ€ํ•œ ๊ฒ€์ฆ์ด ๋จผ์ € ์ด๋ฃจ์–ด์ ธ์•ผ ํ•œ๋‹ค.

 

์‹œ์Šคํ…œ ์ฝœ mmap()

1. offset์˜ ๊ฐ’์ด PGSIZE์— ์•Œ๋งž๊ฒŒ align๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ

2. addr์ด NULL์ด๊ฑฐ๋‚˜, addr์ด page-aligned๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ kernel ์˜์—ญ์ธ ๊ฒฝ์šฐ

3. ๋งคํ•‘ํ•˜๋ ค๋Š” ํŽ˜์ด์ง€๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํŽ˜์ด์ง€์™€ ๊ฒน์น  ๋•Œ (=spt์— ์กด์žฌํ•˜๋Š” ํŽ˜์ด์ง€์ผ ๋•Œ)

4. ์ฐพ๋Š” ํŒŒ์ผ์ด ๋””์Šคํฌ์— ์—†๋Š” ๊ฒฝ์šฐ

5. fd๋กœ ์—ด๋ฆฐ ํŒŒ์ผ์˜ ๊ธธ์ด๊ฐ€ 0๋ฐ”์ดํŠธ์ธ ๊ฒฝ์šฐ, length๊ฐ€ 0์ธ ๊ฒฝ์šฐ

6. ์ฝ˜์†” ์ž…์ถœ๋ ฅ๊ณผ ์—ฐ๊ด€๋œ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ๊ฐ’์ธ ๊ฒฝ์šฐ

 

๋งคํ•‘์ด ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์—†๋‹ค. 

์œ„์˜ ๊ฒฝ์šฐ๋ฅผ ์ œ์™ธํ•˜๊ณ , do_mmap()์„ ํ˜ธ์ถœํ•ด์„œ ํŒŒ์ผ๊ณผ ๊ฐ€์ƒ ์ฃผ์†Œ ๊ฐ„์˜ ๋งคํ•‘์„ ์ง„ํ–‰ํ•˜๊ณ , ๋งคํ•‘๋œ ๊ฐ€์ƒ ์ฃผ์†Œ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

void *mmap (void *addr, size_t length, int writable, int fd, off_t offset){

	//offset์˜ ๊ฐ’์ด PGSIZE์— ์•Œ๋งž๊ฒŒ aling๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ
	if(offset % PGSIZE != 0)
		return NULL;

	//addr์ด NULL์ด๊ฑฐ๋‚˜, addr์ด page-aligned๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ kernel ์˜์—ญ์ธ ๊ฒฝ์šฐ 
	if(addr == NULL || addr == 0 || addr != pg_round_down(addr) || !is_user_vaddr(addr || !is_user_vaddr(addr + length)))
		return NULL;

	// ๋งคํ•‘ํ•˜๋ ค๋Š” ํŽ˜์ด์ง€๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํŽ˜์ด์ง€์™€ ๊ฒน์น  ๋•Œ(==SPT์— ์กด์žฌํ•˜๋Š” ํŽ˜์ด์ง€์ผ ๋•Œ)
	if(spt_find_page(&thread_current()->spt, addr))
		return NULL;

	//์ฐพ๋Š” ํŒŒ์ผ์ด ๋””์Šคํฌ์— ์—†๋Š” ๊ฒฝ์šฐ
	struct file *target = get_file_from_fd(fd);
	if(target == NULL)	
		return NULL;
	
	//fd๋กœ ์—ด๋ฆฐ ํŒŒ์ผ์˜ ๊ธธ์ด๊ฐ€ 0๋ฐ”์ดํŠธ์ธ ๊ฒฝ์šฐ, length๊ฐ€ 0์ผ ๋•Œ๋„ ์‹คํŒจ
	if( file_length(target) == 0 || (long long)length <= 0)
		return NULL;
	
	//์ฝ˜์†” ์ž…์ถœ๋ ฅ๊ณผ ์—ฐ๊ด€๋œ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ๊ฐ’์ธ ๊ฒฝ์šฐ
	if(fd == 0 || fd == 1)	
		return NULL;

	return do_mmap(addr, length, writable, target, offset);
}

 

do_mmap()

 

file-backed page๋„ anonymous page์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ lazy loading์„ ์ด์šฉํ•œ๋‹ค.

page๊ฐ€ ์ดˆ๊ธฐํ™”๋  ๋•Œ ํŒŒ์ผ์—์„œ ๋‚ด์šฉ์„ ์ฝ์–ด์˜ฌ ์ˆ˜ ์žˆ๋„๋ก lazy_load_segment์™€ ๋กœ๋”ฉํ•  ๋•Œ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ํŽ˜์ด์ง€์— ์ €์žฅํ•ด๋‘์–ด์•ผ ํ•œ๋‹ค.

 

ํŒŒ์ผ์— ๋Œ€ํ•œ ๋…๋ฆฝ์ ์ธ ์ฐธ์กฐ

์œ ๋‹‰์Šค ๊ทœ์น™์— ๋”ฐ๋ผ ๋งคํ•‘์€ ๋งคํ•‘์„ ํ•ด์ œํ•˜๋Š” munmap์ด ํ˜ธ์ถœ๋˜๊ฑฐ๋‚˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ์œ ํšจํ•˜๋‹ค.( ํŒŒ์ผ์„ ๋‹ซ๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•ด๋„ ๋งคํ•‘์€ ํ•ด์ œ๋˜์ง€ ์•Š๋Š”๋‹ค.)

 

๋™์ผํ•œ ํŒŒ์ผ์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ ํ”„๋กœ์„ธ์Šค์— ์˜ํ•ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋งคํ•‘์ด ์กด์žฌํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž. ์ด๋•Œ ํ•œ ํ”„๋กœ์„ธ์Šค์—์„œ ์ด ํŒŒ์ผ์„ ๋‹ซ๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•˜๋ฉด ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์—์„œ๋„ ์ด ๋งคํ•‘๋œ ์˜์—ญ์— ๋Œ€ํ•œ ์ฐธ์กฐ๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š๊ฒŒ ๋˜์–ด๋ฒ„๋ฆฐ๋‹ค. ๋˜ํ•œ, ํ•œ ๋งคํ•‘์—์„œ ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ๋ณ€๊ฒฝํ•˜๋ฉด ๋‹ค๋ฅธ ๋งคํ•‘์—๋„ ์˜ํ–ฅ์„ ์ฃผ๊ฒŒ ๋œ๋‹ค.

 

๊ทธ๋ž˜์„œ file_reopen ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด ํŒŒ์ผ์— ๋Œ€ํ•œ ์ƒˆ๋กœ์šด fd๋ฅผ ์–ป๊ฒŒ ๋˜์–ด ๋‹ค๋ฅธ ๋งคํ•‘์— ์˜ํ–ฅ์„ ์ฃผ๊ฑฐ๋‚˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๋Š” ๋…๋ฆฝ์ ์ธ ๋งคํ•‘์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

void *
do_mmap (void *addr, size_t length, int writable,
		struct file *file, off_t offset) {
	
	struct file *re_file = file_reopen(file);
	void *start_addr = addr; // ๋งคํ•‘ ์„ฑ๊ณต ์‹œ ํŒŒ์ผ์ด ๋งคํ•‘๋œ ๊ฐ€์ƒ ์ฃผ์†Œ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ

	size_t read_bytes = file_length(re_file) < length ? file_length(re_file) : length;
	size_t zero_bytes = PGSIZE - read_bytes % PGSIZE;

	ASSERT((read_bytes + zero_bytes) % PGSIZE == 0);
	ASSERT(pg_ofs(addr) == 0);	  // upage๊ฐ€ ํŽ˜์ด์ง€ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ
	ASSERT(offset % PGSIZE == 0); // ofs๊ฐ€ ํŽ˜์ด์ง€ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ

	while (read_bytes > 0 || zero_bytes > 0)
	{
		size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE;
		size_t page_zero_bytes = PGSIZE - page_read_bytes;

		struct lazy_load_arg *lazy_load_arg = (struct lazy_load_arg *)malloc(sizeof(struct lazy_load_arg));
		lazy_load_arg->file = re_file;
		lazy_load_arg->ofs = offset;
		lazy_load_arg->read_bytes = page_read_bytes;
		lazy_load_arg->zero_bytes = page_zero_bytes;

		// vm_alloc_page_with_initializer๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋Œ€๊ธฐ ์ค‘์ธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
		if (!vm_alloc_page_with_initializer(VM_FILE, addr,
											writable, lazy_load_segment, lazy_load_arg))
			return NULL;

		read_bytes -= page_read_bytes;
		zero_bytes -= page_zero_bytes;
		addr += PGSIZE;
		offset += page_read_bytes;
	}

	return start_addr;
}

 

 

๐Ÿšซ์—๋Ÿฌ ๋‚ฌ๋˜ ์ 

struct file *re_file = file_reopen(file);
			:
lazy_load_arg->file = re_file;
			:

 

file_reopen(file)์„ ํ†ตํ•ด ์ƒˆ๋กœ ์–ป์€ fd๋ฅผ lazy_load_arg์˜ file๋กœ ๋„˜๊ฒผ์–ด์•ผ ํ–ˆ๋Š”๋ฐ ์ธ์ž๋กœ ๋ฐ›์•„๋“ค์ธ file์„ ๋„˜๊ฒผ์–ด์„œ ์ž๊พธ do_mmap()์—์„œ ๋๋‚˜์ง€ ์•Š๋Š” ์—๋Ÿฌ๊ฐ€ ๋‚ฌ์—ˆ๋‹ค. 

๊ผญ๊ผญ!! ์ƒˆ๋กœ ์–ป์€ fd์ธ re_file์„ ์ธ์ž๋กœ ์ €์žฅํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ž€๋‹ค!!

 

 

์ด ์ดํ›„๋กœ do_munmap()์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ๊ณ„์†ํ•ด์„œ ๋ฐœ์ƒํ–ˆ๋‹ค. ์• ๋ฅผ ์“ฐ๋‹ค๊ฐ€ ๊ทธ ์ด์œ ์— ๋Œ€ํ•ด ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค.

 

1. file_page ๊ตฌ์กฐ์ฒด ๋ฌธ์ œ

struct file_page {
	// struct file *file;
	// off_t ofs;
	// uint32_t read_bytes;
	// uint32_t zero_bytes;
	void* aux;
};

 

์ฃผ์„ ์ฒ˜๋ฆฌ๋œ ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ file_page์˜ ๋ณด์กฐ ๋ฐ์ดํ„ฐ๋“ค์„ ์ €์žฅํ•ด๋’€๋Š”๋ฐ file ๊ตฌ์กฐ์ฒด ์•ˆ์— file์„ ์„ ์–ธํ•ด๋‘๋ฉด ์•ˆ๋œ๋‹ค๋Š” ๋™๋ฃŒ๋ถ„์ด file_page->aux๋กœ ์ ‘๊ทผํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ•ด์„œ ์ˆ˜์ •ํ–ˆ๋‹ค.

์ •ํ™•ํ•œ ์ด์œ ๋Š” ์•„์ง ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค ใ…œ

 

๊ทธ๋ž˜์„œ ๊ด€๋ จ๋œ ์ฝ”๋“œ์— ๋Œ€ํ•ด ์ „๋ถ€ ์ˆ˜์ •ํ•ด์ฃผ์—ˆ๋‹ค.

 

file_backed_initalizer()

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;
    file_page->aux = page->uninit.aux;

    // struct lazy_load_arg *lazy_load_arg = (struct lazy_load_arg *)page->uninit.aux;
    // file_page->file = lazy_load_arg->file;
    // file_page->ofs = lazy_load_arg->ofs;
    // file_page->read_bytes = lazy_load_arg->read_bytes;
    // file_page->zero_bytes = lazy_load_arg->zero_bytes;
    return true;

 

file_page ๊ตฌ์กฐ์ฒด์˜ ํฌ์ธํ„ฐ๋ฅผ page->file๋กœ ์ดˆ๊ธฐํ™”ํ•˜๊ณ , ํŽ˜์ด์ง€์— ์—ฐ๊ด€๋œ ๋ณด์กฐ ๋ฐ์ดํ„ฐ๋“ค์„ file_page->aux์— ํ• ๋‹นํ•œ๋‹ค. 

 

file_backed_destroy

file-backed ํŽ˜์ด์ง€๋Š” ๋””์Šคํฌ์— ์กด์žฌํ•˜๋Š” ํŒŒ์ผ๊ณผ ์—ฐ๊ด€๋œ ํŽ˜์ด์ง€๋‹ค. ๊ทธ๋ž˜์„œ ๋งŒ์•ฝ ํ•ด๋‹น ํŽ˜์ด์ง€์˜ ์ˆ˜์ •์‚ฌํ•ญ์ด ์žˆ์„ ๊ฒฝ์šฐ ์ด๋ฅผ ๊ฐ์ง€ํ•˜์—ฌ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋””์Šคํฌ์˜ ํŒŒ์ผ์— ์จ์ค˜์•ผ ํ•œ๋‹ค.

 

1. ํ•ด๋‹น ํŽ˜์ด์ง€๊ฐ€ ๋ณ€๊ฒฝ๋˜์–ด ์žˆ์„ ๊ฒฝ์šฐ ๋””์Šคํฌ์— ์กด์žฌํ•˜๋Š” file์— write ํ•ด์ฃผ๊ณ  dirty-bit๋ฅผ ๋‹ค์‹œ 0์œผ๋กœ ๋ณ€๊ฒฝ์‹œ์ผœ์ค€๋‹ค.

2. ๋งŒ์•ฝ ๋ณ€๊ฒฝ์ด ๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด ํ•ด๋‹น ํŽ˜์ด์ง€๋ฅผ pml4์—์„œ ์‚ญ์ œ ํ•ด์ค€๋‹ค.

static void
file_backed_destroy (struct page *page) {
	struct file_page *file_page UNUSED = &page->file;
	struct lazy_load_arg *file_aux = (struct lazy_load_arg *)file_page->aux;
	struct thread *t = thread_current();

	if(pml4_is_dirty(t->pml4, page->va)){			
		file_write_at(file_aux->file, page->va, file_aux->read_bytes, file_aux->ofs);
		pml4_set_dirty(t->pml4, page->va, 0);
	}
	pml4_clear_page(t->pml4, page->va);
    
      // if (pml4_is_dirty(thread_current()->pml4, page->va))
      // {
      //     file_write_at(file_page->file, page->va, file_page->read_bytes, file_page->ofs);
      //     pml4_set_dirty(thread_current()->pml4, page->va, 0);
      // }
      // pml4_clear_page(thread_current()->pml4, page->va);
}
}

 

 

do_munmap()

์—ฐ๊ฒฐ๋œ ๋ฌผ๋ฆฌํ”„๋ ˆ์ž„๊ณผ์˜ ์—ฐ๊ฒฐ์„ ๋Š์–ด์ค˜์•ผ ํ•œ๋‹ค.

์šฐ์„  ์ฃผ์–ด์ง„ addr์„ ํ†ตํ•ด์„œ spt๋กœ๋ถ€ํ„ฐ page๋ฅผ ํ•˜๋‚˜ ์ฐพ๊ณ , ํ•ด๋‹น ํŽ˜์ด์ง€์˜ ๋ณด์กฐ ๋ฐ์ดํ„ฐ๋“ค์„ page->file.aux์— ํ• ๋‹นํ•œ ํ›„์—  file_backed_destroy()ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ํŒŒ์ผ์˜ ์ˆ˜์ •์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•˜๊ณ  ๊ฐ€์ƒ ํŽ˜์ด์ง€ ๋ชฉ๋ก์—์„œ ํŽ˜์ด์ง€๋ฅผ ์ œ๊ฑฐํ•˜๋„๋ก ํ•œ๋‹ค.

void
do_munmap (void *addr) {

	while(true){
		struct thread *curr = thread_current();
		struct page *find_page = spt_find_page(&curr->spt, addr);
		
		if (find_page == NULL) {
    		return NULL;
    	}

		struct lazy_load_arg* container = (struct lazy_load_arg*)find_page->uninit.aux;
		find_page->file.aux = container;

		file_backed_destroy(find_page);
		addr += PGSIZE;
	}
}

 

 

supplemental_page_table_copy()

์ž์‹ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค์˜ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ๋ฅผ ์ƒ์†ํ•˜๋Š” ๊ณผ์ •์—์„œ spt๋ฅผ ๋ณต์‚ฌํ•  ๋•Œ, file_backed_page๋Š” ์ž์‹ ํŽ˜์ด์ง€๊ฐ€ ๋ถ€๋ชจ์˜ ํ”„๋ ˆ์ž„๊ณผ ๋งคํ•‘๋˜๋„๋ก ๋ถ„๊ธฐ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

bool supplemental_page_table_copy(struct supplemental_page_table *dst UNUSED,
								  struct supplemental_page_table *src UNUSED)
{

	struct hash_iterator i;
	hash_first(&i, &src->hash_table);

	while (hash_next(&i))
	{
		struct page *src_page = hash_entry(hash_cur(&i), struct page, hash_elem);

		enum vm_type vm_type = src_page->operations->type;
		void *va = src_page->va;
		bool writable = src_page->writable;

		/* 1) type์ด uninit์ด๋ฉด */
		if (vm_type == VM_UNINIT)
		{ // uninit page ์ƒ์„ฑ & ์ดˆ๊ธฐํ™”
			vm_initializer *init = src_page->uninit.init;
			void *aux = src_page->uninit.aux;
			vm_alloc_page_with_initializer(VM_ANON, va, writable, init, aux);
			continue;
		}

		// if(vm_type == VM_FILE)
		// {
		// 	//ํŒŒ์ผ ๋กœ๋”ฉ์— ํ•„์š”ํ•œ ์ •๋ณด ์ €์žฅ
		// 	struct lazy_load_arg *file_aux =(struct lazy_load_arg *)malloc(sizeof(struct lazy_load_arg));
		// 	file_aux->file = src_page->file.file;
		// 	file_aux->ofs = src_page->file.ofs;
		// 	file_aux->read_bytes = src_page->file.read_bytes;
		// 	file_aux->zero_bytes = src_page->file.zero_bytes;

		// 	//file_aux ๊ตฌ์กฐ์ฒด๋ฅผ ์ธ์ž๋กœ ์ „๋‹ฌํ•˜์—ฌ VM_FILE page ์ƒ์„ฑ & ์ดˆ๊ธฐํ™”
	 	// 	if(!vm_alloc_page_with_initializer(vm_type, va, writable, NULL, file_aux))
		// 		return false;

		// 	//์ƒ์„ฑ๋œ ํŽ˜์ด์ง€ ๊ฐ€์ ธ์˜จ๋‹ค.
		// 	struct page *file_page = spt_find_page(dst, va);
		// 	//ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์™€ ํŽ˜์ด์ง€๋ฅผ ์ฑ„์šด๋‹ค.
		// 	file_backed_initializer(file_page, vm_type, va);

		// 	//์ƒ์„ฑ๋œ ํŽ˜์ด์ง€์˜ ํ”„๋ ˆ์ž„์„ ์›๋ณธ ํŽ˜์ด์ง€์˜ ํ”„๋ ˆ์ž„์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
		// 	file_page->frame = src_page->frame;

		// 	//ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”์— ํŽ˜์ด์ง€ ๋งคํ•‘
		// 	pml4_set_page(thread_current()->pml4, file_page->va, src_page->frame->kva, src_page->writable);
		// 	continue;
		// }
		else{

			/* 2) type์ด uninit์ด ์•„๋‹ˆ๋ฉด */
			if (!vm_alloc_page(vm_type, va, writable)) // uninit page ์ƒ์„ฑ & ์ดˆ๊ธฐํ™”
				// init์ด๋ž‘ aux๋Š” Lazy Loading์— ํ•„์š”ํ•จ
				// ์ง€๊ธˆ ๋งŒ๋“œ๋Š” ํŽ˜์ด์ง€๋Š” ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๋„ฃ์–ด์ค„ ๊ฒƒ์ด๋ฏ€๋กœ ํ•„์š” ์—†์Œ
				return false;

			// vm_claim_page์œผ๋กœ ์š”์ฒญํ•ด์„œ ๋งคํ•‘ & ํŽ˜์ด์ง€ ํƒ€์ž…์— ๋งž๊ฒŒ ์ดˆ๊ธฐํ™”
			if (!vm_claim_page(va))
				return false;

			// ๋งคํ•‘๋œ ํ”„๋ ˆ์ž„์— ๋‚ด์šฉ ๋กœ๋”ฉ
			struct page *dst_page = spt_find_page(dst, va);
			memcpy(dst_page->frame->kva, src_page->frame->kva, PGSIZE);
		}
		
	}
	return true;
}

 

 

 

728x90