LinuxCommandLibrary

swapoff

Deactivate swap space

TLDR

Disable a given swap area

$ swapoff [path/to/file]
copy

Disable all swap areas in /proc/swaps
$ swapoff [[-a|--all]]
copy

Disable a swap partition by its label
$ swapoff -L [label]
copy

SYNOPSIS

swapoff [-a] [-v] <swapfile>...

PARAMETERS

-a
    Deactivates all swap devices and files listed in /etc/fstab.

-v
    Verbose mode. Displays information about the swap device being deactivated.

<swapfile>
    The path to the specific swap file or swap device to deactivate. Multiple files can be specified.

DESCRIPTION

The swapoff command disables swap devices and files for memory paging on a Linux system. Swap space is used when the system's physical memory (RAM) is exhausted. Deactivating swap can free up disk space and potentially improve performance if swapping is degrading system responsiveness, although this is generally not recommended except for specific use cases such as debugging or hardware testing. Once swap is disabled, the system relies solely on RAM, and if memory runs out, processes may be terminated by the OOM killer.
Note: The command doesn't delete swap files. It just stops using them.

CAVEATS

Disabling swap can lead to system instability if the system runs out of physical memory. Use with caution. Changes are not persistent across reboots unless removed from /etc/fstab.

USAGE EXAMPLES

Deactivating a specific swap file: swapoff /swapfile
Deactivating all swap spaces listed in /etc/fstab: swapoff -a
Deactivating a swap partition: swapoff /dev/sda5

TROUBLESHOOTING

If swapoff -a doesn't deactivate all swap spaces, check the output of swapon -s to verify which swap spaces are active and manually deactivate the ones that remain.

HISTORY

The swapoff command has been a core part of Unix-like operating systems, including Linux, since their inception. Its purpose has always been to provide a way to dynamically disable swap space for management and debugging purposes. Over time, its functionality has remained relatively consistent, focusing on providing a reliable mechanism for deactivating swap devices.

SEE ALSO

swapon(8), mkswap(8), fstab(5), free(1)

Copied to clipboard