Swapping
Unit-3
By
UMESH PRASAD ROUT
Swapping
● Swapping is a memory management technique where the OS
temporarily moves processes (or parts of processes) from
RAM (main memory) to disk (swap space) and vice versa to
free up memory for other tasks.
● This process helps to manage the limited amount of physical
RAM, allowing the system to run more programs than it could
otherwise hold simultaneously, or to accommodate processes
that are larger than the available physical memory.
2
Swapping Process
The process of swapping
involves two main operations:
1. Swap-Out
2. Swap-In
3
Swapping Process
1. Swap-Out (or Paging-Out):
● The selected data (entire process, or specific pages/segments of a process) is
written from RAM to the swap space on the secondary storage.
● Once the data is written to swap space, the corresponding memory frames in RAM
are freed up and become available for other processes.
2. Swap-In (or Paging-In):
● At some later time, when a swapped-out process (or part of it) needs to be
executed again, the operating system brings it back into main memory.
● The data is read from the swap space on secondary storage and loaded back into
available RAM frames.
4
Advantages of Swapping
1. Increased Multiprogramming Degree : Allows more processes to reside (at least partially)
in memory, leading to better CPU utilization. The OS can run many programs concurrently,
even if their combined memory requirements exceed physical RAM.
2. Supports Large Processes : Enables the execution of processes that are larger than the
available physical memory. Only the active parts of the process need to be in RAM at any
given time.
3. Prevents System Crashes : Avoids "Out of Memory" errors by moving idle processes to
disk.
4. Supports Virtual Memory : Creates the illusion of a larger amount of available memory
(virtual memory) than the physical RAM actually present. This helps in efficient utilization of
RAM by relocating inactive data to disk.
5. Improves Responsiveness : Critical processes stay in RAM, while less important ones
swap out.
5
Disadvantages of Swapping
1. Slower Performance : Secondary storage (HDDs or even SSDs) is much
slower than RAM. Moving data between RAM and disk is a very slow
operation compared to CPU instruction execution.
2. Thrashing: If the system spends more time swapping pages/processes in
and out of memory than it does executing actual program instructions, it's
called thrashing. This severely degrades system performance and can make
the computer feel extremely slow or unresponsive.
3. Storage Overhead: A dedicated portion of the secondary storage (swap
space) must be reserved, reducing the available storage for user files.