Ad Space — Top Banner

Not Enough Swap Space

Linux Linux

Severity: Moderate

What Does This Error Mean?

Swap is disk space that Linux uses as extra RAM when physical memory runs out. If swap space is too small or disabled, your system can crash or kill processes when RAM fills up. You might see a slow, unresponsive system, the OOM Killer terminating programs, or messages like 'Not enough memory to fork.' Adding swap is quick and often dramatically improves stability.

Affected Models

  • Ubuntu
  • Debian
  • Fedora
  • CentOS
  • Arch Linux
  • Linux Mint
  • Raspberry Pi OS

Common Causes

  • No swap partition or swap file was created during installation
  • The swap partition is too small for the workload — a common issue on systems with limited disk space
  • Swap was disabled accidentally by running swapoff without turning it back on
  • Hibernation is failing because the swap partition is smaller than the amount of RAM
  • A memory-intensive application is consuming both RAM and all available swap

How to Fix It

  1. Check current swap status. Run: free -h to see RAM and swap usage. Run: swapon --show to see all active swap devices and their sizes.

    If swapon --show shows nothing, swap is disabled. If free -h shows Swap: 0, there is no swap configured.

  2. Create a swap file. Run these commands one at a time: sudo fallocate -l 2G /swapfile then: sudo chmod 600 /swapfile then: sudo mkswap /swapfile then: sudo swapon /swapfile

    This creates a 2 GB swap file. Adjust 2G to 4G or 8G if you have more disk space and need more swap. Large applications like Chrome or virtual machines benefit from more swap.

  3. Make swap permanent across reboots. Edit /etc/fstab: sudo nano /etc/fstab and add at the end: /swapfile none swap sw 0 0

    Without this line, the swap file will not be activated automatically after a reboot.

  4. Adjust swappiness. Check current setting: cat /proc/sys/vm/swappiness. Lower values (10-20) use swap less aggressively. Set it: sudo sysctl vm.swappiness=10. Make it permanent in /etc/sysctl.conf: vm.swappiness=10

    Swappiness of 60 is the default. For desktop systems, 10-20 is often better — it keeps more data in RAM for faster access.

  5. Increase swap for hibernation. If hibernation fails, your swap must be at least as large as your RAM. Repeat Step 2 with a larger swap file and remove the old one: sudo swapoff /swapfile && sudo rm /swapfile

    Hibernation saves your RAM contents to swap, so it needs swap at least the same size as your installed RAM.

When to Call a Professional

Adding swap is a simple operation that any Linux user can do. You do not need professional help for this. For servers with very high memory demands, a system administrator can tune the swappiness setting to optimize when swap is used.

Frequently Asked Questions

How much swap space should I have?

A common guideline: for systems with less than 2 GB RAM, use 2x RAM as swap. For 2 to 8 GB RAM, use equal to RAM. For more than 8 GB RAM, 4 to 8 GB of swap is usually enough. For hibernation to work, swap must be at least as large as the total RAM.

Does having swap make my SSD wear out faster?

Swap does write to your SSD, which contributes to wear. Modern SSDs have very high write endurance — a typical SSD would take many years of heavy swap use to wear out from swap alone. The performance benefit of having some swap outweighs the minimal wear impact for most users. Adjusting swappiness to a lower value reduces how often swap is used.

Can I use a USB drive or SD card as swap?

Technically yes, but it is not recommended. USB drives and SD cards have slow write speeds and limited write cycles. Swap on a USB drive will be much slower than swap on your internal SSD. Use swap on your internal drive for best performance.