How to Increase Swap Space on Linux (Live System Adjustment for OpenSUSE 11.3)


3 views
$ swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/sdc1 partition   2G   0B   -2

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           23Gi       4.2Gi        15Gi       356Mi       3.8Gi        18Gi
Swap:         2.0Gi          0B       2.0Gi

While 24GB RAM seems ample, modern Linux systems benefit from swap space for:

  • Kernel memory compression (zswap)
  • Hibernation support
  • Handling sudden memory spikes
  • Memory pressure management (vm.swappiness)
# 1. Create new swap file
$ sudo fallocate -l 8G /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile

# 2. Enable temporary swap
$ sudo swapon /swapfile

# 3. Verify new configuration
$ swapon --show
NAME       TYPE      SIZE USED PRIO
/dev/sdc1  partition   2G   0B   -2
/swapfile  file        8G   0B   -3

# 4. Make permanent in fstab
$ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

For partition-based approach (more complex):

# 1. Disable current swap
$ sudo swapoff /dev/sdc1

# 2. Delete and recreate partition (using fdisk)
$ sudo fdisk /dev/sdc
Command (m for help): d
Partition number (1-2, default 1): 1
Command (m for help): n
Partition type: p
Partition number (1-4, default 1): 1
First sector (2048-468862129, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-281, default 281): +10G

# 3. Recreate swap signature
$ sudo mkswap /dev/sdc1

# 4. Reactivate swap
$ sudo swapon /dev/sdc1
$ cat /proc/swaps
Filename                Type        Size    Used    Priority
/swapfile               file        8388604 0       -3
/dev/sdc1               partition   10485756 0       -2

$ grep -i swap /etc/fstab
/dev/sdc1 swap swap defaults 0 0
/swapfile none swap sw 0 0

After adjusting swap size, consider these optimizations:

# Adjust swappiness (default 60)
$ echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -p

# Enable zswap if available
$ echo 'zswap.enabled=1' | sudo tee -a /etc/default/grub
$ sudo update-grub

When working with a Linux server (OpenSUSE 11.3 in this case) that originally had a smaller memory configuration, the default 2GB swap space allocation might become insufficient after a RAM upgrade to 24GB. Here's how to check your current swap:

# View current swap information
sudo swapon --show
free -h

While conventional wisdom suggests swap should equal RAM size, modern recommendations differ:

  • For systems with 2GB-8GB RAM: 1.5x RAM size
  • For 16GB-64GB RAM: 4GB-8GB (as hibernation becomes less likely)
  • For 64GB+: Minimum 4GB for emergency situations

Option 1: Create a Swap File (Recommended)

# Create 8GB swap file
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# Make permanent
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Option 2: Resize Existing Swap Partition

This requires temporarily disabling swap and using fdisk:

# Disable current swap
sudo swapoff /dev/sdc1

# Delete and recreate partition (be careful!)
sudo fdisk /dev/sdc
# Follow interactive steps to delete partition 1 and create new larger one

# Reinitialize swap
sudo mkswap /dev/sdc1
sudo swapon /dev/sdc1
# Verify new swap
free -h
sudo swapon --show

# Adjust swappiness (10-60 recommended for servers)
echo 'vm.swappiness=30' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
  • Filesystem type must be "Linux swap" (code 82)
  • Ensure no processes heavily use swap during resize
  • Backup critical data before partition operations
  • Consider LVM for future flexibility

If using LVM, resizing becomes simpler:

# Extend logical volume
sudo lvextend -L +6G /dev/vg_os/swap

# Resize filesystem
sudo mkswap /dev/vg_os/swap

# Reactivate
sudo swapon /dev/vg_os/swap