Linux – Move partition from back of disk to the front for performance

hard drivelinuxpartitioningswap

Hard drives have faster performance at the beginning of the platter (see zone bit recording).

According to an answer to "What is the purpose of multiple swap files?", you should put your swap partition near the beginning of the drive.

I like to have multiple swap partitions occupying the beginning of every disk (to take advantage of zone bit recording).

  1. How would you move your swap from the end of the drive, to the beginning?
  2. During the Linux install process, how do you specify where the swap is located on disk? Does the order the partitions are listed coincided with their physical location on disk?

Resources:

Best Answer

Hard drives have faster performance at the beginning of the platter.

Not really.

The first step is to figure out which part of the drive is closest to the center. Usually bits with lower indexes will be closest to the center, but this is not always the case *. To that end, there is zcav(1) which is part of bonnie++.

# zcav -b 200:10  /dev/mapper/try-root > root.log
awk 'NF==3 { printf "% 6.1f % 7.1f % 4.1f\n", $1, $2, $3 } 
     NF!=3 { print }' root.log
#block offset (GiB), MiB/s, time
   0.0    50.2  4.0
   0.2   175.3  1.1
   0.4   178.1  1.1
   0.6   182.6  1.1
   0.8   174.4  1.1
   1.0    57.9  3.5
   1.2   177.3  1.1
   1.4   106.0  1.9
   1.6    78.2  2.6
   1.8   183.5  1.1
# Read 2000 megs in 18 seconds, 107 megabytes per second.

This measures throughput. It will be larger towards the broad part of the drive (where the circumference of an imaginary ring would be largest). Unfortunately, high throughput of the longest (outer most) tracks does not coincide with low access time of the inner most tracks. I believe this was the basis of your claim (not wrong, but inaccurate).

If you measure a regular block device, the MB/s values will either ascend or descend as the GB values increase. When the transfer rate increases it means that the bit-numbering starts at the innermost track.

And to answer your questions;

One

  1. delete the current swap partition.
  2. create a new partition at the logical block offset range that would best suit your needs.
    If that area is occupied, move the valuable data to another device and reclaim the space for the swap partition.

Two

  1. By creating a partition on a specific range of gigabytes. eg 1-10 vs 990-1000.
  2. If data is mapped out -> in, then GB 1-10 will be on the out-most part of the drive. Conversely,
    a drive mapped in -> out will have GB 1-10 on the inner most track.
    However, several partitioning tools (e.g fdisk) allow the user to specify if a new partition should be at the beginning or the end of the free space. The beginning may be closest to the center or edge of the drive, depending on how data is mapped internally.
  3. There is no inherent connection between a partition number and that partition's physical location relative to the edge of a disc.

* This is a contradiction of wikipedia. I have yet to see a drive that maps data starting at the outmost track. Run the zcav utility on your drive unless you can find this information in the specification sheet or manual of your drive.

Related Question