Linux Swap Errors — Swappiness, Swap Full, and Memory Pressure
About Linux Swap Errors
Fix Linux swap issues including swap space full, high swappiness causing excessive swapping, creating emergency swap files, and monitoring memory pressure. 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 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: 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. 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 and swapon --show. Create swap file: sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile. Make permanent: add '/swapfile none swap sw 0 0' to /etc/fstab. Adjust swappiness: sudo sysctl vm.swappiness=10 (persistent: add to /etc/sysctl.conf). Monitor pressure: cat /proc/pressure/memory (shows some/full pressure metrics). 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
What swappiness value should I use?
Desktop: 10-30 (minimize swap for responsiveness). Server: 60 (default, balance between RAM and swap). Database server: 1-10 (keep data in RAM).
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
- 1Check swap usage: free -h and swapon --show
- 2Create swap file: sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
- 3Make permanent: add '/swapfile none swap sw 0 0' to /etc/fstab
- 4Adjust swappiness: sudo sysctl vm.swappiness=10 (persistent: add to /etc/sysctl.conf)
- 5Monitor pressure: cat /proc/pressure/memory (shows some/full pressure metrics)