Thrashing in Operating System (OS)

Thrashing in Operating System

Thrashing in Operating System

First we need to know what actually happens inside your OS that makes your system behave as if it has a very large memory. 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. OS decides which program’s memory is actually in RAM at any specific instant of time.

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.

Thrashing in Operating System

Thrashing in Operating System

Now if it happens that your system has to swap pages at such a higher rate that major chunk of CPU time is spent in swapping then this state is known as thrashing. So effectively during thrashing, the CPU spends less time in some actual productive work and more time in swapping.

While processing page faults it is necessary to be in order to appreciate the benefits of virtual memory, thrashing has a negative effect on the system.As the page fault rate increases, more transactions need processing from the paging device.

While the transactions in the system are waiting for the paging device, CPU Utilization, system throughput and system response timedecrease, resulting in below optimal performance of a system.

Cause of Thrashing

  1.  High degree of multiprogramming:
    The CPU scheduler sees the decreasing CPU utilization and increases the degree of multiprogramming as a result. The new process tries to get started by taking frames from running processes, causing more page faults and a longer queue for the paging device. As a result, CPU utilization drops even further, and the CPU scheduler tries to increase the degree of multiprogramming even more

     

  2. Lack of frames:-
    If  a process has less number of frames then less pages of that process will be able to reside in memory and hence it would result in more frequent swaping. This may lead to thrashing. Hence sufficient amount of frames must be allocated .
 
 

Recovery

  • Do not allow the system to go into thrashing by instructing the long term scheduler not to bring the processes into memory after the threshold.
  • If the system is already in thrashing then instruct the mid term schedular to suspend some of the processes so that we can recover the system from thrashing.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

Summary
Review Date
Reviewed Item
Trashing
Author Rating
51star1star1star1star1star