Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Thrashing (computer science)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Constant exchange between memory and storage}}In [[computer science]], '''thrashing''' occurs in a system with [[virtual memory]] when a computer's [[Computer memory|real storage]] resources are ''overcommitted'', leading to a constant state of [[paging]] and [[page fault]]s, slowing most [[Application software|application]]-level processing.<ref>{{cite journal|last = Denning | first = Peter J. | title = Thrashing: Its causes and prevention | journal= Proceedings AFIPS, Fall Joint Computer Conference |year = 1968 |url = http://www.cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/vm-and-gc/thrashing-denning-afips-1968.pdf | access-date = 2012-02-15 | pages = 915–922 | volume = 33}}</ref> This causes the [[Computer performance|performance of the computer]] to degrade or even collapse. The situation can continue indefinitely until the user closes some running applications or the active processes free up additional virtual memory resources. After initialization, most programs operate on a small number of code and data [[Memory paging|pages]] compared to the total memory the program requires. The pages most frequently accessed at any point are called the [[working set]], which may change over time. When the working set is not significantly greater than the system's total number of real storage ''page frames'', virtual memory systems work most efficiently, and an insignificant amount of computing is spent resolving page faults. As the total of the working sets grows, resolving page faults remains manageable until the growth reaches a critical point at which the number of faults increases dramatically and the time spent resolving them overwhelms the time spent on the computing the program was written to do. This condition is referred to as thrashing. Thrashing may occur on a program that randomly accesses huge data structures, as its large working set causes continual page faults that drastically slow down the system. Satisfying page faults may require freeing pages that will soon have to be re-read from disk. The term is also used for [[#Other uses|various similar phenomena]], particularly movement between other levels of the [[memory hierarchy]], wherein a process progresses slowly because significant time is being spent acquiring resources. "Thrashing" is also used in contexts other than virtual memory systems –for example, to describe [[Cache (computing)|cache]] issues in computing, or [[silly window syndrome]] in networking. ==Overview== [[Virtual memory]] works by treating a portion of [[secondary storage]] such as a computer [[hard disk]] as an additional layer of the [[cache hierarchy]]. Virtual memory allows [[Process (computing)|processes]] to use more memory than is physically present in [[Random-access memory|main memory]]. Operating systems supporting virtual memory assign processes a [[virtual address space]] and each process refers to [[Address (computing)|addresses]] in its [[execution context]] by a so-called virtual address. To access [[Data (computing)|data]] such as [[Machine code|code]] or [[Variable (computer science)|variables]] at that address, the process must translate the address to a [[physical address]] in a process known as [[virtual address translation]]. In effect, physical main memory becomes a [[Cache (computing)|cache]] for virtual memory, which is in general stored on disk in [[Page (computer memory)|memory pages]]. Programs are allocated a certain number of pages as needed by the [[operating system]]. Active memory pages exist in both RAM and on disk. Inactive pages are [[Cache replacement policies|removed from the cache]] and [[Write-back|written to disk]] when the main memory becomes full. If processes are utilizing all main memory and need additional memory pages, a cascade of severe [[cache miss]]es known as [[page fault]]s will occur, often leading to a noticeable [[Latency (engineering)|lag]] in the operating system [[responsiveness]]. This process together with the futile, repetitive page swapping that occurs is known as "thrashing". This frequently leads to high, runaway CPU utilization that can grind the system to a halt. In modern computers, thrashing may occur in the paging system (if there is not sufficient [[physical memory]] or the disk access time is overly long), or in the I/O communications subsystem (especially in [[Bus contention|conflicts over internal bus access]]), etc. Depending on the configuration and algorithms involved, the [[throughput]] and [[Latency (engineering)|latency]] of a system may degrade by multiple [[Computer performance by orders of magnitude|orders of magnitude]]. Thrashing is when the CPU performs 'productive' work less and 'swapping' work more. The overall memory access time may increase since the higher level memory is only as fast as the next lower level in the memory hierarchy.<ref>{{Cite book|title=Computer architecture: a quantitative approach|last=L.|first=Hennessy, John|date=2012|publisher=Morgan Kaufmann|others=Patterson, David A., [[Asanović, Krste]].|isbn=9780123838728|edition= 5th|location=Waltham, MA|oclc=755102367}}</ref> The CPU is busy swapping pages so much that it cannot respond to users' programs and interrupts as much as required. Thrashing occurs when there are too many pages in memory, and each page refers to another page. Real memory reduces its capacity to contain all the pages, so it uses 'virtual memory'. When each page in execution demands that page that is not currently in real memory (RAM) it places some pages on virtual memory and adjusts the required page on RAM. If the CPU is too busy doing this task, thrashing occurs. ===Causes=== In [[virtual memory]] systems, thrashing may be caused by programs or workloads that present insufficient [[locality of reference]]: if the [[working set]] of a program or a workload cannot be effectively held within physical memory, then constant data swapping, ''i.e.,'' thrashing, may occur. The term was first used during the tape operating system days to describe the sound the tapes made when data was being rapidly written to and read. A worst case might occur on [[VAX]] processors. A single <code>MOVL</code> crossing a page boundary could have a source operand using a displacement deferred addressing mode, where the longword containing the operand address crosses a page boundary, and a destination operand using a displacement deferred addressing mode, where the longword containing the operand address crosses a page boundary, and the source and destination could both cross page boundaries. This single instruction references ten pages; if not all are in RAM, each will cause a page fault. The total number of pages thus involved in this particular instruction is ten, and all ten pages must be simultaneously present in memory. If any one of the ten pages cannot be [[Paging|swapped in]] (for example to make room for any of the other pages), the instruction will fault, and every attempt to restart it will fail until all ten pages can be swapped in. A system thrashing is often a result of a sudden spike in page demand from a small number of running programs. Swap-token<ref>{{Cite conference |author= Song Jiang, and Xiaodong Zhang | title="Token-ordered LRU: an effective page replacement policy and its implementation in Linux systems" |conference=Performance Evaluation| year=2005 |pages = 5–29|doi=10.1016/j.peva.2004.10.002}}</ref> is a lightweight and dynamic thrashing protection mechanism. The basic idea is to set a token in the system, which is randomly given to a process that has page faults when thrashing happens. The process that has the token is given a privilege to allocate more physical memory pages to build its working set, which is expected to quickly finish its execution and release the memory pages to other processes. A timestamp is used to hand over the tokens one by one. The first version of swap-token is implemented in Linux[http://fxr.watson.org/fxr/source/mm/thrash.c?v=linux-2.6 .] The second version is called preempt swap-token[https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7602bdf2fd14a40dd9b104e516fdc05e1bd17952 .] In this updated swap-token implementation, a priority counter is set for each process to track the number of swap-out pages. The token is always given to the process with a high priority, which has a high number of swap-out pages. The length of the time stamp is not a constant but is determined by the priority: the higher the number of swap-out pages of a process, the longer the time stamp for it will be. ==Other uses== Thrashing is best known in the context of memory and storage, but analogous phenomena occur for other [[System resource|resources]], including: ;{{visible anchor|Cache thrashing}} :Where main memory is accessed in a pattern that leads to multiple main memory locations competing for the same cache lines, resulting in excessive [[CPU cache#Cache miss|cache misses]]. This is most likely to be problematic for caches with [[CPU cache#Associativity|associativity]]. ;{{visible anchor|TLB thrashing}} :Where the [[translation lookaside buffer]] (TLB) acting as a cache for the [[memory management unit]] (MMU) which translates virtual addresses to physical addresses is too small for the working set of pages. TLB thrashing can occur even if instruction cache or data cache thrashing is not occurring because these are cached in different sizes. Instructions and data are cached in small blocks ([[cache line]]s), not entire pages, but address lookup is done at the page level. Thus even if the code and data working sets fit into the cache, if the working sets are [[Fragmentation (computing)|fragmented]] across many pages, the virtual address working set may not fit into TLB, causing TLB thrashing. ;{{visible anchor|Heap thrashing}} :Frequent [[garbage collection (computer science)|garbage collection]], due to failure to allocate memory for an object, due to insufficient free memory or insufficient contiguous free memory due to [[Fragmentation (computing)|memory fragmentation]] is referred to as heap thrashing.<ref>''Performance Optimization and Tuning Techniques for IBM Processors, including IBM POWER8'', [https://books.google.com/books?id=oxUBBAAAQBAJ&pg=PA170&dq="heap+thrashing" p. 170]</ref> ;{{visible anchor|Process thrashing}} :A similar phenomenon occurs for processes: when the [[process working set]] cannot be [[Coscheduling|coscheduled]], i.e. such that not all interacting processes are scheduled to run at the same time, they experience "process thrashing" due to being repeatedly scheduled and unscheduled, progressing only slowly.<ref>{{cite news |author-link=John Ousterhout |first=J. K. |last=Ousterhout |url=https://web.stanford.edu/~ouster/cgi-bin/papers/coscheduling.pdf |title=Scheduling Techniques for Concurrent Systems |journal=Proceedings of Third International Conference on Distributed Computing Systems |year=1982 |pages=22–30 }}</ref> == See also == {{wikisource |The Paging Game}} * {{annotated link|Page replacement algorithm}} * {{annotated link|Congestion collapse}} * {{annotated link|Resource contention}} * {{annotated link|Out of memory}} * {{annotated link|Software aging}} ==References== {{reflist}} [[Category:Virtual memory]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Annotated link
(
edit
)
Template:Cite book
(
edit
)
Template:Cite conference
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite news
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Visible anchor
(
edit
)
Template:Wikisource
(
edit
)