Note: There is no dedicated “official documentation” for “centos swapper” from CentOS/RHEL. The term “swapper” typically refers to the Linux kernel’s swap subsystem (swap partition or swap file), which is managed using standard system tools. Below are the official and community-accepted best practices for configuring and managing swap space on CentOS systems.
Before configuring swap, verify if your system already has swap enabled:
free -h
Look for the “Swap” line in the output. If “Swap” shows 0B, no swap is configured.
A swap file is flexible and does not require modifying disk partitions.
Create a swap file (e.g., 2GB):
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
if=/dev/zero: Input source (infinite zero stream).of=/swapfile: Output file path.bs=1M: Block size (1MB).count=2048: Number of blocks (2048 × 1MB = 2GB).Set strict permissions (only root can read/write):
sudo chmod 600 /swapfile
Format the file as swap:
sudo mkswap /swapfile
Activate the swap file:
sudo swapon /swapfile
Enable auto-mount on boot:
Edit /etc/fstab and append:
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab
This ensures swap is re-enabled after a reboot.
For production servers, a dedicated swap partition is often preferred for stability.
Identify unused disk space:
sudo fdisk -l
Look for a disk with unallocated space (e.g., /dev/sdb).
Create a new partition:
Use fdisk to create a partition (replace /dev/sdb with your disk):
sudo fdisk /dev/sdb
n (new partition) → p (primary) → enter partition number → press Enter (default start sector) → +2G (set size, e.g., 2GB) → t (change partition type) → 82 (Linux swap type) → w (write changes).Format the partition as swap:
sudo mkswap /dev/sdb1
Activate the partition:
sudo swapon /dev/sdb1
Enable auto-mount on boot:
Edit /etc/fstab and append:
echo "/dev/sdb1 swap swap defaults 0 0" | sudo tee -a /etc/fstab
Verify:
Use sudo swapon --show or free -h to confirm.
The swappiness parameter controls how aggressively the system uses swap (range: 0–100).
Check current value:
cat /proc/sys/vm/swappiness
Temporarily modify (until reboot):
sudo sysctl vm.swappiness=10
Permanently modify:
Edit /etc/sysctl.conf and add:
vm.swappiness=10
Apply changes:
sudo sysctl -p
Reboot (optional, to ensure persistence):
sudo reboot
Regularly check swap usage to ensure optimal performance:
free -h
sudo swapon --show
cat /proc/swaps
sysstat first):sar -W 1 5