written 3.0 years ago by | • modified 3.0 years ago |
Thrashing
Whenever the same pages are being loaded repeatedly because of a lack of main memory to keep them in memory, then the performance of the paging system degrades considerably.
To understand thrashing there is a necessity to understand some of the concepts of the Paging System concepts.
Page Fault - It generates when a program tries to access data or code in its address space but is not currently located in the system RAM.
Swapping - To overcome the issue created by page fault OS tries to access that page from secondary memory and try to swap it with one of the pages in RAM.
The Thrashing arises when page fault and swapping are carried on the system very frequently and at a higher rate, then OS needs to spend most of the time swapping the pages in and out from the memory. This scenario is called Thrashing.
Situations Responsible for Thrashing
Lacks of Frames - If the process is assigned with very small page-frames, this will create several frequent page faults. OS always remains busy swapping pages in and out from the memory and utilization of CPU degrades.
High Degree of Multiprogramming - If a long-term scheduler is used for improving CPU utilization, the scheduler load various processes into the memory. This increases the degree of multiprogramming. But, this also again reduces the CPU utilization, creates more page faults, and increases the degree of multiprogramming leading towards the thrashing condition.
Ways to Avoid Thrashing
Increase the RAM size - The addition of more RAM and the memory ease the process of task handling and avoid disk thrashing. It acts as a long-term solution.
Stops the working of applications if too many applications running simultaneously - If too many applications running in the background then it consumes lots of resources of the system and slow down the system leading towards the thrashing. To avoid this close some of the applications. This can minimize the chances of thrashing to some extend only.
Use less memory occupying programs - Always prefer programs that require less space in the memory as compared to those programs that require more memory space.
Set swipe size smartly - The swap file of the system configured correctly to avoid disk thrashing.
How to Recover from Thrashing
Do not allow the system to go into thrashing by instructing the long-term scheduler not to bring the processes into memory after the threshold.
If the system is already in a thrashing situation, then instruct the mid-term scheduler to suspend some of the processes so that we can recover the system from thrashing.