Disk Thrashing

What is Disk Thrashing?

Disk thrashing, virtual memory thrashing, or simply thrashing refers to the state when the hard disk overworks to move data to and from the system and virtual memory excessively, barring most processing at application level.

Technically, thrashing is caused when the virtual memory is used to exchange data from a hard disk as the main memory gets full. Added pages are exchanged in and out of the virtual memory causing a very high rate of hard disk access.

Understanding Disk Thrashing

What is Disk Thrashing

When the computer system starts using the virtual memory too often and too much, it results in being accessed more for swapping pages. This results in disk thrashing.

This specific phenomenon slows down the computer considerably because the data needs to be moved back and forth less efficiently to the physical memory from the hard drive.

In such situations, the application may stop responding but that does not keep the disk drive’s light from blinking on and off.

This is because too many applications or programs need to compete for memory access.

Disk thrashing is a common issue with the Hard Disk Drives (HDDs), but it may happen with the Solid State Drives (SSDs) as well.

However, the possibility of it happening and failing is greater in the case of HDDs than SSDs due to the mechanical disks in them and the moving head hovering over the disk in order to read from and write to it.

In comparison, on a modern SSD, the individual cells usually come with a higher lifespan, but can still be reduced if you write and delete data constantly to and from them.

In contemporary computers, disk thrashing may happen in two specific situations such as:

Impact

Disk thrashing may have little impact initially, but if it is allowed to continue, it may cause serious issues.

It will slow down the computer and reduce the performance level due to the physical limitations of the Hard Disk Drives.

In spite of its limitations, it will have a lot of work to do as programs and applications continue loading.

Prolonged thrashing also results in a significant rise in the temperature level.

As you may know, overheating is the primary cause of a plethora of issues with the performance of the computer components, of which the hard drive is one.

Therefore, intense disk thrashing will result in a permanent hard drive failure.

What are the Causes of Disk Thrashing?

The primary reason behind disk thrashing is excessive usage of the resources of the virtual memory by the computer due to insufficient system resources and memory, or because the main system memory is full.

This typically results in continuous page faults or a state of swapping pages inhibiting application-level processing.

Typically, the common causes of disk thrashing can be summarized as follows:

Read Also:  Why is Your CPU Frequency So High? (Causes & Fixes)

In such conditions, the additional pages are swapped in and out of the virtual memory at a rapid pace which increases the access rate on the hard drives.

Here are some other significant causes:

Working set

Ideally, the pages that are accessed more frequently are called the working set, which may also cause disk thrashing.

When there are too many computer processes, they have to compete for the available and inadequate memory resources and lower CPU utilization.

Ideally, after initialization is complete, most of the programs run on a small number of data pages and codes in comparison to the total amount of memory needed.

This is where the concept of a working set comes in, which may also result in disk thrashing.

When this working set is a small percentage of the total number of pages in the system, the virtual memory systems work very efficiently.

In these situations, a small amount of computing is expended in order to resolve the page faults.

When this percentage of working sets increases, things are still manageable in terms of resolving page faults, but only up to a certain point.

When this reaches a critical point, the faults also increase significantly along with it.

During these times, the time required to resolve the faults is much more. This results in disk thrashing.

This happens especially when the program typically has to work on large data structures.

This increases the working set resulting in continuous page faults and disk thrashing that slows down the computer system.

Virtual memory:

When the use of virtual memory is frequent and high, it may lead to unproductive CPU utilization, which may bring the computer system to a grinding halt due to disk thrashing.

Ideally, the virtual memory treats a part of the secondary storage, such as a computer hard disk, as an added layer of the cache subsystem while operating.

The virtual memory is known for permitting processes and applications to utilize more memory than what is present physically in the main memory. Apart from that, it is also known for permitting virtual machines.

The operating system, on the other hand, assigns a virtual address space to the processes while supporting the virtual memory.

This purported virtual address is referred to by every process as an address while execution.

When the process needs to access a specific type of data such as variables or codes at that specific virtual address, it needs to translate it to a physical address. This is done by a process called virtual address translation.

However, in reality, the physical memory of the main system becomes the cache memory for the virtual memory. This is generally stored in the memory pages on the disk.

The programs are assigned a specific number of pages based on the requirements of the operating system. These are called active memory pages and are found both on the hard disk and in the RAM.

The inactive pages, on the other hand, are removed from the cache memory when the main memory gets filled up and are written to the disk.

When the process uses the whole main memory and needs more memory pages, a series of significant cache misses will happen.

These are referred to as page faults that result in a severe lag in the performance of the operating system and reduce its responsiveness.

When this process continues to happen alongside repetitive yet futile page swapping, disk thrashing sets in.

CPU utilization:

Ideally, disk thrashing may occur when the CPU performs less productive work and more swapping.

It mainly depends on the algorithms involved and the configuration, which affect the latency and throughput of the computer system.

This typically happens due to the degrading in the multiple orders of magnitude.

This increases the general memory access time mainly because the higher-level memory in the memory subsystem is only as fast as the subsequent lower level in the hierarchy.

This keeps the Central Processing Unit (CPU) of the computer system busy swapping pages.

This means that the CPU cannot respond to the interrupts and the user programs as much and as fast as required.

Read Also:  Why Does SSD Run Slow? (7 Fixes)

When there are too many pages existing in the memory, thrashing sets in, where every page has to refer to another page, slowing down the system eventually.

In such a state, the capacity of the main or real memory gets reduced, so much that it cannot accommodate all of the pages in it.

This leaves no other option but to use the virtual memory.

When every page in implementation demands a page which is not available currently in the real system memory, the CPU will place some of these pages on the virtual memory. the required page will be adjusted on the RAM.

When the CPU is engaged in this particular task more, its utilization is not as desired, and it results in thrashing.

How Do You Stop Thrashing?

The most effective and common way to stop disk thrashing and its effects is to allocate as many frames as required by each process during its operation.

You can find out the number of frames needed by using the locality model, which typically refers to the set of pages that are being actively used together.

A few other effective ways to eliminate or prevent disk thrashing and its negative impact on the hard drive as well as the overall performance of the computer system are as follows:

Read Also:  5 Ways to Fix Action Needed Prompt for Wi-Fi

Now, here are some of the things that you should certainly NOT DO in anticipation of fixing hard disk thrashing.

These are not only unhelpful but are also very dangerous for the hard drive as well as the computer system as a whole.

How Do You Detect Thrashing?

Since trashing is the result of the under apportionment of the lowest number of pages needed by a process that forces a continuous page fault, it can be detected easily by assessing the level of utilization of the Central Processing Unit and comparing it with the level of multiprogramming.

Ideally, there are two specific methods to detect disk thrashing.

Method 1:

(This will open the Resource Monitor on Windows 7 and Windows Vista)

Now, identify the particular process or file that is using the disk most.

Method 2:

Alternatively, you can visit the Sysinternals web site of Microsoft and download the Process Explorer from there. Once the download is complete and the tool starts running, follow these steps:

This will display the new columns for each listed process. Look for the specific process from the list that has the highest number of reads or read bytes. This is the process that may be killing your hard drive.

Once you have identified disk thrashing and the bad processes, you can then rectify it by using the Task Manager.

You can also detect disk thrashing in the following ways:

In short, general sluggishness and unusual lags of the computer while opening any item, application or menu indicates disk thrashing or high disk usage.

Typically, use your Task Manager and watch out for any process or file that takes an extended period of time to open, irrespective of its size.

All these are worth worrying, regardless of the impact on the performance it may have.

Conclusion

So, as this article has pointed out, disk thrashing can become a serious issue soon if you do not take care of it.

It will initially slow down your computer, and gradually may result in considerable wear and tear of the read/write heads while transferring data back and forth, resulting in a permanent failure of the hard disk.