diff --git a/labs/cow.html b/labs/cow.html new file mode 100644 index 0000000..c8a0c1d --- /dev/null +++ b/labs/cow.html @@ -0,0 +1,99 @@ +
+Your task is implement copy-on-write fork in the xv6 kernel. You are +done if your modified kernel executes both the cow and usertests +programs successfully. + +
+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 read-only. 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 when the last +reference disappears. + +
+$ cow +simple: fork() failed +$ ++ +The "simple" test allocates more than half of available physical +memory, and then fork()s. The fork fails because there is not enough +free physical memory to give the child a complete copy of the parent. + +
+When you are done, your kernel should be able to run both cow and +usertests. That is: + +
+$ cow +simple: ok +simple: ok +three: zombie! +ok +three: zombie! +ok +three: zombie! +ok +file: ok +ALL COW TESTS PASSED +$ usertests +... +ALL TESTS PASSED +$ ++ +
+It may be useful to have a way to record, for each PTE, whether it is +a COW mapping. You can use the RSW (reserved for software) bits in +the RISC-V PTE for this.