Re: mmap to read an entire file



On Fri, 03 Mar 2006 15:38:30 -0500, Henry Townsend wrote:

Thomas Maier-Komor wrote:
You might be able to even
improve performance by using posix_madvise and giving a hint to the
memory subsystem how you are going to access the file.

Thanks, good idea. Looks like POSIX_MADV_SEQUENTIAL is just the ticket.
And according to the Solaris man page this is how both cat(1) and cp(1)
work, which clearly indicates the system architects thought
mmap+sequential is faster than read() in a loop.

Note that you can use posix_fadvise() with read(), and GNU utils
still use read() with an 8k buffer for cat/cp like operations (because
it's faster -- even faster than sendfile() last I heard).
Also remember that you are open to DOS attacks if anyone can truncate
files you are mmap()'ing.

--
James Antill -- james@xxxxxxx
http://www.and.org/and-httpd

.



Relevant Pages

  • Re: mmap to read an entire file
    ... Henry Townsend wrote: ... improve performance by using posix_madvise and giving a hint to the ... memory subsystem how you are going to access the file. ... it in the buffer you passed to read. ...
    (comp.unix.programmer)
  • Re: Shared memory and IOCP
    ... in the buffer, so that there is no need to worry about synchronizing ... messages between windows apps. ... of the memory subsystem. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Why is there no difference between buffered and unbuffered file IO?
    ... >> Hint, hint. ... >> I am afraid this hint is lost on the OP. ... >> and you issue a single write call for the entire buffer. ...
    (comp.os.linux.development.system)
  • Re: mmap to read an entire file
    ... Thomas Maier-Komor wrote: ... improve performance by using posix_madvise and giving a hint to the ... memory subsystem how you are going to access the file. ... And according to the Solaris man page this is how both catand cpwork, which clearly indicates the system architects thought mmap+sequential is faster than readin a loop. ...
    (comp.unix.programmer)
  • Re: Why is there no difference between buffered and unbuffered file IO?
    ... > Hint, hint. ... > I am afraid this hint is lost on the OP. ... > You do allocate a buffer large enough to contain the entire file, ... > and you issue a single write call for the entire buffer. ...
    (comp.os.linux.development.system)