On Sat, 10 Aug 2002, Jamie Lokier wrote:
>
> Don't forget to include the need for mmap(... MAP_ANON ...) prior to the
> read.
Ahhah! But I _don't_.
Yes, with read() you have to do a brk() or mmap(MAP_ANON) (and brk() is
the _much_ faster of the two).
But with mmap() you need to do a fstat() and a munmap() (while with read
you just re-use the area, and we'd do the right thing thanks to the
COW-ness of the pages).
So I don't think the MAP_ANON thing is a loss for the read.
And read() is often the much nicer interface, simply because you don't
need to worry about the size of the file up-front etc.
Also, because of the delayed nature of mmap()/fault, it has some strange
behaviour if somebody is editing your file in the middle of the compile -
with read() you might get strange syntax errors if somebody changes the
file half-way, but with mmap() your preprocessor may get a SIGSEGV in the
middle just because the file was truncated..
In general, I think read() tends to be the right (and simpler) interface
to use if you don't explicitly want to take advantage of the things mmap
offers (on-demand mappings, no-write-back pageouts, VM coherency etc).
Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Thu Aug 15 2002 - 22:00:22 EST