Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

swapoff

Disable devices and files for paging and swapping.

Synopsis

swapoff device...
swapoff -a

Operation

Calls swapoff(2) to disable swapping on the specified device or file. The kernel moves all swap pages back to RAM before deactivating the area, which may take significant time if the swap is heavily used.

--all mode

Reads /proc/swaps to find all active swap areas and disables each one.

Inputs

SourcePurpose
Device/file pathTarget to disable
/proc/swapsEnumerate active swap areas for --all

Outputs

  • swapoff(2) syscall to disable swap

Syscalls

SyscallDescription
swapoff(2)Disable swapping on a device/file

Command-line options

OptionDescription
-a, --allDisable all active swap areas
-v, --verboseVerbose output
-h, --helpDisplay help
-V, --versionDisplay version

Exit codes

CodeMeaning
0All succeeded
4swapoff(2) failed
8Non-syscall system error
32All failed (--all mode)
64Some failed (--all mode)

Permissions

Requires CAP_SYS_ADMIN.

Notes

  • swapoff may take a long time if the swap area is heavily used, as all pages must be paged back into RAM.
  • If there isn’t enough free RAM to absorb the swap contents, swapoff will fail with ENOMEM.

Not yet implemented

  • -L, -U label/UUID specifiers (needs libblkid)