SysTutorials

Disabling All Swap on Linux

· updated April 12, 2026

To disable all active swap spaces on Linux, run:

swapoff -a

The -a flag targets all currently enabled swap devices and files. This forces the kernel and applications to rely entirely on physical RAM.

When You’d Do This

Disabling swap is useful for:

Important Caveats

Before you disable swap, understand the risks:

Checking Current Swap Status

Before making changes, see what swap devices are active:

swapon --show

Or use the traditional method:

free -h
cat /proc/swaps

Disabling Specific Swap Devices

To disable a single swap device or file instead of all:

swapoff /dev/sda2
swapoff /swapfile

Re-enabling Swap

To turn swap back on after disabling it:

swapon -a

This re-enables all swap devices and files listed in /etc/fstab.

To enable a specific device:

swapon /dev/sda2
swapon /swapfile

Making Changes Persistent

These commands only affect the running system. To permanently disable swap across reboots, either:

  1. Comment out swap entries in /etc/fstab:

    # /swapfile                                 none            swap    sw              0       0
    # /dev/sda2                                 none            swap    sw              0       0
    
  2. Disable swap in systemd:

    systemctl mask dev-sda2.swap
    

Instead of completely disabling swap, consider lowering vm.swappiness:

sysctl vm.swappiness=10

This reduces swap usage while keeping it available as a safety net. Values range from 0 (minimal swap, but not disabled) to 100 (aggressive swapping). Most production systems use values between 10–30.

To make this permanent, add to /etc/sysctl.conf:

vm.swappiness=10

Then reload:

sysctl -p

This approach prevents OOM kills while still using physical memory primarily, offering a practical middle ground between performance and stability.

Troubleshooting Common Issues

When encountering problems on Linux systems, follow a systematic approach. Check system logs first using journalctl for systemd-based distributions. Verify service status with systemctl before attempting restarts. For network issues, use ip addr and ss -tulpn to diagnose connectivity problems.

Package management issues often stem from stale caches. Run dnf clean all on Fedora or apt clean on Ubuntu before retrying failed installations. If a package has unmet dependencies, try resolving them with dnf autoremove or apt autoremove.

These commands are frequently used alongside the tools discussed in this article:

Quick Verification

After applying the changes described above, verify that everything works as expected. Run the relevant commands to confirm the new configuration is active. Check system logs for any errors or warnings that might indicate problems. If something does not work as expected, review the steps carefully and consult the official documentation for your specific version.

← All posts