What does it mean to "align" partitions?
Solution 1:
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.
Solution 2:
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. Or write.
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).
Having a read-ahead, write-back cache of a multiple size of storage elementary unit (which might be 512b, 4K, 32K, 64K, or even 128K depending on technology), and OS filesystem aligned to the storage layout, can reduce disk accesses for read and write to a minimum, greatly improving performances.
To make a partition "aligned", you move/set its offset from the beginning of the disk to the appropriate multiple of 512b-sectors, leaving the gap unpartitioned or not depending on the tool and your whim, so that the partition starts exactly on a disk-sector boundary. Actually: so that the majority of the OS clusters is aligned on a storage boundary.
For example: say you have a file system organized so its data section starts 50000 Kb from the beginning of the partition, and it is organized in blocks of 8 Kb. If the storage has 16Kb blocks, this is good, since 50000 Kb is exactly 3125 blocks. But if you have a NVMe storage with 64Kb blocks, 50000 Kb is 781 blocks and a quarter, so each 64Kb storage block will hold 7 full OS blocks and two block fragments. By making the partition start 3/4ths of a 64Kb block further (so, 48 Kb further), the data section offset will be aligned exactly at the 782nd storage block.