Bug 248405 - the open(2) man page lists an incorrect requirement on O_DIRECT buffer alignment
the open(2) man page lists an incorrect requirement on O_DIRECT buffer alignment
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: man-pages (Show other bugs)
5.0
All Linux
low Severity low
: ---
: ---
Assigned To: Ivana Varekova
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-07-16 13:40 EDT by Jeffrey Moyer
Modified: 2013-04-12 15:14 EDT (History)
0 users

See Also:
Fixed In Version: RHBA-2008-0587
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-07-16 09:37:44 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
reproducer program (562 bytes, text/plain)
2007-07-16 13:40 EDT, Jeffrey Moyer
no flags Details

  None (edit)
Description Jeffrey Moyer 2007-07-16 13:40:15 EDT
Description of problem:
O_DIRECT I/O must be allowed to buffers aligned on a 512-byte boundary, and must
allow an I/O size that is a multiple of 512 bytes.  This works properly on every
other architecture.

Version-Release number of selected component (if applicable):
2.6.18-32.el5

How reproducible:
100%

Steps to Reproduce:
Run the attached reproducer.
Comment 1 Jeffrey Moyer 2007-07-16 13:40:15 EDT
Created attachment 159344 [details]
reproducer program
Comment 2 Jan Glauber 2007-07-23 08:43:18 EDT
On s390 the I/O size is not 512 bytes but 4096 bytes! Therefore this testcase
does produce an error (due to the check in fs/direct_io.c: __blockdev_direct_IO()).

Reading 512 bytes with direct-IO is therefore not supported on s390... rejecting.
Comment 3 Jeffrey Moyer 2007-07-23 09:58:27 EDT
Jan,

I discussed this with Zach Brown, and he said that this is an ABI that the
kernel provides to userspace.  Alignment on 512 byte boundaries must be
supported, so this is a bug.  Surely you can read in 4k and zero out the
remainder of the block?  It's not optimal, but should only be required for the
first/last partial blocks.
Comment 4 Jan Glauber 2007-07-24 07:47:04 EDT
Jeffrey,

it is not correct that the direct-IO blocksize is always 512 bytes. It happens
to be 512 bytes on other architectures but on s390 the dasd device blocksize
always was 4K. Direct-IO must work with the blocksize of the device!

Apparently the man page for open is wrong:

Under Linux 2.4 transfer sizes, and the alignment of user buffer and file offset
must all be multiples of the logical block size of the file system. Under Linux
2.6 alignment to 512-byte boundaries suffices.
Comment 5 Zach Brown 2007-07-24 13:15:51 EDT
I asked around, and the man page does seem to be wrong.

The change from 2.4 wasn't to force 512B as a standard minimum alignment, but to
let the app operate at disk sector alignment instead of fs block alignment.  I
was confused and mislead Jeff.

So apps using O_DIRECT are, supposedly, expected to figure out the sector size
of the underlying block device and align accordingly.  The code seems to match
this, working with bdev_hardsect_size() when a block device for the inode is
available.
Comment 6 Jeffrey Moyer 2007-07-24 13:20:30 EDT
Thanks for the update, Zach.  Sorry to waste your time, Jan!
Comment 7 Jan Glauber 2007-07-25 05:21:25 EDT
We should update the man page, but I don't know how this could be done, maybe you
open a bugzilla against the man page :)
Comment 8 Jeffrey Moyer 2007-07-25 13:02:13 EDT
(In reply to comment #7)
> We should update the man page, but I don't know how this could be done, maybe you
> open a bugzilla against the man page :)

Actually, I don't see that verbiage in the read(2) or write(2) man pages on my
RHEL 5 system.  At which man page are you looking?
Comment 9 Jan Glauber 2007-07-27 15:41:18 EDT
its the open man page, man 2 open, look for O_DIRECT (format broke by paste):

O_DIRECT
Try to minimize cache effects of the I/O to and from this
file. In  general  this  will degrade performance, but it is useful
in special situations, such  as  when  applications  do  their
own caching.   File I/O is done directly to/from user space
buffers. The I/O is synchronous, i.e., at the completion of a read(2)
or write(2),  data  is  guaranteed to have been transferred.
Under Linux 2.4 transfer sizes, and the alignment of user  buffer
and file  offset  must all be multiples of the logical block size
of the file system. Under Linux 2.6 alignment  to  512-byte
bound-aries suffices.

The last sentence is wrong. For 2.6 the alignment must fit the block size
of the device.
Comment 16 errata-xmlrpc 2008-07-16 09:37:44 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2008-0587.html

Note You need to log in before you can comment on or make changes to this bug.