Wood Chen

Disabling Swap on a Linux Server

0 comments110 views268 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

On my local server, I allocated a 16G swap partition when installing the OS, but I've since upgraded the RAM to 32G. The disks are configured as raid6, which has relatively poor performance, so I'd rather disable swap and use physical memory only.

‍

Disabling a swap partition on a server may require administrator privileges. The exact steps depend on your operating system. Here's how to disable swap on common Linux distributions such as Ubuntu and CentOS:

1. Check the current swap status

sudo swapon --show

This lists the currently active swap partitions. If there is no output, no swap partitions are active.

2. Turn off swap

If any swap partitions are active, turn them off with the following command:

sudo swapoff -a

3. Disable automatic activation

Edit /etc/fstab and comment out the lines related to swap partitions so they won't be activated automatically at boot.

sudo nano /etc/fstab

Find a line like the following and comment it out by adding # at the beginning:

#/dev/sdX none swap sw 0 0

Replace /dev/sdX with the actual device path of your swap partition.

4. Disable swap permanently

Reboot the server to confirm that the swap partition is no longer activated.

Notes:

  • Disabling swap may affect system performance, especially when memory is low. Make sure your system has enough physical memory to handle its workload.
  • Before disabling swap, check your system's memory usage and make sure it isn't constantly reaching its memory limit. Otherwise, disabling swap could make the system unstable or cause it to crash.

If you're using another operating system or are unsure about your system configuration, back up important data and test before making changes.

‍

Related posts

Comments 0