KS3 & GCSE Computing · GCSE

Thrashing in Operating Systems — Virtual Memory Explained for GCSE

Understand thrashing and virtual memory for GCSE Computer Science: page faults, page replacement algorithms, why thrashing cripples performance, and how to prevent it.

Duke Harewood — author of AI Tutors for Key Stage 3Updated 5 min read

On this page

Short answer

Thrashing occurs when an operating system spends most of its time swapping pages of memory between RAM and secondary storage rather than executing programs, causing the system to become extremely slow or unresponsive. It is a consequence of running more processes simultaneously than the available RAM can comfortably support.

At a glance

Key stage
GCSE
Subject
Computing
Type
Explainer
For
Students
Read time
5 min
Last updated
8 October 2026

Where this fits

  1. Key Stage 3Years 7–9
  2. GCSEYears 10–11This article
This article is aimed at GCSE (Years 10–11), the stage after Key Stage 3 (Years 7–9).

Method at a glance

  1. The OS moves infrequently used pages from RAM to a dedicated area of…
  2. This frees RAM for the currently active page
  3. When the evicted page is needed again, it is swapped back into RAM…
The 3 numbered steps in this article, in order.

How does virtual memory work?

Virtual memory allows a computer to use secondary storage (a hard drive or SSD) as an extension of RAM. The operating system divides both RAM and the virtual address space into fixed-size blocks called pages (typically 4 KB). When a program needs more memory than is physically available:

  1. The OS moves infrequently used pages from RAM to a dedicated area of secondary storage called the swap file (Windows) or swap partition (Linux).
  2. This frees RAM for the currently active page.
  3. When the evicted page is needed again, it is swapped back into RAM — swapping out another page first if necessary.

This process lets a computer run programs whose combined memory requirements exceed physical RAM, at the cost of slower access times (secondary storage is thousands of times slower than RAM).

What is a page fault?

A page fault occurs when a program tries to access a page that is not currently in RAM — it has been swapped out to secondary storage. The page fault triggers the OS to:

  1. Find the required page in the swap file.
  2. Load it into a free RAM frame (if one exists) or evict an existing page first.
  3. Update the page table to record the new location.
  4. Resume the halted instruction.

Occasional page faults are normal and expected. Thrashing occurs when page faults happen constantly and the OS spends more time handling them than running programs.

Condition Page fault rate System behaviour
Plenty of free RAM Very low (near zero) Fast; programs run normally
RAM moderately full Low to moderate Slight slowdown; occasional pauses
RAM overcommitted Very high Severe slowdown; disk activity light is constant
Thrashing Extreme System effectively halted; CPU used only for swapping

Why does thrashing happen?

Thrashing arises from a vicious cycle:

  1. Many processes are running simultaneously, each requiring more pages than RAM can hold.
  2. A process needs a page — it generates a page fault.
  3. To load that page, the OS evicts another page.
  4. The evicted page belongs to a different process, which then generates its own page fault.
  5. Each attempt to resolve one page fault creates another.

The CPU's utilisation drops because no process ever gets to run for long before another page fault halts it. The OS scheduler, seeing low CPU utilisation, may try to increase concurrency by loading more processes — making thrashing worse. This is the trap.

What page replacement algorithms does an OS use?

When a page must be evicted to make room, the OS chooses which page to remove using a replacement algorithm:

Algorithm How it works Advantage Disadvantage
FIFO (First In, First Out) Evict the page that has been in RAM longest Simple May evict frequently used pages
LRU (Least Recently Used) Evict the page that was accessed longest ago Good approximation of future use Expensive to track precisely
Optimal Evict the page not needed for longest in the future Theoretically best Impossible in practice (requires future knowledge)
Clock (Second Chance) Circular list; skip pages recently accessed Efficient LRU approximation Slightly more complex than FIFO

LRU (or a clock approximation of it) is the most common in real operating systems. The idea is that pages used recently are likely to be used again soon (the principle of temporal locality).

How can thrashing be prevented or resolved?

  1. Add more RAM — the simplest and most effective solution. More physical memory means fewer page faults.
  2. Reduce the number of concurrent processes — the OS can suspend lower-priority processes to free RAM for running processes.
  3. Increase the page size — fewer, larger pages reduce the overhead of page table management, though this also increases wasted space (internal fragmentation).
  4. Use an SSD for the swap file — SSDs are far faster than HDDs for random access; page faults resolve much more quickly, softening the impact of thrashing.
  5. Working set model — the OS tracks the set of pages each process is actively using (its working set) and ensures all those pages stay in RAM before the process is allowed to run.

Frequently asked questions

How can I tell if my computer is thrashing?

Signs of thrashing include: the system feels unresponsive even for simple tasks; the hard drive activity indicator is constantly lit; Task Manager (Windows) or Activity Monitor (macOS) shows very high disk usage but low CPU usage; moving the mouse or typing has a noticeable lag. Adding RAM, closing unused applications, or restarting typically resolves it immediately.

Is thrashing only possible with a hard drive, or can it happen with an SSD?

Thrashing can occur with any secondary storage, including SSDs. However, because SSDs are roughly 100–1,000 times faster than HDDs for random page reads, the system degradation during thrashing is less severe on an SSD. You may notice slowdowns without the system becoming completely unresponsive. NVMe SSDs (connected via PCIe) further reduce the gap, though they are still far slower than RAM.

Why would the OS make thrashing worse by loading more processes?

The OS process scheduler monitors CPU utilisation and tries to keep it high. When thrashing occurs, processes spend most of their time waiting for page faults to resolve, so CPU utilisation appears low. The scheduler interprets this as "the CPU is idle — load more processes." More processes need more pages, intensifying the competition for RAM and accelerating the thrashing. This counter-intuitive feedback loop is why thrashing can be sudden and dramatic.

What is the working set of a process?

The working set is the collection of pages a process is actively using at a given moment. Processes tend to exhibit locality of reference: they repeatedly access the same small set of pages for a period before moving on to a different set. If the OS ensures each process's working set fits entirely in RAM before the process is scheduled to run, page fault rates drop dramatically. The working set model formalises this — it is a more sophisticated approach than simple page replacement.


Struggling to understand operating system memory management? Professor Turing at aitutors.me can explain thrashing, page tables, and scheduling at just the right pace.

Key terms

  • Virtual memory
  • pages
  • infrequently used pages
  • swap file
  • swap partition
  • page fault
  • increase concurrency
  • FIFO

Sources