Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter 8 of your text. First generate a random page-reference string (this should be 20 entries long) where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms so that the number of page frames goes from 1 to 7 and you must compute the page fault for each of these frame numbers. Record the number of page faults with each of these different page frames numbers and each of the different algorithms. Assume that demand paging is used. Remember to count the first time a page comes in, as this is a page fault in demand paging.
FIFO Page Replacement:
FIFO (First-In, First- out) page replacement algorithm is the simplest and low overhead paging algorithm. Here the page that is oldest i.e. which has spent longest time in the memory is selected and replaced with the new data. The algorithm is implemented with the queue. The queue is used to hold the pages in the memory. Some of the advantages of the FIFO algorithm is that it is easy to understand and implement FIFO page replacement algorithm.
Optimal Page Replacement:
In optimal page replacement strategy, the pages that will not be used for the longer period of time is replaced with the new page data. This policy requires knowledge of the pages that is going to be demanded in the future. This algorithm is difficult to implement and is used from the theoretical comparison of the page replacement algorithms.
LRU Page Replacement:
LRU (Least Recently Used) Page Replacement is the good approximate of the optimal algorithm. In LRU page replacement algorithm, the pages that is not used for the longest period of time is replaced with the new data. It is based on the idea that the pages that is not used for the long time will remain be unused in future too.