Explain the different page replacement policies.
Various page replacement algorithms are briefly explained below:
1. First-in, first-out
FIFO page replacement algorithm is a low-overhead algorithm. Now there the operating system maintains track of all the pages in memory in a queue, along with the most current arrival at the back, and the initial arrival in front. While a page requires to be replaced, the page at the front of the queue as the oldest page is selected.
Advantage: FIFO is intuitive and cheap.
Disadvantage:
1. Not good performs in practical application.
2. Suffers from Belady's anomaly.
2. Not recently used
NRU page replacement algorithm works at the following principle: while a page is referenced, a referenced bit is set for which page, marking this as referenced. The same, when a page is modified or written to, a modified bit is set. At an exact fixed time interval, the clock interrupt triggers and clears the referenced bit of each the pages, therefore only pages referenced inside the current clock interval are marked along with a referenced bit. When a page requires to be replaced, the operating system divides the pages in four classes:
- Class 0: not referenced, not modified
- Class 1: not referenced, modified
- Class 2: referenced, not modified
- Class 3: referenced, modified.
The Not recently used algorithm picks a random page from the lowest category for removal.
3. Optimal page replacement algorithm
The optimal page replacement algorithm (also termed as OPT) is an algorithm which works as follows:
When a page requires being swapped-in, the operating system swaps-out the page, whose subsequent use will occur farthest in the future. For illustration, a page which is not going to be used for the next 6 seconds will be swapped-out over a page which is going to be used inside the next 0.4 seconds.
Disadvantage: This algorithm can't be implemented in the common purpose operating system since this is impossible to calculate reliably how long this will be before a page is going to be used.