Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Direct I/O questions

RE: Direct I/O questions

From: Magni Fabrizio <Fabrizio.Magni_at_rasnet.it>
Date: Mon, 13 Dec 2004 16:19:01 +0100
Message-ID: <BFCF159FFD14F444B205968F32DBD5BB6A541B@MAILEX01.rasgroup.ita.localnet>


Hello James,
eventually I was able to make O_DIRECT work even on x86_64 (kernel 2.6.5-7.97-smp and 2.6.9 vanilla).
Unfortunately I haven't got any itanium where to test it.

I had to create a file named xxx in the same directory of the executable with:

dd if=3D/dev/zero of=3Dxxx bs=3D4196 count=3D100

I tested on ext2, ext3, reiserfs.

Regards
Fabrizio

The code (Thanks to Andrea Arcangeli for the revision):

#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>

#define O_DIRECT 040000 /* direct disk access hint */

int main(int argc, char *argv[])
{

     int fd =3D open("xxx", O_RDWR|O_DIRECT);
     int len, pagesize =3D getpagesize();
     char *message;

        printf("Pagesize: %d\n", pagesize);

     posix_memalign((void **)&message, pagesize, pagesize);
     memset(message, 0xff, pagesize);
     printf("%p\n", message);
     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);
          }

    }
    close(fd);

    return 0;
}

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Dec 13 2004 - 09:20:13 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US