1. Introduction

Virtual memory and demand paging improve memory utilization by loading pages only when required. However, if memory becomes overcommitted, the system may spend most of its time handling page faults instead of executing useful work.

This condition is known as Thrashing.

Thrashing is one of the most serious performance problems in virtual memory systems because it causes dramatic degradation in system throughput and responsiveness.

2. What is Thrashing?

Thrashing is a condition in which the page fault rate becomes extremely high, causing the operating system to spend most of its time swapping pages between RAM and disk rather than executing processes.

Key Idea

High Page Fault Rate

↓

Frequent Disk I/O

↓

Less CPU Execution

↓

Poor Performance

3. Why Thrashing Occurs

Virtual memory assumes that a process needs only a small portion of its pages at any given time.

When this assumption fails:

  • Too many pages are missing from memory

  • Constant page faults occur

  • Continuous page replacement becomes necessary

Eventually:

System Busy

↓

But Little Useful Work Done

4. Basic Scenario

Suppose:

RAM Capacity = Limited

The system loads:

P1
P2
P3
P4
P5

simultaneously.

Each process receives only a few frames.

As execution continues:

Required Page Missing

↓

Page Fault

↓

Load New Page

↓

Replace Existing Page

↓

Another Fault

This cycle repeats continuously.

5. Step-by-Step Thrashing Process

Step 1

System increases multiprogramming.

More Processes

↓

Less Memory Per Process

Step 2

Processes lose important pages.

Working Pages Removed

Step 3

Page faults increase.

Missing Pages

↓

Page Faults

Step 4

Operating system performs excessive page replacement.

Disk ↔ RAM Transfers

Step 5

CPU waits for disk operations.

CPU Idle

↓

Disk Busy

Step 6

Overall performance collapses.

6. Core Cause of Thrashing

The primary cause of thrashing is:

Insufficient Physical Memory

for the active processes.

Important Insight

Thrashing is usually caused by:

Memory Shortage

not

CPU Shortage

7. Relationship with Page Faults

Normal demand paging:

Occasional Page Faults

↓

Good Performance

Thrashing:

Continuous Page Faults

↓

Poor Performance

Key Observation

Page fault handling requires:

  • Trap to OS

  • Disk access

  • Page loading

  • Page table update

These operations are thousands of times slower than normal memory access.

8. Locality of Reference

Programs typically exhibit:

Temporal Locality

Recently used pages are likely to be used again.

Spatial Locality

Nearby pages are likely to be accessed.

These properties allow virtual memory to work efficiently.

9. Thrashing and Locality

During thrashing:

Important Pages Removed

↓

Locality Destroyed

↓

More Faults

The process cannot keep its actively used pages in memory.

10. Degree of Multiprogramming

The degree of multiprogramming refers to:

Number of Processes in Memory

Low Multiprogramming

Fewer Processes

↓

More Frames Per Process

↓

Lower Fault Rate

High Multiprogramming

More Processes

↓

Fewer Frames Per Process

↓

Higher Fault Rate

11. Thrashing Cycle

A dangerous feedback loop can occur:

Page Fault Rate Increases

↓

CPU Utilization Drops

↓

OS Thinks CPU Underutilized

↓

Adds More Processes

↓

Even Fewer Frames Available

↓

More Page Faults

↓

More Thrashing

This further worsens performance.

12. Symptoms of Thrashing

Common indicators include:

  • Extremely high page fault rate

  • Low CPU utilization

  • Heavy disk activity

  • Slow response time

  • Reduced throughput

Important Observation

CPU Usage Low

Disk Usage High

often indicates thrashing.

13. Thrashing vs Normal Paging

FeatureNormal PagingThrashing
Page Fault RateLowVery High
CPU UtilizationHighLow
Disk ActivityModerateExcessive
PerformanceGoodPoor
ThroughputHighVery Low

14. Working Set Model

One of the most important solutions to thrashing is the Working Set Model.

15. What is a Working Set?

A working set is the collection of pages that a process is actively using during a particular time interval.

Key Idea

Currently Needed Pages

=

Working Set

16. Example of Working Set

Suppose a process repeatedly accesses:

Page 2
Page 3
Page 4
Page 7

Then:

Working Set = {2,3,4,7}

These pages should remain in memory.

17. Working Set Principle

If the operating system provides enough frames to hold the working set:

Low Page Faults

↓

Good Performance

If not:

Working Set Broken

↓

Thrashing

18. Working Set Strategy

Operating system estimates:

Working Set Size

for each process.

Then:

Allocate Sufficient Frames

↓

Maintain Locality

↓

Prevent Thrashing

19. Page Fault Frequency (PFF) Method

Another common technique is the Page Fault Frequency Method.

20. Basic Idea of PFF

Monitor page fault rate continuously.

If Fault Rate Too High

Allocate More Frames

If Fault Rate Too Low

Remove Some Frames

This dynamically adjusts memory allocation.

21. PFF Strategy

High Fault Rate

↓

Needs More Memory

↓

Increase Frames
Low Fault Rate

↓

Excess Memory Allocated

↓

Reduce Frames

22. Preventing Thrashing

Several techniques can be used.

22.1 Reduce Degree of Multiprogramming

Fewer Processes

↓

More Memory Per Process

Some processes may be suspended temporarily.

22.2 Use Working Set Model

Maintain sufficient pages for each process.

22.3 Use Page Fault Frequency Control

Monitor and adjust allocations dynamically.

22.4 Increase Physical Memory

Add more RAM.

22.5 Better Page Replacement Algorithms

Algorithms such as:

  • LRU

  • Optimal (theoretical)

  • Clock Algorithm

help reduce unnecessary faults.

23. Thrashing and Page Replacement

Poor page replacement can worsen thrashing.

Example:

Page Loaded

↓

Immediately Removed

↓

Needed Again

↓

Another Fault

This creates unnecessary disk activity.

24. System-Level Impact

Thrashing causes:

Reduced Throughput

Fewer processes complete.

Increased Response Time

Applications become slow.

Resource Wastage

CPU waits for disk operations.

Poor User Experience

System appears frozen or sluggish.

25. Thrashing vs Swapping

FeatureSwappingThrashing
PurposeMemory managementPerformance problem
FrequencyOccasionalContinuous
System HealthNormalPoor
Disk ActivityModerateExcessive

26. Real-World Analogy

Imagine ten students sharing a small study desk.

Need Book A

↓

Remove Book B

↓

Need Book B Again

↓

Remove Book A

↓

Repeat

Students spend more time moving books than studying.

This is exactly what happens during thrashing.

Most Important Point

Thrashing occurs when processes do not receive enough frames to maintain their working sets, causing continuous page faults and severe performance degradation.