LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-01-2006, 12:14 PM   #1
bigqueso
LQ Newbie
 
Registered: Jun 2006
Location: Salt Lake City, UT, USA
Distribution: Ubuntu (laptop,home), Suse (work)
Posts: 8

Rep: Reputation: 0
Max read size for O_DIRECT file I/O


I'm trying to use O_DIRECT to open and read some very large files. I'm trying to read 2-30 GB files into memory and I don't need the caching facilities of the OS since I plan to fill the entire memory space.

The man page for open is a little sparse on details (man 2 open, man 2 read) on the maximum size I can use to read using the O_DIRECT flag when opening a file:

Code:
  
  int in_fd = open(filename, O_RDONLY | O_DIRECT | O_LARGEFILE);
  // Get the file size
  struct stat64 statbuf;
  fstat64(in_fd, &statbuf);

  // Allocate memory for the file and align it to 512 bytes.
  int d_mem=512;
  char* idata = (char*)malloc(statbuf.st_size+d_mem);
  size_t addr = (size_t)idata;
  size_t offset = addr % d_mem;
  if (offset)
    addr += d_mem - offset;
  char* data = (char*)addr;

  // What I need to know is how to determine what maxReadSize is
  size_t maxReadSize = 0x00800000;
  size_t remaining = statbuf.st_size;
  size_t total = 0;
  while (remaining > 0) {
    size_t toRead = remaining>maxReadSize?maxReadSize:remaining;
    ssize_t result = read(in_fd, data + total, maxReadSize);
    if (result <= 0) {
      // Do error stuff ....
      return 1;
    }
    total += toRead;
    remaining -= toRead;
  }
  if (total != statbuf.st_size) {
    fprintf(stderr, "Didn't read the right number of things\n");
    // Do error stuff ....
    return 1;
  }
  close(in_fd);
What I need to know is how to determine what the maxReadSize I can feed to read. There doesn't seem to be as many restrictions for cases not using O_DIRECT.

Thanks,
James
 
Old 06-02-2006, 10:47 AM   #2
bigqueso
LQ Newbie
 
Registered: Jun 2006
Location: Salt Lake City, UT, USA
Distribution: Ubuntu (laptop,home), Suse (work)
Posts: 8

Original Poster
Rep: Reputation: 0
Is there another forum or mailing list I could ask this question on?

Thanks,
James
 
  


Reply

Tags
code


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Samba and path/file name max size? cdxz Linux - Software 5 11-11-2016 03:18 AM
Whats the max file size on FC2? deanbrown3d Linux - Newbie 4 03-08-2005 03:47 PM
increasing max file size arokh AIX 4 08-31-2004 03:59 AM
mkisofs, is there a max file size limitation? tsw Linux - Software 4 07-27-2004 04:10 PM
max size file system f.montel Linux - Hardware 0 05-27-2004 04:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration