
- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- OS - TAT & WAT
- OS Processes
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling Algorithms
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithms
- HRRN Scheduling Algorithms
- Priority Scheduling Algorithms
- Multilevel Queue Scheduling
- Context Switching
- Operations on Processes
- Lottery Process Scheduling
- Predicting Burst Time SJF Scheduling
- Race Condition Vulnerability
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Process Control Block
- Inter Process Communication
- Preemptive and Non-Preemptive Scheduling
- Operating System - Deadlock
- Introduction to Deadlock in Operating System
- Conditions for Deadlock in Operating System
- OS Synchronization
- Operating System - Process Synchronization
- Operating System - Critical Section
- Operating System - Semaphores
- Operating System - Counting Semaphores
- Operating System - Mutex
- Operating System - Turn Variable in Process Synchronization
- Operating System - Bounded Buffer Problem
- Operating System - Reader Writer Locks in Process Synchronization
- Operating System - Test Set Lock in Process Synchronization
- Operating System - Peterson Solution in Process Synchronization
- Operating System - Monitors in Process Synchronization
- Operating System - Sleep and Wake in Process Synchronization
- OS Memory Management
- OS - Memory Management
- OS - Virtual Memory
- OS - Paging
- OS - Demand Paging
- OS Storage Management
- File Systems in Operating System
- Linked Index Allocation in Operating System
- Indexed Allocation in Operating System
- Structures of Directory in Operating System
- File Attributes in Operating System
- Operating System - Page Replacement
- Operating Systems - Thrashing
- Optimal Page Replacement Algorithm
- Operating System - Types
- Types of Operating System
- Batch Processing Operating System
- Multiprocessing Operating System
- Hybrid Operating System
- Monolithic Operating System
- Zephyr Operating System
- Nix Operating System
- Blackberry Operating System
- Garuda Operating System
- Tails Operating System
- Clustered Operating System
- Haiku Operating System
- AIX Operating System
- Solus Operating system
- Tizen Operating System
- Bharat Operating System
- Fire Operating System
- Bliss Operating System
- VxWorks Operating System
- Embedded Operating System
- Single User Operating System
- OS Miscellaneous
- OS - Multi-threading
- OS - I/O Hardware
- OS - I/O Software
- OS - Security
- OS - Linux
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Operating System - Thrashing
Thrashing is a performance issue in virtual memory systems due to multiple page faults during demand paging. We already learned about paging and demand paging in the earlier chapters. In this chapter, we will explain thrashing, how it occurs, and how to prevent it. Following topics will be covered in this chapter −
- What is Thrashing?
- What Causes Thrashing?
- Degree of Multiprogramming and Thrashing
- How to Detect Thrashing?
- How to Prevent Thrashing?
What is Thrashing?
Thrashing is a condition in which the system spends most of the time swapping pages in and out of physical memory (RAM) instead of executing actual processes. This happens when there is no enough physical memory to hold all the active pages of all the processes that are currently running. In simpler terms, thrashing occurs when the size of your RAM is less than the size of the processes being executed.
What Causes Thrashing?
The main reason for thrashing is overloading the system with too many processes. Technically, the reasons for thrashing can be listed as follows −
- High Degree of Multiprogramming − The degree of multiprogramming refers to the number of processes that are kept in memory at the same time. If this value increase too much, it can cause thrashing.
- Improper Page Replacement Algorithms − The page replacement algorithm decides which pages to swap out when a page fault occurs. Poorly designed algorithms like FIFO can cause frequent page faults, which can lead to thrashing.
- Less Physical Memory − If the physical memory (RAM) is too small to hold the working set of all active processes, then thrashing can occur.
Degree of Multiprogramming and Thrashing
The degree of multiprogramming is the number of processes that are kept in memory at the same time. It is very closely related to thrashing. The following graph shows how CPU utilization changes with the degree of multiprogramming −

Initially, when the degree of multiprogramming increases, the utilization of CPU and other resources also increases. This will lead to better performance. However, after a certain point, if the degree of multiprogramming continues to increase, the thrashing will start. So for every system, there is an optimal degree of multiprogramming that have maximum CPU utilization without thrashing.
The operating system always aims to find the optimal degree of multiprogramming. When thrashing begins, the performance of the system starts to degrade. So the OS will starts to reduce the degree of multiprogramming by swapping out some processes from memory to disk. This way the system can return to a state of optimal performance.
How to Detect Thrashing?
To detect thrashing, the operating system uses working set model introduced by Peter Denning. For each process the OS keeps track of the pages it is currently using, known as its working set (W(t, Δ)). Where,
- t is the current time.
- Δ is window size (number of recent references).
- W(t, Δ) is the set of pages that a process has referenced in the time interval (t - Δ, t).
If the total size of the working sets of all processes in the system is more than the available physical memory, then thrashing will occur. For example, if a process has a working set of 10 pages and there are 5 such processes in the system, then the total working set size is 50 pages. If the physical memory can only hold 40 pages, then thrashing will occur.
The operating system also monitors the following metrics to detect thrashing −
- Page Fault Rate − If number of page faults occurring at each second is very high, then it indicates that the system is thrashing.
- CPU Utilization − If the CPU utilization is very low, then this might indicates that the system is thrashing.
How to Prevent Thrashing?
To prevent thrashing, the operating system can implement the following strategies −
1. Local Page Replacement
The local page replacement refers to a restricting processes from using frames that belong to other processes. This will prevent one process from causing thrashing in others. If you are using global page replacement, then a process can use any free frame in the system. This will lead to thrashing if one process starts using too many frames.
In local page replacement, each process is allocated a fixed number of frames. If a process needs more frames, it must wait until some of its own frames are freed up. This way, the operating system can ensure that no any big process will consume all the memory and cause thrashing.
2. Working Set Model
The working set model helps the operating system to keep track of the pages that a process is currently using. By monitoring the working set of each process, the OS can calculate the total working set size of all processes in the system. If this size exceeds the available physical memory, then the OS can take action to reduce the degree of multiprogramming. This is done by swapping out some processes from memory to disk.
3. Page-Fault Frequency (PFF) Scheme
The page-fault frequency (PFF) scheme is another method to control thrashing. In this scheme, the operating system monitors the page-fault rate of each process and adjusts the number of frames allocated to it based on its page-fault rate. For example,
- If page faults are too high → Allocate more frames.
- If page faults are too low → Deallocate some frames.
By this way, the OS can adjust the number of frames allocated to each process based on its current needs. Meaning, this will prevent thrashing by ensuring that each process has enough frames to hold its working set.
Conclusion
Thrashing is a serious performance issue in virtual memory systems. It occurs when the system spends more to swap process pages in and out of memory than executing actual processes. The main causes of thrashing are less physical memory(RAM), high degree of multiprogramming, and improper page replacement algorithms. To prevent thrashing, the operating system can implement strategies such as local page replacement, working set model, and page-fault frequency scheme.