1. Gyanastra
  2. Operating Systems
  3. Thrashing
  4. Thrashing and Page Fault Rate
Free lesson, no account needed 7 min read 11 practice questions after it
Asked in past papers9 times
  • GATE CSE2007200620051997
  • ISRO20132008
  • UGC NET202320152013

Operating Systems · Thrashing

Thrashing and Page Fault Rate

Overview

Thrashing is the condition in which a process spends most of its time moving pages between secondary disk and main memory instead of executing useful work.
It matters because a high page-fault rate directly inflates the effective memory access time and slows process execution, so page-replacement and frame-allocation choices must be judged by how well they keep the fault rate low.

Key concepts

  • Thrashing: a process spends most of its time moving pages back and forth between the secondary disk and main memory, instead of doing useful execution.
  • Thrashing signature: thrashing occurs when there is a very large number of page faults — in the extreme, when the number of page faults becomes equal to the number of memory references (almost every memory reference creates a page fault).
    Even a page-fault rate as "small" as 50% is thrashing-like: out of every two memory references, one causes a page fault.
  • Consequence: most of the time is spent only reading the page from the hard disk into main memory, and almost no time is spent executing the process.
  • Page replacement: when all of a process's allocated frames are full, a new page reference forces one resident page to be evicted and replaced; the page-replacement algorithm decides which page is thrown out.
  • Frame allocation: although main memory contains many frames, the operating system does not give all of them to one process.
    To keep the degree of multiprogramming high, each process is assigned a fixed number of frames; several frame-allocation algorithms exist for deciding this number.
  • Service time (page-fault time): the time taken to bring the required page from disk and restart the process after a page fault.
  • Effective memory access time (EMAT): the weighted average of the page-fault service time and the normal memory access time, used to quantify how slow memory access becomes in the presence of page faults.
Memory diagram: Thrashing and Page Fault Rate
Figure. Thrashing and Page Fault Rate

How it works

  1. Why thrashing must be eliminated: the obvious fix is to design better page-replacement algorithms that can "guess" what the process will require in the future, so that the page needed next is kept in memory.
  2. This perfect guess is impossible: if the future were known, every decision would be the best decision — but it is never possible to know the future.
  3. Therefore the practical goal is to design better algorithms that closely approximate the best (optimal) algorithm, so that the page-fault rate can be reduced.
  4. Frame allocation creates the problem: a process is given only a fixed, limited number of frames (for example, only 4 frames).
    Suppose pages P1, P2, P3, P4 are already present in those four frames and the process now asks for page number 5. None of the four frames is free, so one resident page must be evicted and replaced by page 5.
  5. Page replacement: the page-replacement algorithm selects the victim page. A better algorithm can reduce the page-fault rate.
  6. Why reducing the fault rate is very important: the more the page faults, the more the time required for a memory access, and hence the slower the process execution.
  7. Quantify the slowdown: compute the effective memory access time in the presence of page faults (formula below).

Formulas

EMAT = P × service time + (1 − P) × memory access time
  • PP = page-fault rate (fraction of memory references that cause a page fault)

  • service time = also called page-fault time: the time taken to bring the required page from disk and restart the process after a page fault

  • (1−P)(1 - P) = fraction of references that do not fault; these are served directly from main memory, so they cost only the normal memory access time

  • Interpretation: if a page fault occurs, a large amount of work (disk transfer + restart) is done; if no page fault occurs, the access is just a normal main-memory access. Hence EMAT is a weighted average of the two.

Worked examples

Example 1 — Thrashing due to a high fault rate (the 50% case)

  • Suppose out of every two memory references, one reference creates a page fault.
  • Then the page-fault rate P=1/2=0.5P = 1/2 = 0.5 (50%).
  • Half of all memory references require a disk-to-memory page transfer, so the dominant part of execution time is disk service time, not CPU execution — this is thrashing.

Example 2 — Page replacement forced by a small frame allocation

  • The process is allocated 4 frames (only 4, even though main memory has many frames, in order to keep the degree of multiprogramming high).
  • Current contents of the 4 frames:
FramePage held
1P1
2P2
3P3
4P4
  • The process now references page P5. There is no free frame, so one of P1, P2, P3, P4 must be evicted and replaced by P5.
  • Step 1: a page fault occurs for P5.
  • Step 2: the page-replacement algorithm selects a victim page from {P1, P2, P3, P4}.
  • Step 3: the victim is written back (if dirty) and P5 is loaded from secondary storage into that frame.
  • Step 4: the process is restarted.
  • This whole sequence costs the service (page-fault) time; if the algorithm repeatedly evicts pages that are needed again soon, the fault rate rises and thrashing results.

Revision summary

  • Thrashing = excessive page movement between disk and main memory;
    the process spends most of its time paging rather than executing.
  • Extreme signature of thrashing: number of page faults ≈ number of memory references; a 50% fault rate already means one fault per two references.
  • Perfect future knowledge is impossible, so page-replacement algorithms are judged by how closely they approximate the optimal algorithm.
  • Processes receive only a fixed, limited number of frames so that the degree of multiprogramming stays high — this limited allocation is what forces replacements.
  • When all allocated frames are full, a new page reference forces a page replacement; the choice of victim determines the fault rate.
  • Higher page-fault rate → higher effective memory access time → slower process execution; reducing the fault rate is critical.
  • EMAT=P×service time+(1−P)×memory access timeEMAT = P \times \text{service time} + (1 - P) \times \text{memory access time}, where service time is the page-fault time (disk transfer plus process restart).

Previous-year exam insights

  • Thrashing is caused by the sum of the working sets (or total frames demanded) of all processes exceeding the number of available frames; the OS prevents it by suspending/deactivating some processes (reducing degree of multiprogramming) when free frames are insufficient, and by admitting a new process only if enough free frames remain.
    Asked inGATE 2006
  • The working-set model approximates locality of reference: the working set W(t, Δ) is the set of pages referenced in the last Δ references; the OS keeps each process's working set resident and uses the total demand to decide frame allocation and process suspension.
    Asked inGATE 2006UGC NET 2013
  • Increasing physical RAM reduces the page-fault rate (more frames per process, larger resident sets), which is why adding memory improves performance; it does not by itself increase virtual memory size or make memory 'faster'.
    Asked inGATE 2005
  • Belady's anomaly: for some reference strings, increasing the number of allocated frames under FIFO increases the number of page faults; stack algorithms such as LRU and OPT never suffer from it.
    Asked inUGC NET 2023
  • Causes of thrashing include too high a degree of multiprogramming (too many processes sharing too few frames, so each has fewer frames than its working set), global replacement that lets one process steal frames from another, and poor page-replacement policies; thrashing is not inevitable in virtual memory and is not cured merely by swapping.
    Asked inISRO 2013ISRO 2008
  • Effective access time with paging: EAT = (1 − p) × memory access time + p × page-fault service time, where p is the page-fault probability;
    when the fault service time dominates, EAT grows roughly linearly with p, so even a modest fault rate drastically slows execution.
    Asked inUGC NET 2015
Pages 1–2 of 2