






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







In this project you are required to implement the "Working Set" scheme and three page- replacement policies in the Nachos operating system as discussed in class (and in your book). You will then use your implementation to collect data describing the performance of these algorithms and answer a number of questions. As in PA2-1 and PA2-2 you may do this assignment in groups of two. To be sure you start with the same Nachos archive as this project description assumes, please grab this assignment's starter code from the website. Again, if you do not start with this TAR file to implement this project, I will not grade your project. You may want to refer back to the Nachos documentation on the website for some details on the memory system in Nachos. The labs this week (Wednesday, April 15 and Friday, April 17) will also cover the memory system in Nachos.
The working set is the set of all virtual pages a process is actively using. To prevent a process from thrashing pages in and out, a record is kept of which pages are accessed during a fixed accounting interval. This access record is then used to calculate page membership in the working set and to determine how many physical pages should be granted to the process. Most systems for implementing a working set involve using a record of N intervals. Page accesses are "remembered" over time by setting bits in a bit field of a given length. As time proceeds, new data is shifted into the most significant bit (MSB) of the field and old data is shifted out periodically. In this way, the length of the bit field in the page table entry directly determines the amount of history it can keep about access to each page. The number of history bits (the number of accounting intervals) is referred to as the "Delta". The history field for a page table entry with a Delta of 8 is shown below. Note that during time periods t1 , t3 , and t7 , the page is accessed. This information is shifted once to the right at the end of each time interval and, by period t9 , the first access is "forgotten".
In this project you will be required to implement simple working set management policies in Nachos as described above. The size ( Delta ) of the page access history bit field will be varied, and you will perform tests to see how different sizes affect performance. Values will be 1, 2, 4, and 8 bits (and thus time periods). You will also be required to implement 3 page replacement (victim selection) algorithms to be used in conjunction with your working set implementation. For this project you will be required to implement FIFO (section 9.4.2 in the text), LRU Approximation (this is the Record Reference Bit algorithm in the slides also known as the Additional-Reference-Bits Algorithm from section 9.5.4.1 in the text), and Enhanced Second Chance (this is similar to the Second Chance algorithm discussed in class – see section 9.4.5.3 in the text for details). Implementation Details To differentiate between the two meanings of "working set" in the rest of this document, we will use the term "actual working set size" for the number of virtual pages a process has used in recent history and the term "prescribed working set size" for the number of physical pages the kernel has determined a process can be using. As will become evident below, both values will change throughout the execution of a process. One way to implement the working set schema is to introduce a bit-field into the page table entry (class TranslationEntry) for each page of a processes' virtual memory. For this project, you will need to keep a history of 8 intervals. Therefore, you can use an unsigned char to store your history. We have prepared some simple example code using C/C++ bit operations to help with the details. When a page is accessed by a program, the virtual address of the page is translated to a physical address by address translation logic (in Machine::Translate). This logic should be modified to record
When selecting a page to page out, information contained in the access history bit fields of all the virtual pages currently mapped to physical pages can be used to implement several replacement algorithms (i.e. LRU Approximation, FIFO, etc). The function MemoryManager::Choose_Victim is called whenever a page needs to be paged out. This function determines which page-replacement policy is being used and calls the appropriate function in the AddrSpace object (AddrSpace::FIFO_Choose_Victim, AddrSpace::LRU_Choose_Victim, or AddrSpace::SC_Choose_Victim). You need to implement these policies by filling in the functions for which we have provided stubs in userprog/addrspace.cc. Every time a process' working set size is refreshed, the history bits for that process's address space should also be aged by shifting them to the right one position. In C, you can use the >> operator to shift an integer to the right (e.g. 0x8 >> 1 == 0x4). This allows the process to slowly "forget" old accesses. Each time a thread runs for 10 quanta, the handout code will cause Nachos to invoke Thread::refreshWss() for the current thread. Just to be absolutely clear, that function should:
NOTE: The fields you need for the enhanced second chance algorithm (i.e. when a page is referenced, and whether or not it has been written to) have already been initialized and are already being updated properly. Also, if you implement the Reference History field correctly, you do not need to introduce any other fields to implement the LRU policy correctly. Once you have added new fields to the TranslationEntry, you need to properly update these values. First, you will need to implement the body of the clearSC, clearRefHistory, setTime, and getTime functions, which should properly initialize your page statistics. Second, you will need to implement updates to your access fields in the function Machine::Translate. Every time a thread refreshes its prescribed working set size (in Thread::refreshWss), you need to calculate the new prescribed working set size, trim down the process's owned frames to match the newly calculated prescribed working set size by paging out some pages if necessary, and then shift the history information. Finally, you need to implement the body of the stub functions (in userprog/addrspace.cc) which will actually choose a victim page to be swapped out based on your new data fields. The stub routines are listed in the next section. Stub Routines We have provided a set of empty functions which are called at appropriate places in the code for proper operation. These are listed below. You will need to modify them to work with your code. ● userprog/addrspace.cc These stub routines should select a physical page based on the named algorithm. See the comments in the code for more detail. ○ SC_Choose_Victim ○ LRU_Choose_Victim ○ FIFO_Choose_Victim ● The other stub routine you must fill in is AddrSpace::TooManyFrames. This routine must decide if the process owns more frames than its prescribed working set allows. ○ TranslationEntry::clearSC This should reset your second chance information to values appropriate when the page is first loaded into memory. ○ TranslationEntry::clearRefHistory This should reset your reference history information to values appropriate when the page is first loaded into memory. ○ TranslationEntry::setTime This should set the time information to the value specified. ○ TranslationEntry::getTime This should return the time information for the page. Important Files Files that you will need to reference or modify include: ● userprog/addrspace.h - Contains the definition of Address Spaces ● userprog/addrspace.cc - Contains the implementation of Address Spaces ● machine/translate.h - Contains the definition of the virtual to physical address translation routines ● machine/translate.cc - Contains the implementation of the virtual to physical address translation routines ● threads/thread.h - Contains the definition of the Thread Class ● threads/thread.cc - Contains the implementation of the Thread Class, including the Thread::refreshWss routine.
After the tests have ran there are two types of post-processing that can be done. The first is to generate a table, listing for each combination of program, page replacement policy, and delta, the number of page faults versus page outs. The second is to generate histograms showing the number of ticks between page faults. But before either the table or histograms can be generated we must post-process the data collected. Post-Process Testing Data
cd nachos/dsui_tmp/prp make prp_postprocess _This step will analyze the data collected from running make prp_tests and prepare data for display and conversion into histograms. This step must be preformed before generating the table or histograms, and it takes several minutes (I recommend using cycle4 if you're using the cycle servers).
Generate Page Fault Stats Table (form: Page Faults / Page Outs)_
cd nachos/dsui_tmp/prp make table The performance data table will be sent to standard out and must be included in your report. If this fails, it is probably because instances of post-processing are still finishing. Just wait a few seconds (or check what is running with
ps aux). Generate Histograms cd nachos/dsui_tmp/prp make histos The generated histograms will be found in the dsui/prp/pdfs directory New Command Line Options for Nachos The commands above will test each user program for each possible page replacement policy and delta value, but in order to facilitate testing of your individual page replacement algorithms with different delta values, we have added a few new command line options to Nachos. ● -prp <page-replacement policy> = allows you to select the page-replacement policy to be used by the system. There are four policies available:
A correct implementation will yield the following performance data table. See the explanation on the next page for how to interpret this. Program = access1:
|| delta=1 | delta=2 | delta=4 | delta=8 | dumb || 1642/1226 | 1539/1192 | 1367/1131 | 1245/1086 | fifo || 1643/1227 | 1538/1190 | 1367/1130 | 1247/1086 | lru || 1028/1022 | 1028/1021 | 1028/1018 | 1028/1013 | secondchance || 1028/1021 | 1028/1020 | 1028/1017 | 1028/1012 | Program = access2:
|| delta=1 | delta=2 | delta=4 | delta= dumb || 34869/33773 | 34869/33773 | 34869/33773 | 34869/ fifo || 34869/33773 | 34869/33773 | 34869/33773 | 34869/ lru || 32825/32750 | 32825/32750 | 32825/32750 | 32825/ secondchance || 32804/32739 | 32804/32739 | 32804/32739 | 32804/ Program = matmult:
|| delta=1 | delta=2 | delta=4 | delta=8 | dumb || 2209/314 | 282/120 | 264/116 | 229/115 | fifo || 4659/566 | 281/118 | 260/114 | 227/113 | lru || 4083/114 | 196/109 | 190/108 | 184/106 | secondchance || 3190/81 | 228/78 | 225/75 | 208/68 | Program = access3:
|| delta=1 | delta=2 | delta=4 | delta=8 | dumb || 19/9 | 18/9 | 15/5 | 15/1 | fifo || 20/10 | 17/7 | 17/5 | 14/0 | lru || 14/8 | 14/7 | 14/4 | 14/0 | secondchance || 14/7 | 14/6 | 14/4 | 14/0 | Program = access4:
|| delta=1 | delta=2 | delta=4 | delta=8 | dumb || 172/117 | 161/111 | 62/39 | 16/2 | fifo || 172/117 | 161/112 | 147/104 | 16/1 | lru || 115/98 | 115/97 | 111/90 | 16/1 | secondchance || 123/97 | 123/96 | 122/93 | 15/0 |
Our Test Programs access1,2,3 and 4 are simple memory loads designed to stress the PRP algorithms in predictable ways. access1 and access2 are the Row-major and Col-major access orders on the 1024 page array. access3 is Row-major on a 10 page array and access4 is 10 iterations of access3.
For your final report, you must answer the following questions:
For this project, you should turn in the following items: