Least Recently Used (LRU) Page Replacement Algorithm
Least Recently Used (LRU) Page Replacement Algorithm
1. Aim
To implement the Least Recently Used (LRU) Page Replacement Algorithm and display the frame contents after each page arrival.
2. Objective
-
To understand how LRU selects a victim page
-
To implement LRU using time (recency) tracking
-
To analyze page hits and page faults
3. Theory
The LRU algorithm replaces the page that has not been used for the longest time in the past.
Key Idea:
“The page that was least recently accessed is least likely to be used again.”
LRU approximates optimal behavior better than FIFO but requires tracking past usage.
4. Data Structures Used
| Structure | Purpose |
|---|---|
frames[] | Stores pages in memory |
time[] | Stores last-used time of each frame |
counter | Global time counter |
5. Algorithm
-
Initialize frames as empty (
-1) -
For each page reference:
-
If page is present → Hit, update its time
-
Else:
-
If empty frame exists → place page
-
Else → replace page with minimum last-used time
-
-
-
Display frame table after each reference
-
Count page faults
6. Modular C Program (LRU)
7. Sample Input
8. Sample Output (Frame Table)
9. Observations
-
LRU produces fewer page faults than FIFO
-
Recently used pages remain in memory
-
Requires additional tracking (time/counters)
10. Advantages
✔ Better performance than FIFO
✔ Approximates optimal algorithm
✔ No Belady’s anomaly
11. Disadvantages
❌ Overhead of tracking usage
❌ Hard to implement perfectly in hardware
12. Result
The LRU page replacement algorithm was successfully implemented and the frame contents were displayed after each page reference.
Comments
Post a Comment