swapoff – Turn off the specified swap space

The swapoff command is used to disable a specific swap space. The syntax for the command is as follows:

swapoff /path/to/swapfile


swapoff /dev/sdXN

where /path/to/swapfile is the path to the swap file, and /dev/sdXN is the swap partition. To turn off all swap spaces, you can run the command without any arguments:

swapoff -a

This will turn off all swap spaces on the system.


To turn off the swap space located at /swapfile, run the following command:

swapoff /swapfile

To turn off the swap partition located at /dev/sda2, run the following command:

swapoff /dev/sda2

To turn off all swap spaces on the system, run the following command:

swapoff -a

Specific Use Cases

The swapoff command can be used in various situations, such as:

  1. To disable a specific swap space that is causing issues, such as high disk usage or slow system performance.
  2. To disable all swap spaces when upgrading or resizing the system’s physical RAM.
  3. To disable swap spaces temporarily for maintenance or troubleshooting purposes.


The swapoff command has the following options:

-aTurn off all swap spaces
-vVerbose mode. Print additional information about the command’s actions.

Troubleshooting Tips

  • If you receive an error message stating that the swap space is busy, it means that some data is still in the swap space. You can use the swapon -s command to check the status of the swap spaces. If the swapoff command is taking a long time to complete, it’s likely because there’s a lot of data in the swap that needs to be moved back to RAM.
  • If you accidentally turn off the wrong swap space, you can turn it back on by running the swapon command with the appropriate arguments.


  • The swapoff command requires root privileges to run.
  • Disabling swap spaces can cause system performance issues if the system runs out of physical RAM. It is important to ensure that the system has enough physical RAM before disabling swap spaces.