On Thu, May 04, 2006 at 10:14:20PM +0200, Michael Kerrisk wrote: > > > > > > are correct; an "r+m" file is read() not mmaped. > > > > > > > > > > Have you written a test program that verifies (presumably via > > > > > monitoring via 'strace') how 'm' changes the behaviour of stdio > > > > > with respect to the use of mmap()? > > > > Erm, yes, thats what I'm talking about (and is strace exactly what I > > > > did). But I'm not sure if I understand you .. I verified that all 3 > > > > routines mmap() a file if "m" is given (and it is read-only), and do > > > > not mmap() it if "m" is not given (or if it is not read-only). > > > > > > > > I include now the test program :) > > > > > > Yes, but did you verify: > > > > > > -- which file is being mmap()ed? (There might be many other > > > unrelated mmap() calls going on.) > > Yes; note that it only happens after you fread() for the first time. > > > > > -- whether the behaviour changes if 'm' is removed from the fopen()? > > > (the strace output shd be different). > > Yes: > > > > routines mmap() a file if "m" is given (and it is read-only), and do > > > > not mmap() it if "m" is not given (or if it is not read-only). > > Hmmm -- I'm not seeing this. Can you post for each of the two > test cases: > > -- the fopen() call that is used. > > -- the command line that is used to run the program. > > -- the results of grep the strace output using: > > egrep '(mmap|open|read)' Sure, (using strace -e mmap2,open,read instead):
fopen "r": |... |open("/tmp/fp.c", O_RDONLY) = 3 |mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f3a000 |read(3, "#include <sys/types.h>\n#include "..., 4096) = 460 |read(3, "", 4096) = 0 fopen "r+m": |... |open("/tmp/fp.c", O_RDWR) = 3 |mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f8e000 |read(3, "#include <sys/types.h>\n#include "..., 4096) = 462 |read(3, "", 4096) = 0 fopen "rm": |... |open("/tmp/fp.c", O_RDONLY) = 3 |mmap2(NULL, 461, PROT_READ, MAP_SHARED, 3, 0) = 0xb7f1c000 fdopen "rm": |... |open("/tmp/fp.c", O_RDONLY) = 3 |mmap2(NULL, 447, PROT_READ, MAP_SHARED, 3, 0) = 0xb7fc3000 fdopen "r+m": |... |open("/tmp/fp.c", O_RDONLY) = 3 |mmap2(NULL, 447, PROT_READ, MAP_SHARED, 3, 0) = 0xb7fc3000 fdopen "r": |... |open("/tmp/fp.c", O_RDWR) = 3 |mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f06000 |read(3, "#include <sys/types.h>\n#include "..., 4096) = 444 |read(3, "", 4096) = 0 freopen "r": |... |open("/tmp/fp.c", O_RDONLY) = 2 |mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f0f000 |read(2, "#include <sys/types.h>\n#include "..., 4096) = 466 |read(2, "", 4096) = 0 freopen "r+": |... |open("/tmp/fp.c", O_RDWR) = 2 |mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fc1000 |read(2, "#include <sys/types.h>\n#include "..., 4096) = 468 |read(2, "", 4096) = 0 freopen "r+": |... |open("/tmp/fp.c", O_RDONLY) = 2 |mmap2(NULL, 467, PROT_READ, MAP_SHARED, 2, 0) = 0xb7f20000 If it matters: Linux andromeda 2.6.15-1-686 #2 Mon Mar 6 15:27:08 UTC 2006 i686 GNU/Linux GNU C Library stable release version 2.3.6, by Roland McGrath et al. Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 4.0.3 (Debian 4.0.3-1). Compiled on a Linux 2.6.13 system on 2006-04-14. Available extensions: GNU libio by Per Bothner crypt add-on version 2.1 by Michael Glad and others GNU Libidn by Simon Josefsson linuxthreads-0.10 by Xavier Leroy BIND-8.2.3-T5B libthread_db work sponsored by Alpha Processor Inc NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk Thread-local storage support included. For bug reporting instructions, please see: <http://www.gnu.org/software/libc/bugs.html>. This seems to have been newly-implemented in glibc 2.3 (from the NEWS file). Justin -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]