Re: O_DIRECT alignment requirements ?

From: Joel Becker (Joel.Becker@oracle.com)
Date: Wed Apr 09 2003 - 10:48:36 EST


On Wed, Apr 09, 2003 at 02:16:08PM +0200, Rob van Nieuwkerk wrote:
> I plan to use O_DIRECT in my application (on a partition, no fs).
> It is hard to find info on the exact requirements on the mandatory
> alignments of buffer, offset, transfer size: it's easy to find many
> contradicting documents. And checking the kernel source itself isn't
> trivial.

        In 2.4, your buffer, offset, and transfer size must be soft
blocksize aligned. That's the output of BLKBSZGET against the block
device. For unmounted partitions that is 512b, for most people's ext3
filesystems that is 4K. It is, FYI, the number set by set_blocksize().
        In 2.5, the alignment restrictions have been relaxed. Your
offset, buffer, and transfer size must all be aligned on the hardware
sector size. That is the output of BLKSSZGET against the block device,
and is also what get_hardsect_size() returns in the kernel. For almost
all disks this number is 512b, so you can do O_DIRECT on 512b alignment
for a raw disk or for an ext3 filesystem. About the only thing that
may not have a 512b hardware sector size is a CD-ROM.

Joel

-- 

"Hey mister if you're gonna walk on water, Could you drop a line my way?"

Joel Becker Senior Member of Technical Staff Oracle Corporation E-mail: joel.becker@oracle.com Phone: (650) 506-8127 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Apr 15 2003 - 22:00:18 EST