Log in Sign up
Back to Discover
💻

Thrashing (computer science)

technology Maturity 11-13

A computer can get very slow. This happens when it has too much work. It spends all its time moving things around. It cannot finish its jobs. You can close some apps to help. Does your computer ever act slow?

40 words

A computer can get very slow. This happens when it has too much work. It needs to use its main memory to run programs. But sometimes, it runs out of room.

The computer moves data to a disk to save space. This is like moving books to a big box. When the computer needs a book, it must swap it back. If it does this too much, it slows down. This is called thrashing.

The computer spends all its time swapping data. It does not have time to do its real jobs. The computer may even stop working.

You can help by closing some apps. This gives the computer more room to work. It makes the computer fast again.

121 words

A computer uses a part called RAM to hold data. This is its real memory. Sometimes, a computer runs out of RAM. It uses a trick called virtual memory to help. It moves data to a hard disk to save space. This is called paging.

When a program runs, it uses a group of data pages. This group is called a working set. If the working set is too big, the computer struggles. It must move data back and forth from the disk. This constant swapping is called thrashing.

During thrashing, the computer spends more time moving data than doing work. The CPU, which is the computer's brain, stays very busy. However, it is only busy with swapping. This makes the computer feel very slow. It may even stop working well.

This can happen if a program looks at data in a random way. It can also happen if many programs need memory at once. You can fix thrashing by closing some apps. This frees up memory. This lets the computer focus on its real jobs again.

177 words

Computers use a special trick to handle many tasks at once. They use real memory called RAM to hold active data. When RAM gets too full, the computer uses virtual memory. This uses a hard disk as an extra layer of storage. This process is called paging or swapping. It moves data pages from the RAM to the disk. This helps programs use more memory than is physically there. But sometimes, this system runs into a big problem. This problem is called thrashing.

Thrashing happens when the computer spends too much time swapping. A program has a group of important pages called a working set. The computer works best when this set fits in the RAM. If the working sets grow too large, page faults occur. A page fault happens when the computer needs a page not in the RAM. The system must find that page on the disk. It then moves a different page to the disk to make room. If this happens constantly, the computer enters a state of thrashing. The CPU spends more time moving data than doing real work.

People have used this word for a long time. It started during the days of tape operating systems. Back then, it described the sound tapes made during rapid reading and writing. In the past, it could even happen on VAX processors. One specific instruction could require ten different pages to be in the RAM at once. If even one page was missing, the instruction would fail. This could cause the system to struggle deeply.

Engineers have found ways to protect systems from this. One method is called a swap-token. This is a lightweight tool used to stop thrashing. A token is given to a process that has many page faults. This process gets the privilege to use more physical memory. This helps it finish its job and release memory for others. The first version of this was put into Linux. A newer version is called the preempt swap-token. It uses a priority counter to give tokens to the right processes.

Thrashing is not just about main memory. It can happen in other parts of a computer too. It can occur in the cache, which is a very fast storage area. It can also happen in the TLB, which helps translate addresses. Even networking can experience a similar issue called silly window syndrome. You might see your computer slow down if it is thrashing. You can often fix it by closing some running applications. This frees up the memory resources the computer needs to work properly.

433 words

In computer science, thrashing describes a state where a computer system spends more time moving data than doing actual work. This happens within the memory paging system when a computer's real memory, known as RAM, is overcommitted. RAM is the physical storage used for active data. When RAM is full, the operating system uses virtual memory to allow processes to use more memory than is physically present. It does this by treating a portion of secondary storage, like a hard disk, as an extra layer of the memory hierarchy. Thrashing causes the performance of the computer to degrade significantly or even collapse entirely.

To understand how this happens, we must look at how memory paging works. The operating system assigns each process a virtual address space. To access data, the system must perform virtual address translation. This translates a virtual address into a physical address in the RAM. Physical main memory essentially acts as a cache for the virtual memory stored on the disk. Active memory pages exist in both RAM and on the disk. When the main memory becomes full and a process needs a new page, a page fault occurs. A page fault is a cascade of cache misses where the system must retrieve data from the disk. If the system must constantly move pages to the disk to make room for new ones, it enters a state of thrashing.

Every program has a specific requirement called a working set. This is the collection of code and data pages that a program accesses most frequently at any given time. When the total size of all active working sets is smaller than the total number of real storage page frames, the system works efficiently. In this state, the amount of computing spent resolving page faults is very small. However, if the working sets grow beyond the capacity of the RAM, the number of page faults increases dramatically. This leads to a cycle where satisfying a page fault requires freeing a page that will be needed again almost immediately. The CPU becomes so busy swapping these pages that it cannot respond to user programs or interrupts.

Historically, the term "thrashing" has different origins. It was first used during the era of tape operating systems. It described the actual sound that magnetic tapes made when they were being rapidly read from and written to. In older hardware, such as VAX processors, thrashing could reach extreme levels. For example, a single MOVL instruction could potentially reference ten different pages if it used certain addressing modes. If even one of those ten pages was not in the RAM, the instruction would fault. The system would then attempt to restart the instruction, but it would fail again unless all ten pages could be held in memory simultaneously.

Modern systems use specific mechanisms to protect against this performance collapse. One such method is called a swap-token. This is a lightweight and dynamic protection mechanism. When thrashing is detected, a token is randomly given to a process experiencing page faults. This token grants that process the privilege to allocate more physical memory pages to build its working set. The goal is for that process to finish its execution quickly and release its memory to others. The first version of this was implemented in Linux. A newer version is called the preempt swap-token, which uses a priority counter to give tokens to processes with a high number of swap-out pages.

Thrashing is not limited to main memory paging; it can occur in other areas of a computer's architecture. One type is cache thrashing, which happens when memory access patterns cause multiple locations to compete for the same cache lines. This often involves a lack of locality of reference. Another form is TLB thrashing. The Translation Lookaside Buffer, or TLB, acts as a cache for the memory management unit. If the working set of pages is too large for the TLB, the system will struggle even if the data fits in the main cache. There is also heap thrashing, which occurs when frequent garbage collection happens because the system cannot allocate enough contiguous free memory.

Ultimately, thrashing represents a breakdown in the efficiency of the memory hierarchy. When the CPU performs "productive" work less and "swapping" work more, the system's throughput and latency can degrade by multiple orders of magnitude. This can happen in the paging system or even in the I/O communications subsystem due to internal bus access conflicts. While it is a complex technical failure, it is often a direct result of a sudden spike in page demand. For a user, the most effective way to resolve thrashing is to close running applications to free up the vital RAM resources the system requires.

787 words
Up Next
💻
Working set
Technology
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.