Comparative Study - Simulation of Page Replacement Algorithms
Comparative Simulation of Page Replacement Algorithms
1. Aim
To simulate and compare the performance of:
-
FIFO
-
LRU
-
LFU
-
Random
-
Optimal
using a randomly generated page reference string with 3 page frames, and to calculate:
-
Total Hits
-
Total Misses
-
Hit Rate
2. Objective
-
To understand different page replacement strategies
-
To compare performance of various algorithms
-
To observe that Optimal gives minimum page faults
-
To analyze hit rate differences
3. Theory
When a process executes, pages are loaded into memory frames. If a page is not in memory, a page fault occurs.
Different page replacement algorithms decide which page to remove when memory is full.
Algorithms Used:
1️⃣ FIFO (First In First Out)
-
Replaces the oldest page in memory.
-
Simple queue-based approach.
-
May suffer from Belady’s anomaly.
2️⃣ LRU (Least Recently Used)
-
Replaces the page that has not been used for the longest time.
-
Uses past reference information.
-
Does not suffer from Belady’s anomaly.
3️⃣ LFU (Least Frequently Used)
-
Replaces the page with lowest usage frequency.
-
Requires frequency counting.
4️⃣ Random
-
Replaces any frame randomly.
-
Simple but unpredictable.
5️⃣ Optimal
-
Replaces the page that will not be used for the longest time in the future.
-
Produces minimum page faults.
-
Theoretical (future knowledge required).
4. Algorithm (General Simulation Procedure)
-
Generate a random page reference string.
-
For each algorithm:
-
Initialize frames as empty.
-
Traverse page reference string.
-
Check for hit or miss.
-
Apply replacement policy if needed.
-
-
Count:
-
Total hits
-
Total misses
-
-
Calculate:
-
Hit Rate = (Hits / Total Pages) × 100
-
5. Program
Sample Output
(Note: Output varies because of random generation.)
6. Observations
-
Optimal gives minimum misses.
-
LRU usually performs close to Optimal.
-
FIFO may perform poorly.
-
Random gives inconsistent results.
-
LFU performance depends on access pattern.
7. Result
The simulation of FIFO, LRU, LFU, Random and Optimal page replacement algorithms was successfully implemented and their performance was compared using total hits, total misses and hit rate.
Comments
Post a Comment