On a Linux system with Swap partition or swap file, it is used a temporary storage when physical memory (RAM) space is depleted. When RAM is not available in your system, the inactive memory pages are often dumped into the swap free space. In this article we demonstrate how you can completely disable swap space in your Linux system.

Running the free command in Linux will show whether swap is enabled in the system.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.5Gi       4.4Gi       2.2Gi        16Mi       856Mi       2.9Gi
Swap:         5.0Gi          0B       5.0Gi

If the swap backend is a block device you can check its path using the command below.

# blkid | grep swap
/dev/mapper/rl-swap: UUID="97f7f3ae-6cac-4fb5-967f-b49ba94c1d53" TYPE="swap"

To immediately disable swap in realtime run:

sudo swapoff -a

Confirm that it’s not active.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.5Gi       3.3Gi       3.4Gi        16Mi       856Mi       4.0Gi
Swap:            0B          0B          0B

To disable swap permanently, remove any entries in /etc/fstab file.

$ sudo vim /etc/fstab
#/dev/mapper/rl-swap     none                    swap    defaults        0 0

You can achieve the same using sed command.

sudo sed -i.bak -r 's/(.+ swap .+)/#\1/' /etc/fstab

Another hack involves using cron job.

$ sudo crontab -e
@reboot sudo swapoff -a  

CloudSpinx Services

CloudSpinx exists to offer you support services on Email solutions of any kind. Contact us now if you need help with installation and configurations, post-install integrations, and continuous support services for your email server services.

LEAVE A REPLY

Please enter your comment!
Please enter your name here