Thrashing-Causes, Effect and Techniques To Handle Thrashing
Thrashing-Causes, Effect and Techniques To Handle Thrashing
In case, if the page fault and swapping happens very frequently at a higher rate, then the operating
system has to spend more time swapping these pages. This state in the operating system is termed
thrashing. Because of thrashing the CPU utilization is going to be reduced.
For example, if any process does not have the number of frames that it needs to support pages in
active use then it will quickly page fault. And at this point, the process must replace some pages. As
all the pages of the process are actively in use, it must replace a page that will be needed again right
away. Consequently, the process will quickly fault again, and again, and again, replacing pages that it
must bring back in immediately. This high paging activity by a process is called thrashing.
During thrashing, the CPU spends less time on some actual productive work spend more time
swapping.
Figure: Thrashing
Causes of Thrashing
Thrashing affects the performance of execution in the Operating system. Also, thrashing results in
severe performance problems in the Operating system.
When the utilization of CPU is low, then the process scheduling mechanism tries to load many
processes into the memory at the same time due to which degree of Multiprogramming can be
increased. Now in this situation, there are more processes in the memory as compared to the
available number of frames in the memory. Allocation of the limited amount of frames to each
process.
Whenever any process with high priority arrives in the memory and if the frame is not freely available
at that time then the other process that has occupied the frame is residing in the frame will move to
secondary storage and after that this free frame will be allocated to higher priority process.
We can also say that as soon as the memory fills up, the process starts spending a lot of time for the
required pages to be swapped in. Again the utilization of the CPU becomes low because most of the
processes are waiting for pages.
Thus a high degree of multiprogramming and lack of frames are two main causes of thrashing in the
Operating system.
Effect of Thrashing
At the time, when thrashing starts then the operating system tries to apply either the Global page
replacement Algorithm or the Local page replacement algorithm.
The Global Page replacement has access to bring any page, whenever thrashing found it tries to bring
more pages. Actually, due to this, no process can get enough frames and as a result, the thrashing will
increase more and more. Thus the global page replacement algorithm is not suitable whenever
thrashing happens.
Unlike the Global Page replacement, the local page replacement will select pages which only belongs
to that process. Due to this, there is a chance of a reduction in the thrashing. As it is also proved that
there are many disadvantages of Local Page replacement. Thus local page replacement is simply an
alternative to Global Page replacement.
Techniques to handle:
1. Locality Model –
A locality is a set of pages that are actively used together. The locality model states that as a process
executes, it moves from one locality to another. A program is generally composed of several different
localities, which may overlap.
For example when a function is called, it defines a new locality where memory references are made to
the instructions of the function call, it’s local and global variables, etc. Similarly, when the function is
exited, the process leaves this locality.
According to this model, based on a parameter A, the working set is defined as the set of pages in the
most recent ‘A’ page references. Hence, all the actively used pages would always end up being a part
of the working set.
The accuracy of the working set is dependent on the value of parameter A. If A is too large, then
working sets may overlap. On the other hand, for smaller values of A, the locality might not be
covered entirely.
If D is the total demand for frames and is the working set size for a process i,
Now, if ‘m’ is the number of frames available in the memory, there are 2 possibilities:
(i) D>m i.e. total demand exceeds the number of frames, then thrashing will occur as some
processes would not get enough frames.
(ii) D<=m, then there would be no thrashing.
A more direct approach to handle thrashing is the one that uses the Page-Fault Frequency
concept. The working-set model is successful and its knowledge can be useful in preparing but it is a
very clumpy approach in order to avoid thrashing. There is another technique that is used to avoid
thrashing and it is Page Fault Frequency (PFF) and it is a more direct approach.
The main problem is how to prevent thrashing. As thrashing has a high page fault rate and also we
want to control the page fault rate.
When the Page fault is too high, then we know that the process needs more frames. Conversely, if the
page fault-rate is too low then the process may have too many frames.
We can establish upper and lower bounds on the desired page faults. If the actual page-fault rate
exceeds the upper limit then we will allocate the process to another frame. And if the page fault rate
falls below the lower limit then we can remove the frame from the process.
Thus with this, we can directly measure and control the page fault rate in order to prevent thrashing.