Why does trashing occurs?
Thrashing occurs in computer systems when a process spends more time swapping data in and out of memory than executing actual work. This typically happens if there is an increase in the number of processes submitted to the CPU for execution and when the system's virtual memory is overcommitted, implying that there is not enough physical memory to support the active process. This will lead to increase the CPU utilization. But by increasing the number of process, after a certain time, the CPU utilization sharply falls and reaches zero. This is said to be Thrashing.
We all know that CPU should not be kept idle. Therefore, if the CPU utilization is too small, then we increase the degree of multiprogramming by introducing a new process to the system. Suppose a process enters a new phase in its execution and needs more frames. It starts faulting and taking process from another processes. These faulting process uses the paging device to swap pages in and out. As the process waits for paging device, CPU utilization decreases.
The CPU scheduler increases the degree of multiprogramming as soon as it finds decrease in CPU utilization. The new processes starts taking frames from each other thereby creating long queue for paging devices. All these causes thrashing and the throughput decreases.
Reasons why thrashing occurs:
Insufficient Physical Memory (RAM)
High degree of multiprogramming
Memory leaks
Frequent I/O operations
To mitigate thrashing, Several steps can be taken:
Increase the amount of physical memory RAM.
Reduce the number of running processes.
Optimize applications to use memory more efficiently.
Adjust the system's paging file size and settings.
Use better memory management algorithms.
Visualization:
X-axis ( Time ): represents passage of time.
Y-axis( Execution time) : represents the execution time of the processes.
In the graph,
Before time 30, execution time increases steadily.
Between 30 and 50, the system is experiencing thrashing. The execution time remains constant where a lot of time is spent on swapping pages.
After 50, the execution time starts to decrease, indicating that the thrashing is reducing and the normal execution is resuming.
Time 70 onwards the execution time begins to increase again, but at a slower rate.
Summary
Thrashing in computer systems occurs when processes spend too much time swapping data in and out of memory rather than executing tasks, often due to overcommitted virtual memory and high degrees of multiprogramming. This leads to a sharp drop in CPU utilization and system throughput. To mitigate thrashing, it's essential to increase physical memory, reduce the number of processes, optimize memory usage, adjust paging file settings, and employ better memory management algorithms. Visualization of thrashing shows initial steady execution time, a period of constant execution time due to thrashing, followed by a decrease as thrashing reduces, and a slower rate of increase afterward.