Implement a mini virtual memory system simulator.
- 
The framework provides an environment to simulate virtual memory and paging. Your task is to implement the key components of the simulator. 
- 
In the simulator, we may have multiple processes. Likewise PA2, struct processabstracts processes on the system, andstruct process *currentpoints to the currently running process.struct list_head processesis a list of processes on the system.
- 
The framework accepts five main commands, which are read,write,alloc,free, andswitch, and three supplementary commands, which areshow,pages, andexit. Try to enterhelpor?for brief explanation for each command.
- 
allocis to instruct the simulator to simulate a page allocation to the current process. Following shows the cases for the command. Note that this command does not actually allocate a real page nor memory resource, but do simulate the situation for page allocation.>> alloc 10 r # Allocate a page frame for VPN 10 for read >> alloc 20 rw # Allocate a page frame for VPN 20 for read and write >> alloc 0x10 rw # Allocate a page to VPN 0x10 for read and write
- 
The pages allocated with roption are read-only pages. Writes to those pages should be rejected. The pages allocated withrwcan be read and written. This implies that both read and write accesses to those VPNs should be allowed. However, you may presume that no page will be allocated with onlywoption in this assignment (i.e., no need to support write-only pages).
- 
Allocated pages should be mapped to the current process by manipulating the page table of the process. The system maintains 2-level hierarchical page table as defined in vm.h.
- 
mapcounts[]is an array that is supposed to contain the numbers of PTE mappings to each page frame. For example, when a page framexis mapped to three processes,mapcounts[x]should be 3. You may leverage this information to find a free page frame to allocate.
- 
When the system has many free page frames, allocate the page frame that has the smallest page frame number. 
- 
freecommand is to deallocate the page that is mapped to the VPN. The page table should be set so that subsequent accesses to the freed VPN should be denied by MMU. You should consider the case when the target page frame is mapped more than or equal to 2 to properly handlefreecommand with copy-on-write feature.
- 
readandwriteis to instruct the system to simulate the memory access. These commands are followed by VPN (virtual page number). For example;>> read 10 /* Read VPN 10 */ >> write 0x10 /* Write to VPN 0x10 */
- 
Each read and write request will be processed by the framework. Internally, it calls __translate()invm.c, which simulates the address translation in MMU. It walk through the current page table, which is pointed byptbr, to translate VPN to PFN.
- 
When the translation is successful, the framework will print out the translation result, and waits for next commands from the prompt. 
- 
If the given VPN cannot be translated or accessed using the current page table, it will trigger the page fault mechanism in the framework by calling handle_page_fault(). In this page fault handler, your code should inspect the situation causing the page fault, and resolve the fault if it can handle with. To this end, you may modify/allocate/fix up the page table in this function.
- 
You may switch the currently running process with switchcommand. Enter the command followed by the process id to switch to. The framework will callswitch_process()to handle the request. Find the target process from theprocesseslist, and if it exists, do the context switching by replacingcurrentandptbrwith the requested process.
- 
If the target process does not exist, you need to fork a child process from current. This implies you should allocatestruct processfor the child process and initialize it (including page table) accordingly. To duplicate the parent's address space, set up the PTE in the child's page table to map to the same PFN of the parent. You need to set up PTE property bits to support copy-on-write.
- 
showprompt command shows the page table of the current process.pagescommand shows the summary formapcounts[].
- Implement features in an incremental way; implement the allocation/deallocation functions first to get used to the page table/PTE manipulation. And then move on to implement the fork by duplicating the page table contents. You need to manipulate both PTEs of parent and child to support copy-on-write properly.
- Be careful to handle writablebit in the page table when you attach a page or share it. Read-only pages should not be writable after the fork whereas writable pages should be writable after the fork through the copy-on-write mechanism. You can leverage theprivatevariable instruct pteto implement this feature.
- Likewise previous PAs, printing out to stdout does not influence on the grading. So, feel free to print out debug message using printf.
- 
Use PAsubmit for submission - 450 pts + 10 pts
 
- 
Code: pa3.c (350 pts) - Page allocation (50 pts)
- Page deallocation (50 pts)
- Fork (100 pts)
- Copy-on-Write (150 pts)
 
- 
Document: One PDF document (100 pts) including; - Describe how you implement page allocation, deallocation, fork, and copy-on-write.
- Describe your entire journey to complete the assignment. You must clarify why you choose the particular design you use over other alternatives, what is your key idea in implementing those features, explains your failed tries, the analysis on the causes of those failures, and how you resolved them.
- Bad example: To implement page allocation, find xyz by increasing from 0 to 9999. Then increase x by 2. If xx > 0, do something.
- Good example: To implement page allocation, firstly I used abc properties. Since it is xyz, it is kkk if xyz is 99. So, try to find something like plm by iterating the cde list and finds something with xxx. This value is increased by 2 to indicate something for xyz. I thought this should work, but it did not when xyz is 0xdeadbeef. It turned out that xyz is not true but abc is false. So, I modified it ....
- Must include at least one case of your failure, what the problem was, and how you fixed it.
 
- Explain what happens to the page tables while running testcases/cow-2. Show the final page tables for process 0, 1, and 2, and explain why they are like that.
- Lesson learned
- No more than six pages
 
- Describe how you implement page allocation, deallocation, fork, and copy-on-write.
- 
Git repository (10 bonus pts) - Register http/https URL and with a deploy token and password.
- Start the repository by cloning this repository.
- Make sure your repository is private.
- Also, make sure the token is valid through June 15 (due + 3 slip days + 1 day)
 
- 
THE INSTRUCTOR WILL NOT ANSWER THE QUESTIONS ABOUT THOSE ALREADY SPECIFIED ON THE HANDOUT. 
- 
QUESTIONS OVER EMAIL WILL BE IGNORED UNLESS IT CONCERNS YOUR PRIVACY.