xv6 Memory Layout
process의 virtual address space와 physical address space가 mapping 되어 있음
How Physical Memories Initialized in xv6
![](https://velog.velcdn.com/images/jw3418/post/e12a51cb-0021-41d0-9a28-be9c26c7e6df/image.png)
- physical memory 할당은 main 함수의 kinit1, kinit2 함수를 통해 이루어짐
![](https://velog.velcdn.com/images/jw3418/post/9c8343f1-c6d8-4cc2-a910-d24ead3b5b3f/image.png)
- 모든 physical memory가 boot time에 kmem의 free list에 포함됨
- kinit1() sets up for lock-less allocation in the first 4MB
- kinit2() arranges for more memory (until PHYSTOP) to be allocatable (224MB)
- freerange() kfree() with page size unit
- kfree() fills page with 1s, and put it into freelist (page pool)
![](https://velog.velcdn.com/images/jw3418/post/ac302994-d445-4028-a9da-4c31ca5dff47/image.png)
- fork() 함수는 부모와 완전히 동일한 메모리 컨텐츠를 갖는 자식을 생성함
- allockproc()를 통해 kernel stack을 할당
- copyuvm()을 통해 부모의 page table을 복사함
Project 3: Implement Simple mmap()
- mmap() syscall
- Page fault handler
- munmap() syscall
- freemem() syscall