What is Thrashing ?

Thrashing :

  • A page fault occurs when the memory access requested (from the virtual  address space) does not map to something that is in main memory. A page must  then be sent from main memory to swap, so that the requested new page can be  brought from swap to main memory. This results in 2 disk I/Os. Now you might know that disk I/Os are very slow as compared to memory access.
  • Now if it happens that your system has to swap pages at such a higher rate that major chunk of CPU time is spent in swapping, then this state is known as Thrashing. So effectively during thrashing, the CPU spends less time in some actual productive work and more time in swapping.

Why it occurs :

In our system, Thrashing occurs when there are too much pages in our memory, and each page refers to another page. The real memory shortens in capacity to have all the pages in it, so it uses ‘virtual memory’. When each page in execution demands that page that is not currently in real memory (RAM) it place some pages on virtual memory and adjust the required page on RAM. If CPU is so much busy in doing this task, thrashing occurs.

To resolve thrashing you can do any of the suggestions below :

  • Increase the amount of RAM in the computer.
  • Decrease the number of programs being run on the computer.
  • Adjust the size of the swap file.
  • Shadow Paging

Now the effects of thrashing and also the extent to which thrashing occurs will be decided by the type of page replacement policy.

1. Global Page Replacement: The paging algorithm is applied to  all the pages of the memory regardless of which process “owns” them. A  page fault in one process may cause a replacement from any process in  memory. Thus, the size of a partition may vary randomly.

2. Local Page Replacement: The memory is divided into partitions of a predetermined size for each  process and the paging algorithm is applied independently for each  region. A process can only use pages in its partition.

What happens after Thrashing starts?

If global page replacement is used, situations worsens very quickly. CPU thinks that CPU utilization is decreasing, so it tries to increase the degree of multiprogramming. Hence bringing more processes inside memory, which in effect increases the thrashing and brings down CPU utilization further down. The CPU notices that utilization is going further down, so it increases the degree of multiprogramming further and the cycle continues.

The solution can be local page replacement where a process can only be allocated pages in its own region in memory. If the swaps of a process increase also, the overall CPU utilization does not decrease much. If other transactions have enough page frames in the partitions they occupy, they will continue to be processed efficiently.

Leave a Reply

Your email address will not be published. Required fields are marked *