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.

For example if you have two partitions as follows:

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 Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum