Error Codes Wiki

Linux Swap Errors — Swappiness, Swap Full, and Memory Pressure

Warningsystem

Overview

Fix Linux swap issues including swap space full, high swappiness causing excessive swapping, creating emergency swap files, and monitoring memory pressure.

Key Details

  • Swap provides overflow space when physical RAM is exhausted
  • vm.swappiness (0-100) controls how aggressively the kernel uses swap (default: 60)
  • A system with no swap can OOM-kill processes without warning when RAM is full
  • SSDs handle swap much better than HDDs — swap on HDD causes severe performance degradation
  • Memory pressure can be monitored via /proc/pressure/memory on modern kernels

Common Causes

  • Insufficient RAM causing heavy swap usage and performance degradation
  • No swap space configured, causing OOM kills when RAM is full
  • Swap partition full with no additional swap available
  • High swappiness value causing unnecessary swapping despite available RAM
  • Memory leak in application slowly consuming all RAM and swap

Steps

  1. 1Check swap usage: free -h and swapon --show
  2. 2Create swap file: sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
  3. 3Make permanent: add '/swapfile none swap sw 0 0' to /etc/fstab
  4. 4Adjust swappiness: sudo sysctl vm.swappiness=10 (persistent: add to /etc/sysctl.conf)
  5. 5Monitor pressure: cat /proc/pressure/memory (shows some/full pressure metrics)

Tags

linuxswapmemoryswappinessoom

More in System

Frequently Asked Questions

Desktop: 10-30 (minimize swap for responsiveness). Server: 60 (default, balance between RAM and swap). Database server: 1-10 (keep data in RAM).