Starting from:

$34.99

CS3500 Lab 6 - Copy On Write Solution

Motivation
When a process forks a child, all the code, data and stack variables are copied to the child processes address space and the child continues its execution. However, most of the pages remain unaltered (For example, the pages belonging to the code section). Hence, it is better to keep a single copy of pages in physical memory and make both parent and child processes’ virtual addresses point to the same memory. A new copy of the page is deferred until there is a write to the shared page.
Idea
● During fork(), just copy the page tables entries from parent to child.
○ the entries are made to point to the same physical pages and marked as non-writeable in both parent and child pagetables.
● When there is a write by any of the involved processes to the shared page, it causes a
pagefault. In the pagefault handler, a new physical page is allocated to the faulting process and the contents are copied from the original page. The new page is set as writable.
Implementation Details
4. Finally, modify copyout() to use the same scheme as page faults when it encounters a
Things to be taken care of
1. Multiple processes can use the same physical page. Hence, before freeing a page, it needs to be ensured that no other process references the same physical page.
2. When there is a single owner of a COW page, then its cow and non-writeable flags can be reset and it need not obtain a copy of the page.
Consider three processes P1, P2, P3 and P1 > P2 > P3, where Pi > Pj denotes Pi is parent of Pj.
Say P3 performed write on a cow page. It gets a new copy.
Then P1 performs write on the cow page. It gets a new copy.
Now P2 being the single owner, need not make a copy of the page upon write.
Submission details:
1. Implement your solutions in a fresh download of the xv6 source code. Write youranswers in a Latex/Word document, convert it to PDF and name it as YOUR ROLL NO.pdf. This will serve as a report for the assignment.
2. Put your entire solution xv6 folder, and the YOUR ROLL NO.pdf in a common foldernamed YOUR ROLL NO LAB6.
3. Compress the folder YOUR ROLL NO LAB5 into YOUR ROLL NO LAB5.tar.gz andsub-mit the compressed folder.
4. NOTE: Make sure to run make clean, delete any additional manual and the .gitfolder from the xv6 folder before submitting.

More products