What is thrashing? Why does it occur?
Asked Answered
A

9

57

In an operating system, thrashing is something related to memory management. Why does thrashing occur? How can we prevent it?

I checked Wikipedia (but I need some simple understanding).

Allergic answered 26/9, 2013 at 15:6 Comment(3)
Read Galvin: High paging activity is called thrashing. A process is threshing if it is spending more time paging then executing.Pouliot
OK. Galvin is issued to us from library. I'll try to understand it from there also.Allergic
My suggestion is first read book, if you need further reference then use web. Otherwise you will wast your important time and efforts.Pouliot
T
66

In operating systems that implement a virtual memory space the programs allocate memory from an address space that may be much larger than the actual amount of RAM the system possesses. The OS is responsible for deciding which programs "memory" is in actual RAM. It needs a place to keep things while they are "out". This is what is called "swap space", as the OS is swapping things in and out as needed. When this swapping activity is occurring such that it is the major consumer of the CPU time, then you are effectively thrashing. You prevent it by running fewer programs, writing programs that use memory more efficiently, adding RAM to the system, or maybe even by increasing the swap size.

A page fault occurs when the memory access requested (from the virtual address space) does not map to something that is in RAM. A page must then be sent from RAM to swap, so that the requested new page can be brought from swap to RAM. As you might imagine, 2 disk I/Os for a RAM read tends to be pretty poor performance.

Terpsichore answered 26/9, 2013 at 15:13 Comment(5)
Is page fault also related to thrashing? Sorry I am new to OS.Allergic
@niss yes, it is dues to Global page replacement algo. one process snatch pages(memory) from other process. dues to paging activity (in input/ out unit) CPU becomes free. And OS monitor CPU utilization, if it is too two OS increases degree of multiprograming by allow new process to execute. Introducing new processes mean more page fault that causes further decreases CUP utilization. --that is called thrashing.Pouliot
@niss It is frequently asked question in interview. so learn it.Pouliot
One of the most precise and concise answers with a lot of info I have seen lately!Councilor
It might also be good to mention, the "thrashing" part essentially used to correlate with the needle on spinning disks, making a thrashing sound, as indicative of memory constantly hitting the swap, just to get a task done.Banas
S
20

Thrashing It is a state in which our CPU perform 'productive' work less and 'swapping' more. CPU is busy in swapping pages, so much that it can not respond to user program as much as required. Why it occurs In our system Thrashing occurs when there are too much pages in our memory, and each page referes t an other page. The real memory shortens in capacity to have all the pages in it, so it uses 'virtual memory'. When each page in execution demands that page that is not currently in real memory (RAM) it place some pages on virtual memory and adjust the required page on RAM. If CPU is so much busy in doing this task, thrashing occurs.

Sing answered 30/12, 2013 at 15:52 Comment(0)
F
15

I know this question has been asked long ago, but I just wanted to share information with others.

The term thrashing is actually related to the virtual memory, that an operating system uses in order to provide extra amount of memory or space for the processes. What does it actually mean by the term thrashing is that, when the process is ready to be loaded in the memory, only a few or some pages(parts) of the process are loaded in the actual physical memory, and the rest are in the swap space (the virtual memory or the disk).

Now if the page that the process needs to execute, is not loaded in the memory, it generates a page-fault and asks the OS to replace the page. Here the process resumes its execution.

Sometimes, the page replaced by the OS is again required by the process therefore it again asks the OS to load it in the memory, replacing some other page and so on. Since the process is not executing, therefore the CPU utilization is 0, However the disk read and write are at the peak.

Our OSs are designed in such a way that when the CPU utilization decreases it initiates another process in the memory. The next process have to wait now because the first process is busy. Again since the CPU is not being utilized or it is 0(in our example), the OS initiates another process, and the same thing happen.

Therefore, the CPU utilization decreases to an extreme minimum level, while the processes are busy reading and writing(swapping the pages). This is called thrashing!

Funke answered 5/4, 2015 at 14:29 Comment(0)
C
4

Logical addresses are generated by CPU which are in fact not real memory location but a process thinks that it is the actual memory location. A complete process is divided into different parts which are stored in pages in logical memory but only sub parts or only some pages are allocated actual memory for execution which are required at that point of time, whereas other pages reside in logical memory and are not allocated a physical address. Now if any other pages are required to load and there is not enough frame to allocate it to assign, an interrupt occurs which causes a page fault and a replacement algorithm is needed to remove some pages from frames and load the current page required.

Now suppose there are not enough frames to meet requirements for all the pages needed to be loaded. Then the frame removed will again demand to be loaded and again page fault will occur. This goes in loop. Meanwhile, since the process is not able to execute, CPU utilization will be low, and the dispatcher will load more processes in the CPU which degrades the scenario even more.

This process is known as thrashing. Thrashing generally occurs when enough frames are not allocated to a process than needed.

Ways to prevent thrashing:

  1. instruct mid-term scheduler to swap out some of the process too recover from thrashing
  2. instructing the dispatcher not to load more processes after a threshold
Cordwain answered 12/6, 2017 at 7:23 Comment(1)
Welcome to SO. Generally, if you add an answer to an older question with well established answers, you should make sure you provide distinctively new information in some shape or form. It's also worth splitting a block of text like (the original version of) your answer into multiple paragraphs.Gignac
H
0

In a virtual memory system, thrashing is the excessive swapping of pages of data between memory and the hard disk, causing the application to respond more slowly. The virtual memory function tracks page usage and keeps often-used pages in memory as much as possible.

Hyde answered 5/3, 2015 at 9:45 Comment(0)
A
0

Memory thrashing is a problem which arises when the memory is allocated more than the physical memory and it is not available in the system. To know what is thrashing, you must first be aware of swapping and page fault. So lets start with those concepts: Page Fault and Swapping :- A page fault occurs when the memory access requested (from the virtual address space) does not map to something that is in RAM. A page must then be sent from RAM to swap, so that the requested new page can be brought from swap to RAM. This results in 2 disk I/Os. Now you might know that disk I/Os are very slow as compared to memory access.

To know what is memory thrashing please refer to the following link :

http://www.firmcodes.com/memory-thrashing-in-operating-system/

Atom answered 1/12, 2015 at 16:4 Comment(3)
Linked article doesn't seem complete (seems to stop mid explanation). This answer itself doesn't add to other answers and while correct I don't think it is likely to help those who don't understand the key concepts already.Polypoid
please follow the link to get the details of memory thrashing.Atom
It isn't awful but it ends very abruptly with a (very) partial description of virtual memory and doesn't feel like a conclusion.Polypoid
I
0

The operating system uses the concept of virtual memory to provide memory to process at times when main memory get full and don't have space to provide space to incoming processes.This mechanism of using virtual memory as substitute memory is abstract and the user doesn't get to know what is going behind.It appears to the user that the new process which he/she executed just now got space in the main memory.

So,in order to accomodate incoming processes in main memory ,the idle processes residing in main memory need to be moved to virtual memory.This movement from main memory to virtual memory takes place when page fault occurs.

Now coming to thrashing.

If the operating system uses such a page replacement algo in which there is high probability for page fault to occur,then much of the CPU cycle will be wasted in swapping pages to and fro between main memory and virtual memory.This suppresses CPU performance.This process of degradation in CPU performance due to occurence of large number of page faults is called Thrashing.

Inspan answered 16/8, 2016 at 8:10 Comment(0)
A
0

Thrashing is a state in which our CPU perform 'productive' work less and 'swapping' more. CPU is busy in swapping pages, so much that it can not respond to user program as much as required. Why it occurs : In our system, Thrashing occurs when there are too much pages in our memory, and each page refers to another page. The real memory shortens in capacity to have all the pages in it, so it uses 'virtual memory'. When each page in execution demands that page that is not currently in real memory (RAM) it place some pages on virtual memory and adjust the required page on RAM. If CPU is so much busy in doing this task, thrashing occurs. To resolve thrashing you can do any of the suggestions below : *Increase the amount of RAM in the computer. *Decrease the number of programs being run on the computer. *Adjust the size of the swap file.

Aureomycin answered 7/12, 2016 at 6:53 Comment(0)
P
-4

If you want exactly what is thrashing right..

If C.P.U usage is 0(idle) then this situation called as Thrashing.

It will Occur At the time of Deadlock situation.so at that time no resources(like printers etc)will utilise C.P.U so it will be idle so we can call this situation as Thrashing.

thats it about Thrashing :)

Poilu answered 11/9, 2014 at 11:14 Comment(2)
This doesn't answer the question and is quite vague.Bribery
-4 essentially means if you delete your answer, i believe you will get 4 points :-) See the other answers for what the common meaning is. Thrashing is when its paging excessively, in most terms..Banas

© 2022 - 2024 — McMap. All rights reserved.