What is Thrashing and How to Prevent it?

by Carson
94 views

One of the reasons why computer programs slow down is due to thrashing. Find out about thrashing and how to prevent it from occurring in this article.

The Definition of Thrashing

When a computer could not find the necessary information in RAM, it throws a page fault. After a page fault, it starts scanning in the virtual memory partitions on the disk. However, the rate of retrieving information from disk is significantly lower than that of extracting data from RAM, which can slow down programs significantly.

This is precisely what thrashing is. Essentially, you will see little to no CPU usage at all, even if the process is running, as the program is focused on obtaining the necessary data most of the time of its execution. This is a problem since it can create performance issues or may look like a crash if the thrashing is too severe.

Worse yet, more threads might be started to increase the CPU utilization of the process. This is even more of a problem because the program will need more resources to load correctly, which means lower CPU usage as more time is being devoted to extracting resources. This creates a vicious cycle that may eventually result in a crash or a near-complete halt in the program’s execution.

How to Prevent Thrashing from Taking Place in an App?

Since thrashing is a severe performance issue where memory is overloaded, programmers must take precautions to avoid these performance roadblocks to provide a smooth user experience with quick responses to interrupts.

One of the major reasons thrashing occurs is poor memory management. In large programs involving many variables, programmers may forget to delete unnecessary variables containing lots of information, leading to the accumulation of memory. Moreover, some variables used for debugging purposes might be missed and included in the program where it is unused. This might also contribute to memory overloads.

However great the memory management the apps are taking, thrashing can still happen if other programs are simply using too much memory. Therefore, the first thing a user should do to a program when it’s thrashing isn’t to change the code or uninstall the program altogether. Instead, try closing apps that are hogging memory resources and restart the thrashing application.

How to Handle Thrashing?

Since users might contribute to thrashing, it’s best if thrashing can be handled, too. For instance, we can use the page fault frequency to control thrashing, which means allocating more memory to the process if there are too many page faults. Moreover, more algorithms, such as the working set model that prioritizes retrieval efficiency by whether it’s active or not, can also be used by the operating system’s scheduler to deal with thrashing and increase the productivity of the applications.

Conclusion

In this article, we’ve discussed a severe performance issue called thrashing, how it works, how to prevent it, and how operating systems deal with it once it has happened. If you open more threads but the CPU usage decreases, you should look at the memory usage first instead of the CPU usage. For more, please visit the articles in the references below.

References and Credits

  1. (2021, November 10). What is a Page Fault? Retrieved March 12, 2022, from https://www.computerhope.com/jargon/p/pagefaul.htm
  2. (n.d.). Thrashing and Working Sets. Retrieved March 12, 2022, from https://web.stanford.edu/~ouster/cgi-bin/cs140-winter12/lecture.php?topic=thrashing
  3. (2021, August 7). Thrashing in OS. Retrieved March 12, 2022, from https://www.scaler.com/topics/thrashing-in-os/
  4. (n.d.). Definition of thrashing. Retrieved March 12, 2022, from https://www.pcmag.com/encyclopedia/term/thrashing

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.