Re: mmap() versus read()

Erik Corry (erik@arbat.com)
Sun, 8 Mar 1998 12:28:09 +0100 (MET)


In article <Pine.LNX.3.96dg4.980307222805.24934K-100000@twinlark.arctic.org> you wrote:

> On Sun, 8 Mar 1998, Kenneth Albanowski wrote:

> > My assumption has always been that mmap() isn't well suited for reading
> > through a file once (random or sequential doesn't matter), as the kernel
> > has no way of knowing that the blocks most recently paged in will probably
> > not be needed again any time soon. Perhaps this (if it is an issue) could
> > be ameliorated by changing the default page age values based on a
> > MAP_DISCARD_EASILY flag.

> The ability to give hints to the kernel like you can in OS/2 and WIN32
> would be useful -- specifically you can hint that you're going to use a
> file sequentially or randomly.

Take a look at madvise for Solaris. You can say for a
mmaped area that you are going to read sequentially (do
lots of readahead), read randomly (do no readahead at all),
that you are going to need an area soon, or that you are
(probably) not going to need the area at all any more.

If you say you are reading sequentially, or if pages
are marked as no longer needed, the pages are quickly
purged from memory again (ie they are placed on top of
the next-page-to-use queue if they are clean). 'cat' on
Solaris uses mmap and madvise, and this means you can cat
a 300MB file at full speed without using more than a few
megabytes of physical RAM.

I recently used it for an app that needs to read
simultaneously from two or three different places in a
large file. Without the madvise, performance was very
bad, and the disk did nothing but seek. With the madvise,
things worked very well indeed.

It would be nice with an fadvise that did the same for
file descriptors, not mmapped areas.

-- 
Erik Corry erik@arbat.com

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu