1. Home
  2. Engineering
  3. Computer
  4. Operating Systems
  5. 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.

Operating SystemsEngineeringIntermediateStep-by-step solution

Practice questions

Textbook-style questions. Press Solve in the tool to load the values and see the full solution. Underlined words are explained below.

  1. 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.

  2. 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.

  3. Find the minimum possible number of page faults (Optimal) for that string with 3 frames.

  4. 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.

Plan: how this problem is solved
  1. Write the given values
  2. The rule for this algorithm
  3. Fill the frames one reference at a time
  4. Count faults and hits
  5. Compare with the other algorithms (same string, 3 frames)
Answer
Page faults15
Hits5
Hit ratio25%
Miss ratio75%
Step-by-step solution
  1. 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
  2. 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.

  3. Fill the frames one reference at a time
    70120304230321201701
    77722224440000000777
    0000333222221111100
    111100033333222221
    FFFFHFFFFFFHHFFHHFFF
    Each column is one request. Coloured cells show the page just loaded. Bottom row: F = page fault, H = hit.
  4. Count faults and hits
    Page faults=15
    Hits=20 − 15 = 5
    Hit ratio=520 = 25%
    Miss ratio=1520 = 75%
  5. Compare with the other algorithms (same string, 3 frames)
    AlgorithmPage faults
    FIFO15
    LRU12
    Optimal9
    Optimal always gives the fewest faults, but it needs to know the future, so it is used only as a yardstick.
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.

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.

SymbolWhat it meansSI unit
refReference stringtext
fNumber 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.

Hit ratio = hitstotal references,   Miss ratio = page faultstotal references

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

  1. Type the known values from your question and pick the unit for each one.
  2. Press Solve step by step.
  3. 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.
  4. Check the answer, then go through each numbered step. Where there's a second method, it's shown after the main one.
  5. Stuck on a word? The terms section explains it in simple language.

Frequently asked questions

How does the Page Replacement work?
You enter the values you know, pick their units and press Solve. The tool changes everything to SI units, applies the formula Hit ratio = (hits)/(total references), Miss ratio = (page faults)/(total references) and shows you each step: given data, formula, substitution and the final answer.
What is the key idea behind it?
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.
What if my answer doesn't match my book?
First check that you've picked the right units. Then see which constants your book uses and how many figures it rounds to. You can change the number of figures under Settings in the solver. A small difference in the last digit is usually just rounding.
Can I see how to solve it without seeing the answer?
Yes. Tick Practice mode under the solver. You'll get the plan of steps only, so you can work it out on paper. One click then shows the full solution.
Is the Page Replacement free to use?
Yes, it's free with no sign-up. All calculations happen inside your browser and nothing you type is stored.
Which grades is it useful for?
It's made for Engineering (University · B.Tech · B.E. · Diploma · GATE · FE). The working follows the method used in textbooks and exams.