Thrashing - aryanjoshi0823/5143-Operating-System GitHub Wiki

What is Thrashing in Operating Systems (OS)?

Thrashing in an OS occurs when the system spends more time managing memory swaps than executing useful tasks. It is primarily caused by a high frequency of page faults, where the required data is not present in main memory and must be fetched from disk storage. This condition arises when the operating system employs virtual memory but lacks sufficient physical RAM to handle active processes effectively.

After visualizing the Graphical representation,

  • The underlying idea is that if a process is given too few frames, there would be too many and too frequent page faults. As a result, the CPU would perform no useful work, and CPU usage would plummet drastically.

  • The long-term scheduler would then attempt to enhance CPU usage by loading additional processes into memory, increasing the degree of multiprogramming. Unfortunately, this would result in even lower CPU utilization, creating a chain reaction of larger page faults followed by a rise in the degree of multiprogramming, a phenomenon known as Thrashing.


Causes of Thrashing in Operating Systems

  1. Insufficient Physical Memory: Inadequate RAM leads to excessive swapping.
  2. Overallocation of Memory: Assigning more memory to processes than physically available.
  3. Poor Memory Management: Inefficient allocation or usage of memory resources.
  4. Excessive Multitasking: Running too many concurrent applications.
  5. Highly Demanding Applications: Memory-intensive programs monopolizing resources.
  6. Inefficient Swapping Strategy: Poorly managed swap files or partitions.

How to Overcome Thrashing?

  1. Upgrade RAM: Increasing physical memory reduces reliance on swapping.
  2. Limit Active Applications: Closing unnecessary programs frees system resources.
  3. Replace Memory-Intensive Programs: Use alternatives requiring less memory.
  4. Optimize Swap File Configuration: Properly configuring swap files can mitigate excessive paging.

Techniques to Prevent Thrashing

1. Working-Set Model

2. Page Fault Frequency

This model dynamically allocates frames based on the rate of page faults. Processes exceeding an upper bound receive more frames, while those below a lower bound may release frames.

3. Locality Model

Focuses on retaining frequently accessed pages in memory, reducing disk I/O and alleviating thrashing.


Symptoms of Thrashing

  • High CPU utilization with minimal productive output.
  • Increased disk activity due to frequent page swaps.
  • Excessive page faults.