Managing SWAP in Linux

Here are some fundamental guidelines to manage your SWAP space in LINUX, more efficiently.

1. Try to create SWAP as your first partition on the HDD. HDD works on the concept of ZCAV (zonal constant angular velocity). So first
partitions are created at the outer edge of the HDD, thus having a higher IO speed than on a partition created low down the cylinder.

2. If given a choice to whether use a partition or file for SWAP. Choose dedicated partition. And that is too on the highest speed HDD

3. When creating SWAP on the same HDD containing other mount points (like /var, /home etc). Always create SWAP next to (near to)
the partition having maximum IO
(like in case of FTP server create it near /var) so HDD head movement will take LESS time moving to swap, thus reduce latency.

4. Choose the SWAP on faster HDD to be used first in comparison of the SWAP on a slow HDD. Edit your /etc/fstab file as shown to give
priorities to SWAP locations.

/dev/sda1      swap      swap      pri=4    0   0
/dev/sda2      swap      swap      pri=4    0   0
/dev/sdb4      swap      swap      pri=2    0   0

Kernel will use the /dev/sda1 and /dev/sda2 before using /dev/sdb4 as they are having higher priority of 4. In case two or more SWAP locations have equal priorities kernel will distribute visit in round robin.

God Bless.