联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> C/C++编程C/C++编程

日期:2021-06-15 11:09

Tasks

The goal of this assignment is implement demand-paged virtual memory. The backing store used is a file called SWAP and it can be accessed using the NACHOS OpenFile class.

The main programming tasks of this project are:

?Task 1. Enhance the page fault handler of the given starter code by modifying vm/virtualmemorymanager.cc to incorporate a page replacement policy using the second change algorithm that approximates LRU.

?Task 2. The starter code uses a field "locationOnDisk" for each page table entry defined in machine/translate.h which is the offset of a virtual page stored in SWAP. In practice, the number of bits allocated to a page table entry is limited. This task is to remove this field from machine/translate.h and implement such a functionality in addrspace.h so that each process space maintains a mapping from each virtual page to a SWAP offset. The revised translate.h is included in the released stater code and is called machine/translate.h.TOREPLACE. You will need to modify userprog/addrspace.h and userprog/addrspace.cc in addition to vm/virtualmemorymanager.cc.


Starter Code and Testing

Full project 3 starter code is here. The starter code has already included many functions for you to accomplish Project 3. To learn the execution flow in handling a page fault, three most relevant files are: vm/virtualmemorymanager.cc, userprog/exception.cc, and userprog/addrspace.cc.

When you have the full starter tar file, to compile, type "make" under the main directory "p3-starter". That should go to vm directory to compile Nachos source code, and go to test directory to compile the test c programs. The nachos binary is produced in vm directory.

In test directory, type "../vm/nachos -x testvmfork", you will see the current code works and prints some trace file. You can type "../vm/nachos -x testvmfork > output" to see only the expected output.

You should test your code under various conditions of system load, including one process with an address space larger than physical memory, several concurrently running processes with combined address spaces larger than physical memory, and random process switching (random yielding). The c test programs under this test directory will be used for gradescope.com tests. Some of them are working already. Check the README file under that directory.

The function that needs to be modified for Task 1 is: VirtualMemoryManager::swapPageIn() in vm/virtualmemorymanager.cc. This function loads the desired physical page from SWAP to memory. This physical page corresponds a virtual page that contains the input virtual address being accessed. Your task is to add the second-chance page replacement policy and make sure a dirty page is copied back to the SWAP area.

Click here for Q/A on the starter code and project suggestions.


Report/code submission

For task 1, please submit to Project 3A; for task 2, please submit to Project 3B.

Submission file list for Task 1 (it is expected that your passes all tests under the test directory without revising machine/translate.h)

Submit the following 2 files to Project 3A:

?vm/virtualmemorymanager.cc

?P3_report

In P3_report, describe your system design, which portions of the assignment is completed, and for the ones that are incomplete, what is their current status. When you just submit something that does not work and give no explanations, expect to receive no credit.

Submission file list for Task 2 (it is expected that your code passes all tests under the test directory with revised machine/translate.h after removing field locationOnDisk)

Submit the following 3 files to Project 3B:

?vm/virtualmemorymanager.cc

?userprog/addrspace.cc

?userprog/addrspace.h


Additional Information

In this assignment, we will leverage the following three bits maintained in each page table entry defined in p3-starter/machine/translate.h: valid, dirty, and use bits.

?The valid bit indicates if a page is resident in physical memory or not. If the valid bit in a particular page table entry is set, the MIPS machine assumes that the corresponding virtual page is loaded into physical memory in the physical page frame specified by the physicalPage field. Whenever the program generates an access to that virtual page, the MIPS machine accesses the physical page. If the valid bit is not set, the system generates a page fault exception whenever the program accesses that virtual page. Your exception handler will then find a free physical page frame, read the page in from the backing store SWAP to that physical page frame, update the page table to reflect the new virtual to physical mapping, and restart the program. The MIPS machine will then resume the execution of the program at the instruction that generated the fault. This time the access should go through, since the page has been loaded into physical memory.

?The dirty bit indicates if this page has been modified or not. To find a free frame, your page fault handler may need to eject an in-memory victim page. If the ejected victim page has been modified in the physical memory indicated by the dirty bit in the corresponding page table entry, the page fault handling code must write the page out to the backing store before reading the accessed page into its physical page frame .

?The use bit indicates if this page has been recently accessed. On a page fault, the kernel must decide which page to replace; ideally, it will throw out a page that will not be referenced for a long time, keeping pages in memory those that are soon to be referenced. You are asked to implement the second chance algorithm leveraging this use bit. This bit is set to TRUE every time a user program reads or writes this page. The second chance algorithm follows a clockwise order to find the next victim whose use bit is FALSE. If it sees a page with the use bit value TRUE, it gives this page the second chance to stay, and the use bit of this page should be set as FALSE.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。