Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am familiar with what partitions are, but I saw a question about aligned partitions on Ask Ubuntu, and realised I didn't know what "aligned partitions" are.

So what does it mean to "align" partitions? What are the benefits, and the downsides?

share|improve this question

Aligning the partition means to align it to match the true, underlying block structure.

For a long time now hard disks have used 512 byte blocks. Because this has gone on for a long time it is now almost impossible to change the block size. Too much software would need to be fixed.

On an SSD the true block size could be 128 KB. On a RAID array it might be 64 KB. On an advanced format drive it will be 4 KB.

For backward compatibility the drive continues to work with 512 byte blocks. But for performance reasons your system really should know the true block size.

On of the easiest performance tweaks to make is to align the drive partition with the true block size so that when your OS does write 4 KB or 64 KB or 128 KB it writes a full block.

If the partition was not aligned then the result would be to write 512 bytes to the first block and 4K - 512 bytes to the second block, forcing the disk/SSD/RAID to do two read-modify-write cycles instead of one write.

share|improve this answer
Do you have any suggestion on… – AnkurTank Dec 15 '15 at 13:11
@AnkurTank: No, the question there seems well covered. – Zan Lynx Dec 15 '15 at 16:53
Thank you for your attention, only thing left there is how to confirm that partitions are aligned. Because for me parted is still complaining that partitions are not aligned. Moreover I tried using other tool e.g. gdisk, but I am not able to cross compile gdisk for . So I thought if you have any suggestion on how to verify that will help. – AnkurTank Dec 16 '15 at 7:00

Partitions are sequences of blocks, and by long-standing convention one block is 512 bytes.

So a partition may start at any multiple of 512 bytes inside a disk, "seen" as a very long string of bytes.

The underlying disk hardware, though, which originally had the same 512 byte sector size, uses now a larger size for efficiency. Let's say it's 4096 bytes.

For compatibility reasons, the firmware standing between the OS and the hardware still "talks in sectors". So you ask the first sector, and the hardware retrieves the first block (4096 bytes), and the firmware extracts and delivers the appropriate slice. You ask the second block and the block is probably retrieved from the cache.

So far sector size mismatch has no cons.

But the OS also employs blocks (usually called clusters) for efficiency, and will align them to the partition. So a 4-sector cluster will be made up of sectors 5, 6, 7 and 8.

When the OS requests filesystem cluster #2, the firmware gets asked for logical sectors 5, 6, 7, and 8. If they are all in the same disk block, then the disk has to perform ONE read.

But if the partition starts at the "wrong" sector, the first cluster in the filesystem will for instance end up, simplifying, at sectors 2, 3, 4 and 5. And they might then be be half in the first disk block (1-2-3-4), half in the second (5-6-7-8).

You now need one extra read. For OS-to-disk ratios of 1:1, this is the same as doubling the reads. If OS-to-disk ratio is 2:1, a cluster is two hardware disk blocks, you will need 2+1 = 3 reads, a penalty of 50%:

OS   |--- cluster  12 ---|--- cluster  13 ---|--- cluster  14...
     |                   |                   |
HDD  --|----|----|----|-a--|--b-|-c--|-d--|-e--|----|---        BAD
     |                   |                   |
HDD  |----|----|----|----|-a--|--b-|-c--|-d--|----|----|---     GOOD

Above, a cluster is 4 hardware blocks (ratio 4:1) of 2 sectors each. Aligning on "even" sectors means that to read a cluster those 8 sector reads translate to 4 block reads. Aligning on odd sectors means that the same 8 sector reads require 4+1 = 5 block reads, a performance penalty of 25% (you add one read every four).

If you have a misaligned disk with 4:1 ratio, aligning it will make it 20% faster (you save one read every 5).

To "align" the partition, you can for example create a small partition at the beginning of the disk, with such a size that the next partition starts exactly on a sector boundary. In theory you need at most N-1 sectors, i.e. very few kilobytes. In practice, partitions have a minimum size, so you'll probably need to waste some hundred of kilobytes, possibly whole megabytes, in order to squeeze the most performances out of your multi-gigabyte hard drive.

(You could probably recover that space, and much more, by properly choosing the OS cluster size in relation to your average file size).

share|improve this answer

Dunno if this is helpful, but my understanding was that partition alignment is when you align a given partition with an underlying RAID stripe units.

Apparently, performance may suck when you use a hardware-based RAID or software-based; problems could arise if the starting location of the partition is not aligned with a stripe unit boundary in the disk partition that is created on the RAID.

Depending on the factoring for creating volume clusters, a volume cluster may be created over a stripe unit boundary instead of next to the stripe unit boundary. This behavior could cause a misaligned partition.

I may be way off and this could have nothing to do with RAID ;)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .