Linux disk alignment reloaded dirty cache

Enough has been written on why disk alignment is important but here a brief reminder: The standard DOS partitioning mechanism by default creates the first partition starting at 63 blocks of 512 bytes. So the first data block of the partition starts at 32256 bytes which is not a multiple of EMC storage disk and cache block sizes (it probably doesn’t match many other storage subsystems either). The problem is that a single 8K write (for example, to the first block of the partition) causes two 8K block updates on the physical disk backend. Consider the layout: Disk block 0: 00000 – 08192 * holds DOS partition table and boot sector

If the partition was aligned at, say, 32KB then partition 1 started exactly at offset 32768 (4 blocks) and the whole 8K write operation would require no backend reads at all and just one backend write (of course ignoring RAID and other aspects).


Note that for specialized FLASH arrays (i.e. EMC’s XtremIO and the like) this becomes all the more important – both for performance and to avoid excessive wear of the flash cells.

I found that in CentOS 6, and other recent Linux distributions (i.e. Ubuntu, Mint, probably Red Hat 6 and Oracle Enterprise Linux 6) the command “sfdisk” complains when you want it to create 128 block aligned partitions. I noticed this already when writing my original post but as I was mainly using CentOS 5.x I didn’t bother, until now when I am messing with Oracle on CentOS 6.4 🙂

Strangely enough, on those distros the boot disk comes aligned nicely at 1MB (2048 sectors). But both “fdisk” and “cfdisk” still create partitions by default at 63 sector offsets. However, if you use “fdisk” and follow the guidelines and switch to new behaviour (use “fdisk -c”) it will create aligned partitions by default. Still you have to go through a menu manually and for ease of use when configuring lots of volumes, or when scripting, the old “sfdisk” method was handy.

As you see, sfdisk has overwritten the existing partition happily without any warning. In order to overcome, I have been searching for a better way to do this under Linux 6 distros. I found that the “parted” utility provides a much better, safer and cleaner way to set alignment but it took a moment to figure out how to make it create aligned partitions directly from the command line.

We now have a 1MB aligned partition. It shows as 1049 KB because default reporting is 1MB = 1000000 bytes. “Engineering” style Megabytes ( Mebibytes) don’t seem to be supported so chose either 512 byte blocks, or single bytes: # parted /dev/sdb "unit s print"

Also note that in Red Hat 6 (and CentOS 6 what I’m using) Oracle ASMLib is no longer supported. ASMLib somehow required ASM volumes to be placed on the first partition of a volume (therefore the requirement to align disks). Although there are ways to avoid having to use DOS partitioning, that leads into other trouble. Fortunately, if you do NOT use ASMLib but use Linux UDEV to provide volumes for ASM, then you don’t have to use partitioning at all (and thus this whole article is redundant).

How you do this is nicely and simply described on Using udev on RHEL 6 / OL 6 to change disk permissions for ASM for example. Make sure you use a method that creates ASM volumes directly on the disk (i.e. on /dev/sdb) and does not use partitioning (/dev/sdb1).