What is Thrashing in an Operating System

Thrashing (computer science) - Thrashing (computer science)

The computer constantly exchanges data between memory and storage and leaves little capacity for productive processing

In computer science occurs Thrashing occurs when a computer's virtual memory resources are overloaded, resulting in a constant state of paging and page faults, and most of all preventing application-level processing. This causes the computer's performance to deteriorate or break down. The situation can continue indefinitely until either the user closes some running applications or the active processes free additional virtual memory resources.

After the initialization is complete, most programs operate with a small number of pages of code and data compared to the total memory required by the program. The pages that are most frequently accessed are called the working set.

When the working set is a small percentage of the total number of pages in the system, virtual storage systems operate most efficiently and there is little computational effort required to fix page faults. As the working set grows, page fault fixes remain manageable until growth reaches a critical point. Then the errors increase dramatically and the time spent fixing them overwhelms the time spent calculating the program. This condition is known as thrashing. Thrashing occurs with a program that works with huge data structures because its large working set causes continuous page faults that drastically slow the system down. To fix page faults, it may be necessary to reclaim pages that will soon need to be reread from disk.

The term is also used to refer to various similar phenomena, particularly movements between other levels of the storage hierarchy where a process moves slowly due to the large amount of time spent procuring resources.

"Thrashing" is also used in contexts other than virtual storage systems. For example, to describe cache problems in computing or the stupid window syndrome in networking.


Virtual memory works by treating part of secondary memory, such as a computer hard drive, as an additional layer in the cache hierarchy. Virtual memory is characterized by the fact that processes can use more memory than is physically available in main memory and that virtual machines are activated. Operating systems that allocate the virtual memory allocate a virtual address space to processes, and each process refers to addresses in its execution context through what is known as a virtual address. In order to be able to access data such as code or variables at this address, the process must translate the address into a physical address in a process known as virtual address translation. In fact, the physical main memory becomes a cache for the virtual memory, which is generally stored in memory pages on the hard disk.

Depending on the operating system, the programs are assigned a certain number of pages. Active memory pages are available both in RAM and on the hard disk. Inactive pages are removed from the cache and written to disk when main memory is full.

When processes consume all of the main memory and require additional pages of memory, a cascade of fatal cache errors known as page faults occurs and often results in a noticeable delay in the responsiveness of the operating system. This process, together with the futile, repetitive exchange of pages, is known as "thrashing". This often results in high, out of control CPU usage that can bring the system to a standstill. In modern computers, thrashing can occur in the paging system (if there is insufficient physical memory or if the disk access time is too long) or in the I / O communications subsystem (especially if there is a conflict over internal bus access), etc.

Depending on the configuration and the algorithms involved, the throughput and latency of a system can deteriorate by several orders of magnitude. Thrashing is a state in which the CPU does less "productive" work and "exchanges" more. The total memory access time can increase because the memory of the higher level is only as fast as the next lower level in the memory hierarchy. The CPU is busy swapping pages so often that it cannot respond to and pause user programs as often as needed. Thrashing occurs when there are too many pages in memory and each page points to a different page. The real memory becomes shorter so that all the pages are in it, so the virtual memory is used. If every page in execution needs that page that is not currently in real memory (RAM), some pages are put in virtual memory and the required page in RAM is adjusted. If the CPU is too busy doing this, thrashing will occur.


In virtual storage systems, thrashing can be caused by programs or workloads that have insufficient reference locality: If the working set of a program or a workload cannot be effectively kept in physical memory, constant data exchange, ie Thrashing, occur. The term was first used during the days of the tape operating system to describe the tone the tapes made while writing and reading data quickly. A worst-case scenario of this nature on the IBM System / 370 series mainframe computer could be an execute instruction that crosses a page boundary, that references a move instruction itself, that also crosses a page boundary, and itself to a source and destination shows which page limits are exceeded in each case. The total number of pages thus involved in this particular instruction is eight, and all eight pages must be in memory at the same time. If any of the eight pages cannot be swapped (for example, to make room for one of the other pages) the instruction will fail and any attempt to restart it will fail until all eight pages can be swapped.

Other uses

Thrashing is best known in the context of memory and storage, but analogous phenomena occur for other resources including:

Cache thrashing

When main memory is accessed in a pattern that results in multiple main memory locations competing for the same cache lines, resulting in excessive cache errors. This is most problematic for caches with low associativity.

Beat up TLB

When the Translation Lookaside Buffer (TLB), which acts as a cache for the memory management unit (MMU) that translates virtual addresses into physical addresses, is too small for the working set of pages. TLB thrashing can occur even if command or data cache thrashing is not occurring, as these are cached in different sizes. Instructions and data are cached in small blocks (cache lines), not in whole pages, but the address lookup is done at the page level. Even if the code and data working sets fit in the cache and the working sets are fragmented over many pages, the virtual address working set may not fit in the TLB, resulting in TLB thrashing.

Beat up heaps

Frequent garbage collection, due to an error in allocating memory for an object, due to insufficient free memory or insufficient contiguous free memory due to memory fragmentation, is known as heap thrashing.

Beat up the process

A similar phenomenon occurs with processes: If the process work set cannot be planned together - therefore not all interacting processes should be executed at the same time - "process thrashing" occurs because they are planned repeatedly and not planned and only progress slowly.

See also