Swap Space in Operating System (original) (raw)

Last Updated : 27 Apr, 2026

Modern operating systems use both physical memory (RAM) and virtual memory to manage processes efficiently. Swap space (also called paging space or swap file) plays a key role in this memory management strategy. It is a dedicated area on the hard disk used by the operating system as an extension of physical RAM.

lazy-swapping

Swapping

**Note: Swap space enables the OS to handle memory more flexibly, supporting the illusion of a larger memory than physically available, thus improving multitasking and stability of the system.

Working of Swap Space

  1. When physical memory (RAM) is full, the OS selects some memory pages that are inactive or least recently used (using algorithms like LRU – Least Recently Used).
  2. These pages are written from RAM to the swap space on the disk.
  3. When those pages are needed again, they are read back from the swap space into RAM.
  4. This process of moving pages between RAM and disk is called paging (or page swapping); swapping refers to moving an entire process between memory and disk, which is different.

**Note: Despite its usefulness, accessing swap space is much slower than RAM due to disk I/O delays.

Optimal Swap Space Size

A general rule of thumb recommends swap space size to be about 1.5 times the size of physical RAM. However, the exact swap size depends on the system's use case:

**Note: Modern systems with large amounts of RAM often use much smaller swap sizes, just to handle exceptional cases.

Swap Space vs Virtual Memory

Feature Swap Space Virtual Memory
Definition Physical disk space used for swapping memory pages Abstract combination of physical RAM and swap space
Role Storage area for inactive pages Provides an abstraction of larger memory to applications
Performance Slow access (due to disk I/O) Appears seamless to applications
Implementation Typically a swap partition or swap file Managed by OS using page tables

Configuring Swap Space

**Linux:

**Example commands:

sudo mkswap /swapfile
sudo swapon /swapfile

**Windows: Page file settings can be managed through System Properties -> Advanced System Settings -> Performance Settings -> Virtual Memory.

When Should Swap Space Be Disabled?

**Note: In general-purpose systems, swap space should be present for safety.

Advantages :

Disadvantages :