본문 바로가기
KraftonJungle2기/회고

[WIL] Pintos 4주차 - VM(2) (주간공유)

by SooooooooS 2023. 6. 25.
728x90

1. 일정

 06.19 ~ 06.20

  • Git book 기준 lazy loading 구현 완료
  • Git book 기준 stack growth 구현 완료

 06.21 ~ 06.23

  • Git book 기준 Memory mapping 구현 완료

 06.24 ~ 06.25

  • Git book 기준 Swap In/Out 구현 완료

2. 주요 학습

1. Stack growth 사용 이유

메모리 구조

프로세스가 실행 중인 동안에 함수 호출 깊이가 깊어지거나 큰 지역 변수 등으로 인해 스택의 공간이 부족해질 수 있다.

이 때 필요한 만큼 스택 영역을 '성장'시키는 메커니즘이 필요합니다. 이를 "스택 성장(stack growth)"이라고 합니다. 

2. Pintos 에서 구현된 방식

1. 초기 스택 상태

static bool setup_stack(struct intr_frame *if_) {
	bool success = false;
	void *stack_bottom = (void *)(((uint8_t *)USER_STACK) - PGSIZE);
    
	if(vm_alloc_page(VM_ANON | VM_MARKER_0, stack_bottom, 1)) {
		success = vm_claim_page(stack_bottom);
		if(success) {
			if_->rsp = USER_STACK;
		}
	}
	return success;
}

초기 스택 상태

  • Project 2까지는 스택 = 페이지 1개의 크기만큼 고정된 상태
  • 그러므로 PGSIZE 이하의  사용자 프로그램만 구동 가능
  • VM_MARKER_0 : lazy loading 이 될 필요가 없다. 즉, page fault가 발생하기 전에 load를 한다.

2. stack growth

bool vm_try_handle_fault (struct intr_frame *f UNUSED, void *addr UNUSED, 
	bool user UNUSED, bool write UNUSED, bool not_present UNUSED) {
...
	if (not_present) { //접근하려는 페이지가 물리 메모리에 존재하지 않을 경우
		void *rsp = f->rsp;
		if(!user) {
			rsp = thread_current()->rsp;
		}
		if ((USER_STACK - (1 << 20) <= rsp - 8 && rsp - 8 <= addr && addr <= USER_STACK)){
			vm_stack_growth(addr);
		}
...
}

/* Growing the stack. */
static void
vm_stack_growth (void *addr UNUSED) {
	vm_alloc_page(VM_ANON | VM_MARKER_0, pg_round_down(addr), 1);
}

스택 확장 조건 확인

1️⃣ rsp에서 스택을 확장할 수 있는지 확인

2️⃣ addr이 확장할 수 있는 주소에 존재하는지 확인

 

🗒️ git book 설명 🗒️

x86-64 PUSH 명령어는 스택 포인터를 조정하기 전에 액세스 권한을 확인하므로 스택 포인터 아래 8바이트의 페이지 장애가 발생할  있다.

  • 스택 포인터 아래 8바이트 = rsp - 8
  • X86-64의 PUSH 명려어로 인해 원래 의도와는 다르게 실제 rsp는 rsp-8이 될 수 있다는 것을 의미

스택 확장

  • pg_ground_down() 함수를 사용하여 가장 가까운 페이지의 경계를 주소로 ANON 페이지를 생성하여 스택 확장

3. 회고

1. 최종 결과

pass tests/userprog/args-none
pass tests/userprog/args-single
pass tests/userprog/args-multiple
pass tests/userprog/args-many
pass tests/userprog/args-dbl-space
pass tests/userprog/halt
pass tests/userprog/exit
pass tests/userprog/create-normal
pass tests/userprog/create-empty
pass tests/userprog/create-null
pass tests/userprog/create-bad-ptr
pass tests/userprog/create-long
pass tests/userprog/create-exists
pass tests/userprog/create-bound
pass tests/userprog/open-normal
pass tests/userprog/open-missing
pass tests/userprog/open-boundary
pass tests/userprog/open-empty
pass tests/userprog/open-null
pass tests/userprog/open-bad-ptr
pass tests/userprog/open-twice
pass tests/userprog/close-normal
pass tests/userprog/close-twice
pass tests/userprog/close-bad-fd
pass tests/userprog/read-normal
pass tests/userprog/read-bad-ptr
pass tests/userprog/read-boundary
pass tests/userprog/read-zero
pass tests/userprog/read-stdout
pass tests/userprog/read-bad-fd
pass tests/userprog/write-normal
pass tests/userprog/write-bad-ptr
pass tests/userprog/write-boundary
pass tests/userprog/write-zero
pass tests/userprog/write-stdin
pass tests/userprog/write-bad-fd
pass tests/userprog/fork-once
pass tests/userprog/fork-multiple
pass tests/userprog/fork-recursive
pass tests/userprog/fork-read
pass tests/userprog/fork-close
pass tests/userprog/fork-boundary
pass tests/userprog/exec-once
pass tests/userprog/exec-arg
pass tests/userprog/exec-boundary
pass tests/userprog/exec-missing
pass tests/userprog/exec-bad-ptr
pass tests/userprog/exec-read
pass tests/userprog/wait-simple
pass tests/userprog/wait-twice
pass tests/userprog/wait-killed
pass tests/userprog/wait-bad-pid
pass tests/userprog/multi-recurse
pass tests/userprog/multi-child-fd
pass tests/userprog/rox-simple
pass tests/userprog/rox-child
pass tests/userprog/rox-multichild
pass tests/userprog/bad-read
pass tests/userprog/bad-write
pass tests/userprog/bad-read2
pass tests/userprog/bad-write2
pass tests/userprog/bad-jump
pass tests/userprog/bad-jump2
pass tests/vm/pt-grow-stack
pass tests/vm/pt-grow-bad
pass tests/vm/pt-big-stk-obj
pass tests/vm/pt-bad-addr
pass tests/vm/pt-bad-read
pass tests/vm/pt-write-code
pass tests/vm/pt-write-code2
pass tests/vm/pt-grow-stk-sc
pass tests/vm/page-linear
pass tests/vm/page-parallel
pass tests/vm/page-merge-seq
pass tests/vm/page-merge-par
pass tests/vm/page-merge-stk
pass tests/vm/page-merge-mm
pass tests/vm/page-shuffle
pass tests/vm/mmap-read
pass tests/vm/mmap-close
pass tests/vm/mmap-unmap
pass tests/vm/mmap-overlap
pass tests/vm/mmap-twice
pass tests/vm/mmap-write
pass tests/vm/mmap-ro
pass tests/vm/mmap-exit
pass tests/vm/mmap-shuffle
pass tests/vm/mmap-bad-fd
pass tests/vm/mmap-clean
pass tests/vm/mmap-inherit
pass tests/vm/mmap-misalign
pass tests/vm/mmap-null
pass tests/vm/mmap-over-code
pass tests/vm/mmap-over-data
pass tests/vm/mmap-over-stk
pass tests/vm/mmap-remove
pass tests/vm/mmap-zero
pass tests/vm/mmap-bad-fd2
pass tests/vm/mmap-bad-fd3
pass tests/vm/mmap-zero-len
pass tests/vm/mmap-off
pass tests/vm/mmap-bad-off
pass tests/vm/mmap-kernel
pass tests/vm/lazy-file
pass tests/vm/lazy-anon
pass tests/vm/swap-file
pass tests/vm/swap-anon
FAIL tests/vm/swap-iter
pass tests/vm/swap-fork
pass tests/filesys/base/lg-create
pass tests/filesys/base/lg-full
pass tests/filesys/base/lg-random
pass tests/filesys/base/lg-seq-block
pass tests/filesys/base/lg-seq-random
pass tests/filesys/base/sm-create
pass tests/filesys/base/sm-full
pass tests/filesys/base/sm-random
pass tests/filesys/base/sm-seq-block
pass tests/filesys/base/sm-seq-random
pass tests/filesys/base/syn-read
pass tests/filesys/base/syn-remove
pass tests/filesys/base/syn-write
pass tests/threads/alarm-single
pass tests/threads/alarm-multiple
pass tests/threads/alarm-simultaneous
pass tests/threads/alarm-priority
pass tests/threads/alarm-zero
pass tests/threads/alarm-negative
pass tests/threads/priority-change
pass tests/threads/priority-donate-one
pass tests/threads/priority-donate-multiple
pass tests/threads/priority-donate-multiple2
pass tests/threads/priority-donate-nest
pass tests/threads/priority-donate-sema
pass tests/threads/priority-donate-lower
pass tests/threads/priority-fifo
pass tests/threads/priority-preempt
pass tests/threads/priority-sema
pass tests/threads/priority-condvar
pass tests/threads/priority-donate-chain
FAIL tests/vm/cow/cow-simple
2 of 141 tests failed.

😭 FAIL 

FAIL tests/vm/swap-iter

FAIL tests/vm/cow/cow-simple

 

 🗒️ 이번 주차 후기

👩🏻‍💻 팀원1
  지난 프로젝트보다 방대한 양이라서 힘들었지만,  혼자서 개념도 정리해 보고 팀원들과 소통도 하면서 개념이 어떻게 구현되었는지 알수 있는 시간이었습니다. 하지만 이번 프로젝트가 2주의 기간을 주었음에도 시간적인 여유가 없어서 많은 부분들을 완벽하게 이해하지 못한 점을 아쉽게 느끼고 있습니다.
🧑🏻‍💻 팀원2 
  2주의 기간 동안 정말로 방대한 코드와 방대한 개념을 보면서 팀원들의 도움도 받고 여러 자료를 찾아보면서 공부를 해보고 코드도 짜는 경험을 보내면서 아쉬움도 많이 남았지만 많은 것을 배우는 한 주가 된 거 같습니다. 하지만 시간의 부족으로 전체적인 내용을 정리하지 못한 부분에 대해서 아쉬움이 남았습니다.
🧑🏻‍💻 팀원3
  양이 방대하고 다양한 함수들과 매크로들의 사용을 익히는 데 시간을 많이 사용하여 시작이 늦었던 것 같습니다. 막상 코드를 작성 한 후에도 생각하지 못한 부분에서 발생하는 오류를 해결하는데 팀원들이 도움이 되었던 것 같습니다. 부족한 부분은 틈틈히 시간을 내서 채우고 싶습니다.
728x90