operating-systems

Definition

Thrashing

Thrashing occurs when a processor spends a disproportionate amount of time handling page faults compared to executing instructions. This results in a drastic drop in system performance.

Mechanism

Thrashing typically occurs when the sum of the resident sets of all active processes exceeds the available physical RAM.

  • As the system runs out of memory, the replacement policy is forced to swap out pages that will be needed again almost immediately.
  • This creates a feedback loop: a page is swapped in, triggers another fault elsewhere, which swaps out the first page again.

Causes

  • Insufficient RAM: The physical memory is too small for the current workload.
  • Poor Locality: A process is accessing memory in a scattered pattern that does not fit well with paging.
  • Over-multiprogramming: Too many processes are active, causing their resident sets to be squeezed below their working sets.

Prevention

The operating system can prevent thrashing by:

  • Working Set Management: Monitoring the pages each process actually needs and ensuring they are resident.
  • Process Suspension: Temporarily suspending processes to free up frames for the remaining active ones.