codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🖥️

Operating Systems

25 chapters

1Intro to OS & Kernel Architecture2Process Concept & Lifecycle3System Calls & Interrupts4Process Management & PCB5Inter-Process Communication (IPC)6CPU Scheduling (FCFS, SJF, RR)7Threads (User vs Kernel Level)8Process Synchronization9Critical Section Problem10Producer-Consumer Problem11Dining Philosophers Problem12Deadlock Conditions & Prevention13Banker's Algorithm (Avoidance)14Memory Management & Paging15Memory Allocation (First Fit, Best Fit)16Paging and Segmentation17Translation Lookaside Buffer (TLB)18Virtual Memory & Demand Paging19Page Replacement Algorithms20Thrashing21File Systems & Directory Structure22File Allocation Methods23Disk Scheduling Algorithms24I/O Systems & DMA25OS Protection & Security
SubjectsOperating Systems

Thrashing

Updated 2026-04-24
3 min read

Thrashing

If you open too many Chrome tabs and massive video editing programs at the same time, your computer might suddenly freeze. The mouse becomes unresponsive, and you can hear your hard drive spinning aggressively. Your system is experiencing Thrashing.

1. What is Thrashing?

Thrashing occurs when an operating system spends more time paging (swapping pages in and out of the hard disk) than executing actual user code.

The Cycle of Thrashing:

  1. The OS monitors CPU utilization. If CPU utilization is too low, the OS increases the degree of multiprogramming by launching a new process.
  2. The new process needs memory, so the OS steals frames from existing processes.
  3. The existing processes suddenly don't have enough frames to hold their active working set of pages. They begin to suffer page faults.
  4. Because page faults require slow disk I/O, the processes block and go to sleep while waiting for the disk.
  5. The CPU utilization drops drastically because all processes are asleep waiting for the disk.
  6. The OS scheduler sees the CPU utilization drop, assumes it needs to add even more processes to keep the CPU busy, and launches another process.
  7. The new process steals more frames, causing even more page faults.
  8. The system completely collapses.

2. The Working-Set Model

To prevent thrashing, the OS must provide a process with as many frames as it actually needs. But how does it know how many it needs? It uses the Working-Set Model.

The working-set model is based on the assumption of Locality. As a process executes, it moves from locality to locality. A locality is a set of pages that are actively used together.

  • For example, when a process is executing a function, the locality consists of the pages containing the function's code and its local variables.

The Working Set is the set of pages in the most recent $\Delta$ (delta) page references. It is an approximation of the program's locality.

  • If we compute the working set for all processes in the system, we can find the total memory demand: $D = \sum W_i$.
  • If the total demand $D$ is greater than the total physical memory $m$, thrashing will occur.

Prevention

If $D > m$, the OS prevents thrashing by aggressively suspending (swapping out) one of the processes entirely, freeing up its frames to satisfy the working sets of the remaining active processes.

The Hardware Solution: The easiest and most common way to fix a computer that chronically thrashes is simply to buy and install more physical RAM!



PreviousPage Replacement AlgorithmsNextFile Systems & Directory Structure

Recommended Gear

Page Replacement AlgorithmsFile Systems & Directory Structure