- Home
- Engineering
- Computer
- Operating Systems
- Page Replacement Calculator (FIFO, LRU, Optimal)
Page Replacement Calculator (FIFO, LRU, Optimal)
Frame-by-frame table, page faults, hits and hit ratio for any reference string, with all three algorithms compared.
Practice questions
Textbook-style questions. Press Solve in the tool to load the values and see the full solution. Underlined words are explained below.
Count the page faults with FIFO and 3 frames for the string 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1.
Use LRU with 3 frames on the same string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1.
Find the minimum possible number of page faults (Optimal) for that string with 3 frames.
FIFO gives 9 faults for 1 2 3 4 1 2 5 1 2 3 4 5 with 3 frames. How many with 4 frames? (Belady's anomaly)
Worked example
Here's the first practice question solved in full, so you can see exactly what you'll get. Try it on paper before you read the steps.
Question: Count the page faults with FIFO and 3 frames for the string 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1.
- Write the given values
- The rule for this algorithm
- Fill the frames one reference at a time
- Count faults and hits
- Compare with the other algorithms (same string, 3 frames)
- Write the given values
FIFO (first in, first out) ref = 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 f = 3 - The rule for this algorithm
On a fault with full frames, throw out the page that came in earliest. A hit means the page is already in a frame, so nothing changes.
- Fill the frames one reference at a time
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7 0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0 1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2 1 F F F F H F F F F F F H H F F H H F F F Each column is one request. Coloured cells show the page just loaded. Bottom row: F = page fault, H = hit. - Count faults and hits
Page faults = 15 Hits = 20 − 15 = 5 Hit ratio = 520 = 25% Miss ratio = 1520 = 75% - Compare with the other algorithms (same string, 3 frames)
Algorithm Page faults FIFO 15 LRU 12 Optimal 9 Optimal always gives the fewest faults, but it needs to know the future, so it is used only as a yardstick.
Terms used on this page
New to a word in the question or the solution? Here it is in simple language.
- Page and frame
- Programs are cut into equal pieces called pages. Main memory is cut into slots of the same size called frames. A page must sit in a frame before the CPU can use it.
- Page fault and hit
- A hit means the page you need is already in memory. A page fault means it isn't, so the OS must load it, which is slow.
- Reference string
- The list of page numbers in the order the program asks for them.
- FIFO, LRU and Optimal
- Rules for which page to throw out when memory is full. FIFO: the oldest one. LRU: the one not used for the longest time. Optimal: the one needed farthest in the future.
- Hit ratio and miss ratio
- Hit ratio = hits ÷ total requests. Miss ratio = faults ÷ total requests. They add up to 100%.
- Belady's anomaly
- A strange case where FIFO gives more page faults with more frames. LRU and Optimal never do this.
Symbols in this solver
What each box asks for, and its unit.
| Symbol | What it means | SI unit |
|---|---|---|
| ref | Reference string | text |
| f | Number of frames | (no unit) |
Formula & concept
Frame-by-frame table, page faults, hits and hit ratio for a reference string, with FIFO, LRU and Optimal compared.
Key idea: Main memory holds only a few pages at a time. When a needed page is missing, the OS must load it and may have to throw one out. A good rule throws out the page you won't need soon, so fewer faults happen.
How to use this calculator
- Type the known values from your question and pick the unit for each one.
- Press Solve step by step.
- Read the plan first. It lists the steps the solution will follow. Want to try it yourself? Tick Practice mode and the answer stays hidden until you ask for it.
- Check the answer, then go through each numbered step. Where there's a second method, it's shown after the main one.
- Stuck on a word? The terms section explains it in simple language.