Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Not Recently Used (NRU) page replacement algorithm
The Not Recently Used (NRU) page replacement algorithm is a fundamental memory management technique used by operating systems to efficiently manage page replacement in virtual memory systems. Its primary goal is to identify and remove pages from memory that have not been accessed recently, making room for new pages when physical memory becomes full.
How NRU Algorithm Works
NRU uses two hardware bits associated with each page a reference bit (R) and a modified bit (M). The reference bit is set when the page is accessed (read or written), and the modified bit is set when the page is written to. Based on these bits, pages are classified into four priority classes for replacement.
NRU Page Classes
The NRU algorithm categorizes pages into four classes based on their reference and modified bits
| Class | R Bit | M Bit | Description | Priority |
|---|---|---|---|---|
| Class 0 | 0 | 0 | Not referenced, not modified | Highest (best candidate) |
| Class 1 | 0 | 1 | Not referenced, but modified | Second |
| Class 2 | 1 | 0 | Referenced, not modified | Third |
| Class 3 | 1 | 1 | Referenced and modified | Lowest (last resort) |
Algorithm Steps
The NRU algorithm follows these systematic steps for page replacement
Initialization Each page has reference bit (R) and modified bit (M) maintained in the page table entry.
Classification At regular intervals (timer interrupts), classify all pages into the four classes based on their R and M bit values.
Selection Find the lowest-numbered non-empty class. If multiple classes contain pages, choose the one with the lowest class number.
Random Eviction Randomly select a page from the chosen class for replacement.
Reset Bits After page replacement, clear all reference bits (R) to 0 for the next selection cycle.
Example Execution
Consider a system with pages having the following status
| Page | R Bit | M Bit | Class |
|---|---|---|---|
| P1 | 0 | 0 | Class 0 |
| P2 | 1 | 1 | Class 3 |
| P3 | 0 | 1 | Class 1 |
| P4 | 1 | 0 | Class 2 |
| P5 | 0 | 0 | Class 0 |
The algorithm will select from Class 0 (lowest non-empty class) and randomly choose either P1 or P5 for replacement.
Advantages
Simplicity Easy to implement with minimal overhead, making it suitable for resource-constrained systems.
Hardware Support Uses standard hardware reference and modified bits available in most processors.
Fair Approximation Provides a reasonable approximation of LRU behavior without complex timestamp maintenance.
Adaptability Periodic clearing of reference bits allows adaptation to changing access patterns.
Disadvantages
Coarse Granularity Only distinguishes between recently used and not recently used, missing finer temporal details.
Random Selection Random choice within classes may not always select the optimal page for replacement.
Clock Dependency Requires periodic timer interrupts to reset reference bits, adding system overhead.
Use Cases
Embedded Systems Ideal for systems with limited computational resources where complex algorithms are impractical.
Real-time Systems Provides predictable performance with low overhead for time-critical applications.
Legacy Hardware Works well on older systems that lack advanced memory management features.
Simple Operating Systems Suitable for basic OS implementations where simplicity is preferred over optimal performance.
Conclusion
The NRU page replacement algorithm offers a practical balance between simplicity and effectiveness for memory management. While it may not provide optimal performance compared to more sophisticated algorithms like LRU, its low implementation overhead and reasonable approximation make it valuable for resource-constrained environments and systems where simplicity is paramount.
