Error Codes Wiki

Linux Swap Space Errors — Swap Full, OOM Killer, and Swap Configuration

Errorsystem

Overview

Fix Linux swap space issues including swap full causing system freezes, OOM killer activating, creating swap files, and tuning swappiness for performance.

Key Details

  • Swap provides overflow memory when physical RAM is exhausted — prevents OOM kills but is much slower
  • Swappiness (0-100) controls how aggressively Linux moves pages from RAM to swap (default: 60)
  • OOM Killer activates when both RAM and swap are full, killing the most memory-consuming process
  • Swap can be a partition or a file — swap files are easier to resize
  • zram provides compressed swap in RAM, faster than disk-based swap (default on some distros)

Common Causes

  • Insufficient RAM for the workload causing heavy swap usage and system slowness
  • Memory leak in an application gradually filling both RAM and swap
  • Swappiness too high causing unnecessary swapping even when RAM is available
  • No swap configured, making OOM kills more likely
  • Swap file on a slow HDD causing severe performance degradation when swapping

Steps

  1. 1Check swap usage: free -h or swapon --show
  2. 2Create a swap file: sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
  3. 3Make persistent: add '/swapfile none swap sw 0 0' to /etc/fstab
  4. 4Tune swappiness: sudo sysctl vm.swappiness=10 (persistent: add to /etc/sysctl.conf)
  5. 5Identify memory hog: top or htop sorted by memory (press M in top)
  6. 6Check OOM kills: dmesg | grep -i 'out of memory' or journalctl | grep oom

Tags

swapoom-killermemoryswappinessswapfile

Related Items

More in System

Frequently Asked Questions

General rule: equal to RAM for systems with 4-8GB, half of RAM for 16GB+. For hibernate support, swap must be at least equal to RAM. Servers with large RAM may need minimal swap (2-4GB).