Optimal Page Replacement Algorithm
Optimal Page Replacement Algorithm
1. Aim
To implement the Optimal Page Replacement Algorithm and display the frame contents after each page reference.
2. Objective
-
To understand the working of the Optimal page replacement strategy
-
To replace the page that will not be used for the longest time in the future
-
To display the frame table after each page arrival
-
To analyze page hits and page faults
3. Theory
The Optimal Page Replacement Algorithm replaces the page that will not be used for the longest time in the future.
Key Idea:
“Replace the page whose next use is farthest in the future.”
This algorithm produces the minimum possible number of page faults for a given reference string and number of frames.
⚠️ Note:
4. Data Structures Used
| Structure | Purpose |
|---|---|
frames[] | Stores pages in memory |
pages[] | Page reference string |
| Loop variables | To scan future references |
5. Algorithm
-
Initialize all frames as empty (
-1) -
For each page reference:
-
If page exists in frames → Hit
-
Else:
-
If empty frame exists → place page
-
Else:
-
For each page in frame, find next future use
-
Replace page with farthest future use (or never used again)
-
-
-
-
Display frame table after each reference
-
Count page faults
6. C Program (Optimal Page Replacement)
7. Sample Input
8. Sample Output (Frame Table)
9. Observations
-
Optimal algorithm gives minimum page faults
-
Requires future knowledge
-
Used as a benchmark algorithm
10. Advantages
✔ Produces minimum page faults
✔ Useful for performance comparison
✔ No Belady’s anomaly
11. Disadvantages
❌ Not implementable in real systems
❌ Requires future page references
❌ High computational overhead
12. Result
The Optimal Page Replacement Algorithm was successfully implemented and the frame contents were displayed after each page reference.
Comments
Post a Comment