A paging and page-replacement lab
The problem
Build a small virtual-memory simulator: translate addresses through a page table, then count the page faults of FIFO, LRU and the clock algorithm on a reference string.
Requirements
- Translate logical addresses with a page table and report page faults and invalid addresses
- Count page faults for FIFO, LRU and clock for any number of frames
- Show the faults for 1 to 7 frames in a table, and point out any Belady's anomaly
- Add a TLB with FIFO replacement and report its hit rate and the average access time
Technologies
- C
- Arrays
- Integer arithmetic and bit operations
- The StepVioz page-replacement simulator for checking
Step by step
- Write the address-translation function with a page size that is a power of 2.
- Write one function per replacement algorithm that returns the number of faults.
- Run them for 1 to 7 frames on the string 1 2 3 4 1 2 5 1 2 3 4 5 and print a table.
- Add the TLB and compute the average access time from the hit rate.
- Check your fault counts against the simulator.
Expected result
A program that prints a table of page faults for three algorithms and a range of frame counts, and the average access time with a TLB.
How it is evaluated
- Fault counts match the simulator
- Belady's anomaly appears for FIFO on the test string
- The translation handles invalid pages and page faults
- The code is split into small functions
Ways to improve it
- Add the optimal algorithm and use it as a yardstick
- Add dirty bits and count the writes to disk
- Add a two-level page table