read() wont allow me to read files larger than 2 gig (on a 64bit)


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users read() wont allow me to read files larger than 2 gig (on a 64bit)
# 8  
Old 12-26-2009
Two things

Read over the man page for lseek64 and make sure you are using the correct compiler flags. i do not believe you are.

Secondly, The read system call does guarantee that it will fill a buffer completely. Trying issuing a second read and see if you get your data.
# 9  
Old 12-27-2009
Thanks for all your replies,
but it seems that its not possible to use posix read to read files larger than 2.1 gig.
This is according to the uberpenguin linus
http://git.kernel.org/?p=linux/kerne...iff;h=e28cc715

At somepoint I guess it was possible but the kernel has regressed to only allow smaller chunks being read.

kernelsourcetree/fs/read_write.c
PHP Code:
/*
 * rw_verify_area doesn't like huge counts. We limit
 * them to something that fits in "int" so that others
 * won't have to do range checks all the time.
 */
#define MAX_RW_COUNT (INT_MAX & PAGE_CACHE_MASK)

int rw_verify_area(int read_writestruct file *fileloff_t *ppossize_t count); 
This was rather annoying, it would have been nice if this had been documented outside of the kernelsource and kernelmailinglist.
# 10  
Old 12-27-2009
Wait -- you're trying to read >2gb all at once?? Do you actually need it all at once? If not, this is extremely bad programming practice!

Why not just map in the file? That'll turn it into a memory area with one call, letting you use it like you'd loaded it all at once without actually having to do so, it'll autoload it as you use it(though you can force it to load it all with the MAP_POPULATE flag). See man mmap.
# 11  
Old 12-28-2009
Quote:
Originally Posted by Corona688
Wait -- you're trying to read >2gb all at once?? Do you actually need it all at once? If not, this is extremely bad programming practice!

Why not just map in the file? That'll turn it into a memory area with one call, letting you use it like you'd loaded it all at once without actually having to do so, it'll autoload it as you use it(though you can force it to load it all with the MAP_POPULATE flag). See man mmap.
No, it is most definitely *not* an "extremely bad programming practice". I've worked on real-world systems that access tens if not hundreds of gigabytes at a time. In RAM. They *do* exist.

This code:
Code:
/*
 * rw_verify_area doesn't like huge counts. We limit
 * them to something that fits in "int" so that others
 * won't have to do range checks all the time.
 */
#define MAX_RW_COUNT (INT_MAX & PAGE_CACHE_MASK)

int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count);  

is nothing more nor less than utter abdication of 64-bit processing.
# 12  
Old 01-06-2010
Quote:
Originally Posted by achenle
No, it is most definitely *not* an "extremely bad programming practice". I've worked on real-world systems that access tens if not hundreds of gigabytes at a time. In RAM. They *do* exist.
They certainly do exist, hence my asking whether he actually needed it all in RAM at once. Nine out of ten times I see someone slurping an enormous wad of data into RAM, they'd have been better off doing an mmap...
# 13  
Old 01-06-2010
achenle - just becuase you saw somebody do something does not make it good practice.
Even in commerical software.

My company bought a package (C/shell/perl) that had non-terminating loops in it.
Does that mean it was good practice - or good software? We sent it back.
# 14  
Old 01-11-2010
Quote:
Originally Posted by jim mcnamara
achenle - just becuase you saw somebody do something does not make it good practice.
Even in commerical software.

My company bought a package (C/shell/perl) that had non-terminating loops in it.
Does that mean it was good practice - or good software? We sent it back.
There's a very good reason to read a large amount of data with just one system call: in a contended file system, doing so allows for better scheduling of IO to data blocks that are more likely to be contiguous on disk, thus reducing overhead lost to disk head seeks. And I haven't SEEN it done, I've DONE it. And improved IO throughput on said system by about 20 or 30 percent.

Fortunately for the customer, the OS wasn't Linux, which has punted the ability to do large read and writes.

I guess 2 gig is enough for everybody, right?

Your company buying buggy software is about as relevant as the color of your car.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

2. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

3. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

4. Shell Programming and Scripting

How to read log files from last read

Hi i am looking a way to look at a log file(log.txt) from the last time I've read it. However after some days the main log file(log.txt) is rename to (log.txt.1). So now i will have two log files as below. log.txt.1 log.txt Now, i have to read the log from the point where i have left... (3 Replies)
Discussion started by: sumitsks
3 Replies

5. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

6. UNIX for Dummies Questions & Answers

Read statement within while read loop

hi, this is my script #!/bin/ksh cat temp_file.dat | while read line do read test if ]; then break else echo "ERROR" fi done when i execute this code , the script does wait for the user input . it directly prints "ERROR" and terminates after the no. of times as there... (3 Replies)
Discussion started by: siva1612
3 Replies

7. Shell Programming and Scripting

Read Embedded Newline characters with read (builtin) in KSH93

Hi Guys, Happy New Year to you all! I have a requirement to read an embedded new-line using KSH's read builtin. Here is what I am trying to do: run_sql "select guestid, address, email from guest" | while read id addr email do ## Biz logic goes here done I can take care of any... (6 Replies)
Discussion started by: a_programmer
6 Replies

8. Programming

Cannot read a file with read(fd, buffer, buffersize) function

# include <stdio.h> # include <fcntl.h> # include <stdlib.h> # include <sys/stat.h> int main(int argc, char *argv) { int fRead, fPadded, padVal; int btRead; int BUFFSIZE = 512; char buff; if (argc != 4) { printf ("Please provide all of the... (3 Replies)
Discussion started by: naranja18she
3 Replies

9. Shell Programming and Scripting

Can I use read to read content of a variable

Can I use the read command to read the contents of a variable? I'm trying by using the following code and getting nothing back. I'm in a Linux environment. #!/bin/ksh IFS=~ VAR1=1~2~3~4 echo $VAR1 | read a b c d print "$a $b $c $d" (9 Replies)
Discussion started by: nmalencia
9 Replies
Login or Register to Ask a Question