Error Codes Wiki

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

Errorsystem

About Linux Swap Space Errors

Fix Linux swap space issues including swap full causing system freezes, OOM killer activating, creating swap files, and tuning swappiness for performance. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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). Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Check swap usage: free -h or swapon --show. Create a swap file: sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile. Make persistent: add '/swapfile none swap sw 0 0' to /etc/fstab. Tune swappiness: sudo sysctl vm.swappiness=10 (persistent: add to /etc/sysctl.conf). Identify memory hog: top or htop sorted by memory (press M in top). Check OOM kills: dmesg | grep -i 'out of memory' or journalctl | grep oom. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

How much swap space do I need?

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).

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).