Page Replacement Algorithm Simulator
Compare four page-replacement policies with step-by-step frame traces and see how fault counts, hit ratios and frame capacity change.{{ summaryTitle }}
{{ summaryLine }}
{{ summaryAnnouncement }}
| Step | Page | Outcome | Evicted | Frames after request | Policy evidence | Copy |
|---|---|---|---|---|---|---|
| {{ row.step }} | {{ row.page }} | {{ outcomeLabel(row.outcome) }} | {{ row.evicted === null ? '—' : row.evicted }} | {{ formatFrames(row.frames) }} | {{ row.policyState }} |
The chart renderer is unavailable. Exact totals remain available in the comparison ledger.
| Algorithm | Hits | Faults | Evictions | Hit ratio | Faults at {{ simulation.alternateFrameCount }} frames | Frame effect | Copy |
|---|---|---|---|---|---|---|---|
| {{ row.label }} | {{ row.hits }} | {{ row.faults }} | {{ row.evictions }} | {{ formatPercent(row.hitRatio) }} | {{ row.alternateFaults }} | {{ frameEffectLabel(row) }} |
Virtual memory lets a program use addresses without knowing which physical memory frames currently hold its pages. When a requested page is already resident, the access is a hit. When it is absent, a page fault brings it into memory. If every available frame is occupied, the operating system also needs a replacement policy to choose a resident page to evict.
A page-reference string records requests in their original order. Repeated labels matter because recent and future use are exactly what separate the policies. First-In, First-Out (FIFO) follows arrival order, Least Recently Used (LRU) follows access history, Optimal looks ahead through the complete reference string, and Clock approximates recency with a circular hand and reference bits.
- Hit
- The requested page is already in one of the frames, so no replacement is needed.
- Fault
- The requested page is absent. It fills an empty frame or causes an eviction when the frames are full.
- Eviction
- A resident page leaves a full frame so the faulting page can enter.
- Policy state
- The queue, recency order, future-use evidence, or Clock bits that justify the next victim choice.
More frames often reduce faults, but that expectation is not universal. FIFO can show Bélády's anomaly, where a particular reference string produces more faults after memory capacity increases. LRU does not show that anomaly because every page held with a smaller frame count remains part of the larger-frame resident set under the same history.
A trace explains policy decisions for one bounded sequence; it does not predict the total cost of a real memory system. Disk or storage latency, dirty-page writes, prefetching, shared pages, translation lookaside buffers, and live workload changes all affect performance beyond the hit and fault counts shown here.
How to Use This Tool:
Keep the reference string and frame count fixed when comparing policies, then change one factor at a time.
- Choose a Focus policy whose exact frame decisions you want to follow.
- Enter 1 to 30 page labels in Page-reference string, separated by spaces, commas, or line breaks. Each label may contain 1 to 8 letters, numbers, underscores, or hyphens.
- Set Page frames from 1 to 8. Frames begin empty, so the first request for each initially absent page is a fault.
- Move Trace step from step 0 through the final request. Step 0 shows the empty frames; later steps show the requested page, hit or fault, victim, resulting frames, and policy evidence.
- Set Additional-frame comparison from 0 to 3 when you want to compare the same reference string at a larger capacity. The two frame counts together may not exceed 8.
Interpreting Results:
Read the selected trace before comparing totals. A lower fault count is better for this reference string, while the hit ratio expresses the same outcome from the opposite direction. An eviction count can be lower than the fault count because faults that fill empty frames do not evict anything.
The policy comparison uses the same labels and frame count for all four methods. Optimal is an offline lower bound because it can see future requests; it is useful as a benchmark, not as a deployable general-purpose policy. Clock and LRU use different evidence, so similar totals do not mean they made the same victim choices.
A positive fault difference after adding frames means the larger run faulted more often. Treat that as evidence about this policy and sequence, not as a general claim that extra memory hurts performance.
Technical Details:
Each request first checks the resident frames. A hit preserves the frame contents and may update recency or reference-bit state. A fault fills an empty frame if one exists; only a fault with no empty frame invokes the selected eviction rule.
Rule Core:
The victim rule is the main difference among the policies. Ties follow the stable frame or policy order established by the trace.
| Policy | Victim rule when frames are full | State shown in the trace | Important limit |
|---|---|---|---|
| FIFO | Evict the resident that entered earliest. | Oldest-to-newest queue | Ignores later reuse and can show Bélády's anomaly. |
| LRU | Evict the resident whose most recent request is oldest. | Most-recent-to-least-recent order | Uses past access as a predictor of future need. |
| Optimal | Evict the resident used farthest in the remaining string, or one never used again. | Next-use position for every resident | Requires future knowledge and serves as a lower bound. |
| Clock | Advance the hand, clearing reference bits of 1, until a frame with bit 0 is found. | Hand position and one bit per frame | Approximates recency rather than reproducing LRU exactly. |
Formula Core:
The hit ratio is the percentage of page requests served by pages already resident. Hits and faults divide the complete reference string, so their counts add to the number of requests.
The ratio keeps full precision for comparison and is formatted for display. Fault and eviction totals are integer counts; no timing cost is inferred from them.
Bélády Sequence:
For FIFO, the reference string 1 2 3 4 1 2 5 1 2 3 4 5 produces 9 faults with 3 frames and 10 faults with 4 frames. The additional frame therefore changes the FIFO queue in a way that creates one extra fault. LRU retains the stack property and does not reverse direction on this sequence.
Page labels are compared literally. The simulation accepts 1 to 30 labels, 1 to 8 base frames, and up to 3 additional frames, with a hard combined maximum of 8. Every run is deterministic for the same policy, labels, and frame settings.
References:
- Beyond Physical Memory: Policies, Operating Systems: Three Easy Pieces, version 1.10.
- An anomaly in space-time characteristics of certain programs running in a paging machine, Communications of the ACM, June 1969.