Thrashing

The state when the system spends a lot of time in a page fault, but the actual execution of the process is negligible is called thrashing.

In the initial stage, when we increase the degree of multi-programming then, CPU utilization is very high up to lambda (). Lemda is the stage at which the memory is full, and swapping ( IN/OUT) is just going to start.

At point lemda, if we increase the degree of multi-programming, CPU utilization sharply falls. This situation is Thrashing. Look at the following diagram for details.

thrashing in os

In simple words, we can also say that, at a certain point of CPU utilization, the continuous page fault is called Thrashing.

When Thrashing Happened?

SWAP IN and SWAP OUT (page replacement) are done by OS, not by CPU. Page swaps in/out continuously cause thrashing because there is no CPU execution at the time of swapping. OS also enables the programs to access main memory, Hard disk, I/O device, and Hard Disk.

Let’s explain with an example.

Let’s suppose memory is full with 4 pages and CPU demand for page 5.OS replaced page 5 with page 1. After replacing the CPU goes for the execution of the P5, and just before the execution of the P5, CPU demand for page 1 as OS brings the page 1 by replacing page 2 and tries to execute page 1 CPU again, demand page 2, and so on.

thrashing-example in operating system

So here, OS is performing the swap-in/out operations repeatedly, and nothing will execute. It is a thrashing situation.

Conclusion: when swap out page is demanded by CPU before to execute any other page in main memory then system performance decease dramatically. It may happen due to dependency on the executed page and swap-out page.

Problems of Thrashing

Decrease the performance of the system.

How to handle Thrashing

  • Locality Model
  • Handle through decreasing the page fault