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

8,995

Solution 1

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.

Solution 2

GParted is your friend, as others already mentioned in other answers to this question.
Don't forget to backup your system first. One slight mistake and your system will be dead.

Make sure you leave a very small (minimum of 4 MB) are blank at the beginning of the disk. GParted will probably round the size up to the nearest boundary supported by the disk. That is to be expected.
This prevents potential issues with bootloaders that don't like a partition start immediately after the boot-sector. (See also point 1 in the answer of Levans.)

You will receive no noticeable benefit from this though...
Performance gain from re-organizing the swap-space is 10% to 15% at most and just for the actual swap activity.
As swap is MUCH slower than real RAM (often by a factor of 50 to 100) a minor improvement in swap speed is just a ripple on the overall scheme of things.

The only time this might be somewhat beneficial is if you have a system that needs 10x (or more) RAM than what is installed in the system. So it is continuously swapping like crazy.
If you have such a system you are doing it wrong... No amount of performance tuning is going to compensate for the lack of real RAM. Any benefit will be marginal at best.

In such a case installing more RAM is far more efficient and less hassle.

Solution 3

For the 1., you can use GParted on a LiveCD, it's a graphical tool that can help move your partitions.

However, I would not recommend it, especially if it is to mess with the beginning of your disks. While resizing a partition to get some space at the end is quite safe, every time I tried to move the beginning of a partition, It was a failure a I lost my partition. The first sectors of a partition are a really sensible area.

Before doing this, you should consider whether you really need it. Does yous system use a lot of swap, to the point that such an optimization will have a real impact ?

Concerning 2., during the install process of any distribution, there should be a step where it prompts for an installation media. There should be an "advanced" tab, or something similar, which allows you to specify the partitioning you want and the mount points.

So if you situation is, as an example :

/dev/sda1 : root
/dev/sda2 : swap
/dev/sda3 : home

And that you want to switch places of root and swap, I would recommend re-installing the system and define a new partitioning at the same time, if possible (as you can keep your home untouched during the process). It's much less hazardous than moving around your root partition.

Share:
8,995

Related videos on Youtube

spuder
Author by

spuder

Automation Engineer Deving all of the Ops in Lehi, Utah. Primarily focused in: Puppet Chef Docker #SOreadytohelp

Updated on September 18, 2022

Comments

  • spuder
    spuder over 1 year

    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:

    • sawdust
      sawdust almost 11 years
      You would be better off focusing on minimizing random access time than moving swap to the outer cylinders, if you have to obsess about trying to improve HDD performance. Seek time typically dominates the transfer time in the total access time. And don't believe everything you read about short stroking. Most of the articles I've seen misinterpret/misuse HDD specifications and do not correctly "recalculate" the "average" seek time, so the performance gain is exaggerated. A lot of information you can find on the Internet on HDDs is incorrect.
  • spuder
    spuder almost 11 years
    Hard drives do in fact start at the outer edges of the platter (see first 3 links). Cd's and DVD's (with the exception of the xbox) start on the inside of the medium. Care to reconsider your down vote?
  • Ярослав Рахматуллин
    Ярослав Рахматуллин almost 11 years
    The question is in part about instructions on how to create partitions during an unidentified installation process. I dislike that because 1- installers are documented (if not, try it two times to see what the options are). 2- they are all semi-different. Next, hard drives do not have better performance at the beginning of the platter because a) the beginning of the platter is ambiguous, b) "performance" is ambiguous (MB/s vs access time) i.e - lower access time is more important than highest MB/s on swap. Please don't take down-votes as a personal insult and good luck!