Concept of Swap Space

What is Swap Space?
Swap space is a part of the hard disk (or SSD) that Linux uses as virtual memory when the physical RAM is full. Inactive pages of memory are moved from RAM to swap, freeing RAM for active programs.
Types of Swap
- Swap partition: a separate partition reserved only for swap.
- Swap file: a special file on an existing partition used as swap.
How Much Swap?
A traditional rule was swap equal to about twice the RAM for small systems. Modern systems with large RAM often use a smaller swap, and enough swap is needed if you want to use hibernation.
Useful Commands
- free -h: shows RAM and swap usage.
- swapon –show: lists active swap areas.
- mkswap /dev/sdb2: prepares a partition as swap.
- swapon / swapoff: turns swap on or off.
Advantages and Disadvantages
Swap prevents the system from crashing when RAM runs out and allows more programs to run. However, the disk is much slower than RAM, so heavy use of swap slows the computer down.
Important Questions
Q. What is swap space?
Ans. Swap space is disk space used by Linux as virtual memory when the physical RAM is full.
Q. Name the two types of swap in Linux.
Ans. Swap partition and swap file.
Q. Which command shows memory and swap usage?
Ans. free -h