MIT 6.S081 Lab cow
Compulsory exercises
Preparation
- To start the lab, switch to the cow branch:
1 | git fetch |
- OS真不是人写的把😭
Implement copy-on write(hard)
- 当xv6 fork一个子进程时,需要复制父进程的地址空间,这不仅占用了空间,也消耗了时间,你的任务是采用写时复制,fork()时child使用parent的内存空间,即子进程映射到父进程的物理空间上,当进程要写时,触发Page Fault
- 实现COW
- 修改uvmcopy()以在fork()时不分配新page,而映射到父进程
1 | int |
-
修改usertrap()以处理Page Fault
1 | else if ((r_scause() == 15)) { |
-
添加PTE_RSW标志位用于标识是否是cow page
1 |
-
添加cow处理函数
1 | int |
-
修改copyout()
1 | int |
-
添加计数器和锁,并在每次fork是增加计数,在free时只有计数为0时才能真正free
1 | struct spinlock cnt_lock; |
Optional challenge exercises
-
Modify xv6 to support both lazy page allocation and COW.
-
Measure how much your COW implementation reduces the number of bytes xv6 copies and the number of physical pages it allocates. Find and exploit opportunities to further reduce those numbers.
MIT 6.S081 Lab cow