Os Memory Management Questions Medium
The NRU (Not Recently Used) page replacement algorithm is a simple and efficient method used in operating systems for managing memory. It aims to select a page for replacement based on its usage history.
The working of the NRU algorithm involves the following steps:
1. Each page in the memory is assigned a reference bit, which is initially set to 0. This bit is used to track whether the page has been referenced (accessed) recently or not.
2. When a page fault occurs and a new page needs to be brought into memory, the algorithm scans all the pages in the memory and categorizes them into four classes based on their reference bit and dirty bit (modified or not modified).
3. The four classes are as follows:
- Class 0: Pages with reference bit = 0 and dirty bit = 0.
- Class 1: Pages with reference bit = 0 and dirty bit = 1.
- Class 2: Pages with reference bit = 1 and dirty bit = 0.
- Class 3: Pages with reference bit = 1 and dirty bit = 1.
4. The NRU algorithm selects a page for replacement randomly from the lowest numbered non-empty class. This means that it gives priority to pages that have not been recently referenced and are not modified.
5. After selecting a page for replacement, the reference bit of all pages is reset to 0.
By selecting a page randomly from the lowest numbered non-empty class, the NRU algorithm ensures that both frequently used and infrequently used pages have a chance to be replaced. This helps in preventing the replacement of frequently used pages, which can improve the overall performance of the system.
However, the NRU algorithm has a limitation in that it does not differentiate between pages that have been referenced recently and those that have not been referenced for a long time. This can lead to suboptimal page replacement decisions in certain scenarios.