Skip to content

jasongiotis/xv6-riscv-COW

 
 

Repository files navigation

COPY ON WRITE ON MIT XV6


official lab page : https://pdos.csail.mit.edu/6.S081/2020/labs/cow.html

Main Problem


The fork() system call in xv6 copies all of the parent process's user-space memory into the child. If the parent is large, copying can take a long time. Worse, the work is often largely wasted; for example, a fork() followed by exec() in the child will cause the child to discard the copied memory, probably without ever using most of it. On the other hand, if both parent and child use a page, and one or both writes it, a copy is truly needed.

Project Objectives


The goal of copy-on-write (COW) fork() is to defer allocating and copying physical memory pages for the child until the copies are actually needed, if ever. COW fork() creates just a pagetable for the child, with PTEs for user memory pointing to the parent's physical pages. COW fork() marks all the user PTEs in both parent and child as not writable. When either process tries to write one of these COW pages, the CPU will force a page fault. The kernel page-fault handler detects this case, allocates a page of physical memory for the faulting process, copies the original page into the new page, and modifies the relevant PTE in the faulting process to refer to the new page, this time with the PTE marked writeable. When the page fault handler returns, the user process will be able to write its copy of the page.

COW fork() makes freeing of the physical pages that implement user memory a little trickier. A given physical page may be referred to by multiple processes' page tables, and should be freed only when the last reference disappears.

How to test the project

1) make qemu ( wait for the xv6 kernel to boot)
2) cowtest
3) usertests

Implemented on Ubuntu 20.4

About

Copy on Write implementation at xv6

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 86.3%
  • Python 7.4%
  • Makefile 3.1%
  • Assembly 3.0%
  • Other 0.2%