Definition
Swapping
Swapping is a memory management technique in which the operating system moves entire processes between main memory (RAM) and secondary storage (disk). This is done to improve system performance when the number of active processes exceeds the available physical memory.
Mechanism
When main memory becomes over-utilised, the OS identifies processes that are currently inactive (typically those in the Blocked state) and “swaps them out” to a dedicated area on the disk called the swap space.
- Swap Out: Moving a process image from RAM to disk.
- Swap In: Moving a process image from disk back to RAM to resume execution.
This mechanism is the foundation of the Seven-State Process Model, which introduces the Suspended states to track swapped processes.
Causes for Swapping
The OS may decide to swap a process for several reasons:
- Memory Overload: Too many processes in the “Ready” state causing thrashing.
- Blocked State: A process waiting for a long-duration I/O event is a prime candidate for swapping to free up RAM.
- Parent Request: A parent process may request to suspend a child for debugging or coordination.
- Interactive Request: A user suspending a background job.