Skip to content
We areTOP 1%

What is thrashing, why does it happen, and how can it be prevented?

HardConceptPage Replacement & Thrashing
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

Thrashing is a state in which the system spends more time moving pages between RAM and disk than running programs. It happens when the active processes together need more frames than memory has, so each fault evicts a page that is needed again almost at once.

  • Vicious cycle: CPU utilisation drops because processes wait for the disk. A naive OS sees the idle CPU and admits more processes, raising the degree of multiprogramming (the number of processes in memory), which makes it worse.
  • Working-set model: a process's working set is the set of pages it used in its last Δ references. If the working sets add up to more than the available frames, the OS suspends (swaps out) a process.
  • Page-fault frequency: give a process more frames when its fault rate is above an upper limit, and take frames away when it is below a lower limit.
  • Simpler fixes: run fewer processes or add RAM.

Example: with Δ = 5 and last references 2, 6, 1, 5, 7, the working set is {1, 2, 5, 6, 7}. If three processes have working sets of 5, 4 and 6 pages (15 in total) but only 12 frames exist, the OS should suspend one process rather than let all three thrash. A laptop frozen by too many browser tabs while the disk works constantly is thrashing.

More in Page Replacement & Thrashing

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account