[CentOS] Physical position of swap partition on the disk

Tue Dec 1 10:53:25 UTC 2020
Roberto Ragusa <mail at robertoragusa.it>

On 11/30/20 1:55 PM, Jonathan Billings wrote:
> On Nov 30, 2020, at 02:35, Nicolas Kovacs <info at microlinux.fr> wrote:

>>   * /dev/sda1: 500 MB /boot ext2
>>   * /dev/sda2: 4 GB swap
>>   * /dev/sda3: 55 GB / ext4
>>
>> I'd be curious to know what's the reason behind this, and if this kind of
>> configuration detail is really significant.
> 
> When most of us had storage on rotational storage, the fastest, lowest latency access was close to the physical center of the disc, which corresponds to the start of the disk.  You’d want swap to be highly responsive in case it was used for active processes.
Well, actually it is the opposite.
The first blocks of the disk are on the edge of the disk and they
have better throughput since the the track is longer and contains
more data to be read in a single disk revolution (rpm is a constant).

The idea is that you have swap at the beginning because it needs
the best performance, then you have your data immediately after.

Having the swap at the end is the worst choice because it is in the slowest
zone and it is typically very far from a partially filled data
partition at the beginning of the disk, causing a lot of head movement
when swapping. The advantage in no-swapping case is minimal,
because the swap partition is usually small and having your data
starting at 0% of the disk space or at 3% doesn't matter a lot.

Finally, swap throughput really matters when hibernating to disk.

If you have both your swap and filesystems in an LVM volume,
you can shuffle and rearrange them on the disk as you prefer
without even a reboot (pvmove with explicit extent indications).

Regards.
-- 
    Roberto Ragusa    mail at robertoragusa.it