[lkml]   [2003]   [Apr]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: O_DIRECT alignment requirements ?
Rob van Nieuwkerk <> wrote:
> Joel Becker wrote:
> > 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().
> Hi Joel,
> Thank you for your reaction.
> I get 4096 with BLKBSZGET on several unmounted partitions on my system
> (RH 2.4.18-27.7.x kernel). Some give 1024 .. Maybe it is because I
> had them mounted first and unmounted them for the test ?

Yes, the blockdev initially comes up with a 1024 softblocksize. When you
mount a filesystem on the device, the soft blocksize gets rewritten to
(typically) 4096.

Unfortunately it remains at 4096 after the fs is unmounted, which is rather

In 2.5 you should use BLKSSZGET (sector-size, not block-size) to work out the
supported alignment.

I'm not sure what a good and general solution is really. You might have to
resort to probing the size at runtime, by trying increasing blocksizes until
it works.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:34    [W:0.061 / U:3.428 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site