Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Direct I/O questions
Hi James,
I can confirm you two things:
linux support direct i/o (with o_direct), SLES9 seems to have o_direct broken.
I'm subbmitting the program I'm using to test.
It works on SLES8, debian with 2.6.x kernels, ubuntu on several
filesystems: ext2, ext3, xfs, reiserfs.
If I manage to find a fedora I'll go on testing.
I fear something is not working as expected in SuSE 2.6.5-7.97 kernel.
Regards
Fabrizio
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <asm/fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *message; int fd =3D open("/tmp/xxx", O_RDONLY|O_DIRECT); int len, pagesize =3D getpagesize(); posix_memalign((void **)&message, pagesize, pagesize); if(fd < 0) { printf("Unable to open file, errno is %d.\n", errno); } else { if((len =3D read(fd, message, pagesize)) < 0) { perror("read"); } else { printf("%d bytes read from file.\n", len); printf("Message: %s", message); }
}
> -----Original Message----- > From: oracle-l-bounce_at_freelists.org=20 > [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Kramer, James P. > Sent: Wednesday, December 08, 2004 9:59 PM > To: oracle-l_at_freelists.org > Subject: Direct I/O questions >=20 >=20 > > First things first, this isn't an oracle question but=20 > rather a series =3D > of questions based on a previous message on the oracle-l=20 > list. If you =3D > think I should post it on a different list please let me know=20 > which one. > >=3D20 > > The message I am talking about can be found here. > > http://www.freelists.org/archives/oracle-l/02-2004/msg03007.html > >=3D20 > > Also, I am new to the Linux world (just thought I'd let you=20 > know what =3D > kind of a guy your dealing with...newbie). > >=3D20 > > Here is the following information about our Linux server. > >=3D20 > > We are running SUSE LINUX Enterprise Server 9. From the=20 > files located =3D > in /usr/src, the version is 2.6.5-7.97. I'm not sure how=20 > else to get =3D > the version. > > There are 8 IA64 processors. > >=3D20 > > I have been researching ways to get direct I/O to work on=20 > our Linux =3D > machine when I stumbled across the above message. Within the=20 > message =3D > was a small code example that tested direct I/O. I tried=20 > this code out =3D > to see if it would work. I could not get the code to compile=20 > as is. =3D > With some modifying (changed the headers), I was able to get it to =3D > compile but the direct I/O read kept giving me EINVAL (Invalid =3D > Argument). > >=3D20 > > Here is the modified code that I used. > >=3D20 > > #include <stdio.h> > > #include <stdlib.h> > > #include <sys/types.h> > > #include <sys/stat.h> > > #include <errno.h> > > #include <string.h> > > #include <fcntl.h> > > #include <unistd.h> > > #define BUFFSIZE 65536 > > #define ALIGN 4096 > >=3D20 > > int main()=3D20 > > {=3D20 > > char *buff; > > int stat1=3D3D0,stat2=3D3D0,stat3=3D3D0; > > int fd1=3D3D0,fd2=3D3D0; > > if (stat3=3D3Dposix_memalign((void **)&buff,ALIGN,BUFFSIZE)) { > > fprintf(stderr,"ALIGN ERR:%s\n",strerror(stat3)); > > exit(0); > > } > >=3D20 > > fd1=3D3Dopen("/home/rrd/workspace/IORead.txt", =3D > O_RDONLY|O_DIRECT,S_IRWXU); > >=3D20 > > =3D > fd2=3D3Dopen("/home/rrd/workspace/IOWrite.txt",O_CREAT|O_WRONLY| > O_DIRECT,S_=3D > IRWXU); > > while(stat1=3D3Dread(fd1,buff,BUFFSIZE)) { > > if (errno) { > > fprintf(stderr,"READ ERR:%s\n",strerror(errno)); > > exit(0); > > } > > stat2=3D3Dwrite(fd2,buff,(unsigned) stat1); > > if (errno) { > > fprintf(stderr,"WRITE ERR:%s\n",strerror(errno)); > > exit(0); > > } > > } > > close(fd1); > > close(fd2); > > =3D20 > > return 0; > > } > >=3D20 > > Also, is there a programmatic way of retrieving the alignment and ==3D
> block size? I have seen the fcntl call for F_DIOINFO. =20 > However, I have =3D > read articles that Linux doesn't have this. Instead one must=20 > use ioctl =3D > with XFS_IOC_DIOINFO. When I do a search in /usr/, the only=20 > *DIOINFO =3D > that I find is in xfs_fs.h. When I try calling this=20 > function, I get an =3D > error and from what I gather it is because the file doesn't=20 > support this =3D > type of ioctl. Does this mean I am missing some feature? > >=3D20 > > I have been searching Google about direct I/O and have come across ==3D
> countless articles that seem to contradict one another. Some=20 > articles =3D > say that Linux doesn't support O_DIRECT and that you need to convert ==3D
> What must be done to the file system (if anything) to get=20 > direct I/O to =3D > work? Do I need to convert to XFS? > >=3D20 > > Could it be that I'm using the wrong libraries? How can I=20 > find out =3D > what libraries it is using? > >=3D20 > > Is there anything I should look at on the server to make=20 > sure I have =3D > the most up-to-date stuff? Any other ideas on how I should proceed? > >=3D20 > > Any help would greatly be appreciated. > >=3D20 > > James Kramer > >=3D20 > >=3D20 > > THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE =3D > PROPRIETARY MATERIAL and is thus for use only by the intended=20 > recipient. =3D > If you received this in error, please contact the sender and=20 > delete the =3D > e-mail and its attachments from all computers.=3D20 > >=3D20 > >=3D20 > -- > http://www.freelists.org/webpage/oracle-l >=20
-- http://www.freelists.org/webpage/oracle-lReceived on Fri Dec 10 2004 - 02:16:59 CST
![]() |
![]() |