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).
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).
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.
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.
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!
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:
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.
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/
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.
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.
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 :)
© 2022 - 2024 — McMap. All rights reserved.