미소를뿌리는감자의 코딩

[Pintos_project3 (20)] file_backed_swap_in/out 본문

정글 일지

[Pintos_project3 (20)] file_backed_swap_in/out

미뿌감 2024. 12. 3. 17:11
728x90

1. 개요

이번엔 file이 swap in/out 되는 과정에 대해서 알아볼 것이다.

file의 경우엔 file이라는 저장 장소가 있으므로 slot을 할당 받거나 반환할 필요가 없다.

 

2. 본문

/* Swap out the page by writeback contents to the file. */
static bool
file_backed_swap_out (struct page *page) {
	/* pseudo 
	 * (dirty 유무 확인)
	 * (true) file에 변경사항 저장. dirty하지 않다고 명시
	 * (false) 바로 swap_out 진행. RAM에서 해당 frame 사용 중이지 않다고 명시.*/
	struct file_page *file_page UNUSED = &page->file;
	if (pml4_is_dirty(thread_current()->pml4, page->va)) { // dirty인지 확인. 더럽다면 file에 적어두고, dirty이지 않다고 명시
		file_write_at(file_page->file, page->va, file_page->page_read_bytes, file_page->offset);
		pml4_set_dirty(thread_current()->pml4, page->va, false);
	}

	//page와 frame 연관관계 끊기
	page->frame->page = NULL;
	page->frame = NULL;
	pml4_clear_page(thread_current()->pml4, page->va);
}

file_backed_swap_out의 경우엔 해당 페이지가 dirty인지 확인 후, 더럽다면 변경된 내용을 파일에 적고, 해당 페이지가 dirty이지 않음을 pml4_set_dirty를 통해 명시해 준다.

 

이후, page와 frame의 연관관계를 끊으면 끝난다.

 

/* 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;

	return lazy_load_segment(page, file_page);
}

file_backed_swap_in은 간단하다.

이전에 선언해 두었던 lazy_load_segment를 통해 PA와 매핑 시켜주면 된다.

 

3. 결과

728x90