Partition Alignment Guide



Table of Contents (Page)

  1. The easiest Way to achieve Alignment
  2. Partition Alignment - Example Setup
    1. Partition Alignment - Check current Alignment
    2. Partition Alignment - Create aligned Partition
  3. Create RAID-optimized File System
 


The easiest Way to achieve Alignment


A commonly used and very simple alternative to partition alignment is to create the file system directly on the storage device without any paritions. To do this, you would just use mkfs without any partition number, e.g. for XFS:

$ mkfs.xfs /dev/sdb

Thus, you would easily avoid the misalignment, which is introduced by a partition table.

However, even in this case you should still have a look at the section "Create RAID-optimized File System" at the bottom of this page.


Partition Alignment - Example Setup


By default, Linux uses a 512 bytes alignment (to be more specific: 63*512 bytes) for the first primary partition on a device. This is fine for single disks, at least the traditional ones, that use 512 byte blocks. For RAID arrays or SSDs, you want to set a different alignment to avoid the overhead of read-modify-write operations and enable the internal XFS or ext4 RAID optimizations.

Note that if you are using other software layers like LVM on a RAID, these can also introduce another offset and thus need to be taken into account for proper alignment.

Example configuration: In our example, we use a 600GB volume on:
  • an array of 11 disks
  • in RAID-6 mode
  • with a stripe size of 64KB
  • as device /dev/sdc

With RAID-6, we effectively have 9 disks for user data, so we want to align to 9 * 64KB.

(For SSDs, you probably want to align to the erase block size, which is typically 512KB or a multiple of that.)


Partition Alignment - Check current Alignment


Note on GPT partitions: The example below is based on fdisk, which is not compatible with GPT partition tables. For GPT partitions, use e.g. parted or gdisk.

If you already created a partition on your drive, you can check its alignment with the following command:

$ fdisk -lu /dev/sdc

Disk /dev/sdc: 599.9 GB, 599999905792 bytes
255 heads, 63 sectors/track, 72945 cylinders, total 1171874816 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1              63  1171861424   585930681   83  Linux


As you can see above, the start of the partition is currently at position 63*512 bytes, which is inappropriate for our use case.


Partition Alignment - Create aligned Partition


Note on GPT partitions: The example below is based on fdisk, which is not compatible with GPT partition tables. To create aligned GPT partitions, use parted, e.g.:
$ parted /dev/sdc mklabel gpt
$ parted --align=opt /dev/sdc unit KiB mkpart pri $((9*64)) 100%

If you already have a partition on your device, make sure to delete it first:
$ fdisk /dev/sdc

Command (m for help): d
Selected partition 1

Command (m for help): w
The partition table has been altered!


As mentioned above, we want to align to 9*64KB. We will use the fdisk arguments "-H 8 -S 16" to manually specify the (logical) number of heads and sectors. These arguments allow us to create a partition that is aligned to 64KB or any multiple of 64KB.

Our settings are based on 64KB cylinders and we want our partition to start right after the first stripe set (9 cylinders), so we will set the first cylinder to 10.

$ fdisk -H 8 -S 16 /dev/sdc

The number of cylinders for this disk is set to 9155272.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-9155272, default 1): 10
Last cylinder or +size or +sizeM or +sizeK (10-9155272, default 9155272): 
Using default value 9155272

Command (m for help): w
The partition table has been altered!


If you want to verify the new alignment:

$ fdisk -l /dev/sdc

Disk /dev/sdc: 599.9 GB, 599999905792 bytes
8 heads, 16 sectors/track, 9155272 cylinders
Units = cylinders of 128 * 512 = 65536 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1              10     9155272   585936832   83  Linux


We can see above that the partition starts at cylinder 10 and cylinders have a size of 64KB.

Now it's time to create a file system on the new partition.


Create RAID-optimized File System


XFS and ext4 allow you to specify RAID settings. This enables the file system to optimize its read and write access for RAID alignment, e.g. by committing data as complete stripe sets for maximum throughput. These settings can be made at file system creation time or, in the case of XFS, also later at mount time.

Note that these RAID optimizations can significantly improve performance, but only if your partition is properly aligned or of you are avoiding misalignment by creating the xfs on a device without partitions.

To create a new XFS file system for 9 disks (where the number 9 does not include the number of RAID-5 or RAID-6 parity disks) and 64KB chunk size, use:
$ mkfs.xfs -d su=64k,sw=9 -l version=2,su=64k /dev/sdc1


Note: If your data is stored on a RAID-5 or RAID-6 volume, you might want to consider putting the file system journal on a separate RAID-1 volume, due to the read-modify-write overhead of RAID-5 and RAID-6.

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki