Pythian has openings for MySQL and MS SQL Server DBAs in each of our offices in Ottawa, Canada; Boston, USA; Dubai, UAE; and Hyderabad, India. If you are a MySQL and/or SQL Server DBA and would like to evaluate this opportunity, please send us your résumé with an introductory paragraph to hr@pythian.com.

Aligning ASM Disks on Linux

By Christo Kutrovsky March 30th, 2007 at 3:03 pm
Posted in Group Blog PostsOracle

Linux is a wonderful operating system. However there are a number of things that one needs to do to make sure it runs as efficiently as possible. Today, I would like to share one of them. It has to do with using ASM (Automatic Storage Manager) disks.

In Linux, there are 2 major ways to create ASM disks.

  1. you can use ASMlib kernel driver
  2. you can use devmapper devices

You could also use /dev/raw devices, but I don’t recommend this at all. I will write another blog explaining why.

Regardless of which approach you take, you have to create partitions on your LUNs. Starting with version 2, ASMlib won’t let you use the entire disk. You have to create a partition.

The reason to force the creation of this partition is to make explicit that something exists on that device, and that it’s not empty. Otherwise, some OS tools assume the disk is unused and could mark it, or just begin using it, and override your precious Oracle data.

(Read more after the jump.)

Most people would use the “fdisk” command provided by Linux distributions. This command is quite old, and so has some old-fashioned DOS-style behaviours built in.

When you create your partition, by default, the unit of measure is based on cylinders. Here’s a typical print command from fdisk on a 35 GB disk:

Command (m for help): p

Disk /dev/sde: 35.8 GB, 35864050176 bytes
64 heads, 32 sectors/track, 34202 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1       34202    35022832   83  Linux

Notice where it says Units. 2048 cylinders, 512 bytes each = 1 MB. So your units are 1 MB. only when the disk is relatively small.

When your disk is larger — which is far more typical in the database world, especially with raid arrays — the Units change:

Disk /dev/sdc: 513.5 GB, 513556348928 bytes
255 heads, 63 sectors/track, 62436 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       62436   501517138+  83  Linux

Take a look at the Units number. It’s 8 MB minus 159.5 kB. This is a very weird number, totally misaligned with any possible stripe size or stripe with (stride).

This, by itself, is not a big deal, since the best practice is to have 1 partition per LUN, which represents the entire device. However, this is not the end of it. If you switch to sector mode, you will see what the true start offset is:

Command (m for help): u
Changing display/entry units to sectors

Command (m for help): p

Disk /dev/sdc: 513.5 GB, 513556348928 bytes
255 heads, 63 sectors/track, 62436 cylinders, total 1003039744 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1              63  1003034339   501517138+  83  Linux

Notice the start sector, 63th sector. That’s the 31.5 kB boundary. This value does not align with any stripe size. Stripe sizes are usually multiples of 2 and above 64 kB.

The result is, every so often, a block will be split between 2 separate hard disks, and the data will be returned at the speed of the slower (busier) device.

Assuming the typical 64 kB stripe (way too low, as I will discuss in another blog), and 8 kB database block size, every 8th block will be split between 2 devices. If you do the math, that’s about 12% of all your I/O. Not a significant number, but when you consider how discs are arranged in RAID 5, instead of a logical write being 2 reads and 2 writes (data+checksum, update, then write them back), each logical write could be 4 reads and 4 writes, significantly increasing your disk activity.

The solution?

Before you create your partitions, switch to “sector” mode, and create your partitions at an offset that is a power of 2.

I typically create my partitions at the 16th megabyte (32768th sector). Essentially, I “waste” 16 MBs, but gain aligned I/O for stripe width of up to 16 MB.

The procedure to create an aligned disk is:

[~]# fdisk /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

When building a new DOS disklabel, the changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.

Command (m for help): u
Changing display/entry units to sectors
Command (m for help): p
Disk /dev/sdg: 143.4 GB, 143457779712 bytes
255 heads, 63 sectors/track, 17441 cylinders, total 280190976 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot      Start         End      Blocks   Id  System
Command (m for help): n
Command action
e   extended
p   primary partition (1-4) p
Partition number (1-4): 1
First sector (63-280190975, default 63): 32768
Last sector or +size or +sizeM or +sizeK (32768-280190975, default 280190975):
Using default value 280190975
Command (m for help): p
Disk /dev/sdg: 143.4 GB, 143457779712 bytes
255 heads, 63 sectors/track, 17441 cylinders, total 280190976 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/sdg1           32768   280190975   140079104   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

This way, the disk is aligned. When it is aligned at least on 1MB, then the ASM files will be also aligned at the 1MB boundary.

This alignment also applies to ext3 file systems. This file system takes it a step further, allowing you to provide the array stride as a parameter during creation, optimizing writing performance (I have not tested this). Look in the man pages for more information.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Slashdot
  • Google
  • del.icio.us
  • Facebook
  • bodytext
  • Technorati
  • TwitThis
  • Reddit
  • Spurl
  • De.lirio.us
  • Furl
  • blogmarks
  • Ma.gnolia
  • E-mail this story to a friend!

10 Responses to “Aligning ASM Disks on Linux”

  1. LSC Says:

    Hi Christo

    I think this paper from Oracle
    does mention to skip at least 1MB as Best Practice in ASM to avoid missaligment, not sure if can apply in Linux, I guess so.

    Great post

    Thanks

  2. Christo Kutrovsky Says:

    Yes it does mention it for solaris.

    The aligment applies to any OS. I must point out, that the default partitions in linux are worst case for alignment.

  3. Gustavo Tamaki Says:

    Hi Christo,

    In your example, with a stripe size of 64KB, the number of unaligned I/Os are about 12.5%. If I consider the ASM stripe size of 1MB, can I assume that this number would drop to less than 1%?

    For a storage configured in RAID-10, the effect would be negligible, since the unalignment occurs only in the stripe boundaries and there’s no right penalty, correct?

    Gustavo

  4. Christo Kutrovsky Says:

    Hi Gustavo,

    The aligning has to do with the RAID level stripe size, not with the ASM stripe size.

    There’s always a “penalty” on miss-aligned IO. You are using 2 devices, when you could have used only 1. Note, that using multiple devices is not bad by itself. What’s bad is reading small amounts of data from multiple devices, as opposed to just 1.

    You generally want to be doing at least 512kb io sizes per IO device, to achieve 90% of it’s sequencial read speed (in my testing).

  5. Hai Wu Says:

    Hi Christo,
    I was told by SAN administrators here that there’s no way to change the stripe size for EMC LUN to be 1MB here, since it has already been set to 128KB for a big chunk of RAID5, every LUN will come from that one.

    In this case, there’s no choice but to accept that as a fact. Is it necessary to do alignment as above for 128KB stripe size?

    Thanks,
    Hai

  6. Christo Kutrovsky Says:

    Yes it is. Because the default is a not a multiple of your stripe size. As long as it is a multiple of your stripe size you are good.

    So if you offset at the 16th Mb as I do, then you will be alligned for all stripe sizes that are a power of 2, up to 16 Mb stripe size.

    Now EMC has these hypervolumes that have the weird stripe sizes of 960 kb, that completelly destroys any allignement attempts :)

  7. Hai Wu Says:

    Thanks Christo. Since we aren’t going to get any stripe size that would be different from 128KB in this case, I guess I could configure the first sector to be 256 (128K) instead of 32768 (16M), so that it would do alignment for 128K stripe size. Do you see any issues in doing this?
    Thanks,
    Hai

  8. Christo Kutrovsky Says:

    It’s all good. However, consider this. ASM does it’s allocations in 1mb “blocks”. I wouldn’t go under 1mb.

    However, given what I know so far, 256k will be fine. Remembe we’re talking about saving ~760 kb here …

  9. David Edwards Says:

    [Editorial Note: Christo pointed out that the sidebar on this page was getting pushed to the very bottom in IE browsers. The culprit was the long raw URL in the first comment (by LSC). To fix it, I edited the comment, condensing the URL into the words “this paper from Oracle”. The rest of that comment is untouched.]

  10. Hai Wu Says:

    Ok. thanks for the confirmation. I will go with 2048 (1mb) then.

Leave a Reply

Filling out the following captcha not only allows us to cut down on automated blogspam but also helps digitize books. Please feel free to send comments on this approach directly to Paul at vallee@pythian.com.

NOTE: After submitting your comment, verify that it is added to the blog. New comments will be marked as "waiting for moderation" (we only moderate for spam). If the level of spam is as low as we hope, we will bypass this step.