CS 5460 Homework 5

Due: Tuesday, October 27th, 2009 12:25pm

Files for this assignment are in ~cs5460/hw5 on the CADE filesystem.

Your task is to fill in the four page-replacement algorithms in hw5.c, gather statitics on the algorithsm applied to five sample access logs, and answer some questions. You will handin two files:

This is an invidual assignment (as opposed to a team assignment, like HW4).

The Sample Access Logs

To test your page-replacement algorithms, five logs of page accesses are provided. Each log contains an array of 32-bit little-endian twos-complement numbers that correspond to the start of pages in a 32-bit program. Each number represents an access of the heap on a page that is different from the previous access – which corresponds to an access that could trigger a page fault.

Running a Simulation

After you implement the algorithms (below) and assuming that hw5.c is built as hw5, you can run the sumulation with

  hw5 <num-frames> <algorithm> <log-file>

where <num-frames> is between 1 and 1048576, <algorithm> is one of fifo, second, lru, or optimal, and <log-file> is a sample access log.

Page fault statistics for the chosen simulation are written to stdout. (In the real programs, the number of page hits would be much higher, since the access log does not contain entries for consecutive accesses of the same page.)

Implementing the Replacement Algorithms

Fill in the implementations of the following 8 functions in hw5.c:

For each algorithm, the _hit() function is called as a notification when an accessed page was already allocated to a frame (i.e., when the access does not trigger a page fault). For some algorithms, this function won't do anything.

For each algorithm, the _replace() function is called when an accessed page is not already allocated to a frame (i.e., when the access triggers a page fault). The result should be a frame index to be replaced with the accessed page. This function should not directly modify the pages frame table or the frames reverse page table, though it may look at the current frames content to pick a frame index. This function may need to use information stored by the corresponding _hit() function, depending on the algorithm.

For implementing optimal, it turns out to be optimal to evict the page used farthest in the future. Note that searching the future for a given page can take a long time; consider caching the results of such searches, but beware of using a cached result when a previously computed access time has already passed.

Gathering Statistics and Answering Questions

For each of the five sample log files, build a table that shows page-fault counts for each algoritm (columns) and for each frame count (rows) that is a power of two between 1 and 2048 inclusive.

For example, one of the tables should look something like this:

  slides_log      fifo    second       lru   optimal
           1         0         0         0         0
           2         0         0         0         0
           4         0         0         0         0
           8         0         0         0         0
          16         0         0         0         0
          32         0         0         0         0
          64         0         0         0         0
         128         0         0         0         0
         256         0         0         0         0
         512         0         0         0         0
        1024         0         0         0         0
        2048         0         0         0         0

except that the page-fault counts won't be 0.

Finally, answer these questions:

  1. Why are the results the same for all algorithms when using 1 frame?
  2. Why are the results the same for all algorithms when using 2048 frames?
  3. What about the table for the random log distinguishes it from the logs of real programs?
  4. Given that the optimal algorithm is generaly not practical and ignoring the random log, does one of the other three algorithms always beat the remaining two?

Submit the tables and answers in a text file, stats.txt.


Last update: Tuesday, December 8th, 2009
mflatt@cs.utah.edu