Performance Tuning for Linux swap partition

Tuning swap partition my result into a good system performance. You can tune swap by editing /etc/fstab file.

ADVERTISEMENTS

For example if you have two partitions as follows:
/dev/sdb3
/dev/sdc3

Now Linux system will only use one partition at a time. It will use next partition only if first partition exhausted. Each swap area has a priority, either high or low. The default priority is low. Within the low-priority areas, newer areas are even lower priority than older areas.

According to swap man page: All priorities set with swapflags are high-priority, higher than default. They may have any non-negative value chosen by the caller. Higher numbers mean higher priority. Swap pages are allocated from areas in priority order, highest priority first. For areas with different priorities, a higher-priority area is exhausted before using a lower-priority area. If two or more areas have the same priority, and it is the highest priority available, pages are allocated on a round-robin basis between them.

This may result into performance issue as a new process needs to be swapped to disk it may have to wait until another process is swapped out. So open your /etc/fstab:

# vi /etc/fstab

Find out line that read as follows:

/dev/sdb3 swap swap default 0 0
/dev/sdc3 swap swap default 0 0

Replace it as follows:

/dev/sdb3 swap swap pri=0 0 0
/dev/sdc3 swap swap pri=0 0 0

Restart the system or turn on and off swap to take effect with swapon command:

# sync;sync;swapoff -a
# swapon -a

The result of above tuning is that your system should able to use any one of the swap partition independently. Please note that this hack is only useful if your system uses swap.

Further readings:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.