Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Dec 1995 13:16:39 -0500 (EST)
From:      David Hovemeyer <daveho@infocom.com>
To:        hackers@freebsd.org
Cc:        David Hovemeyer <daveho@infocom.com>
Subject:   mmap and memory utilization
Message-ID:  <Pine.BSF.3.91.951216123927.19249G-100000@infocom.com>

next in thread | raw e-mail | index | archive | help
Howdy all,

I am writing a program that needs to do a lot of character at
a time reading through regular files, both forwards and backwards.
I decided to use mmap(2) rather than read(2) to implement this.
My reasoning is that it is easier to do random access in memory
than in a file.  Also, I imagine that calling read(2) for reading
single characters is inefficient in terms of system call overhead.
I could use iostreams (it's a C++ program) to get buffering of
reads, but iostreams are big and hairy, and still more awkward
to use than memory for what I want to do.

What I am wondering is

	What is the impact of mmap'ing a large file and then
	scanning linearly through it?

Currently I am thinking of mmap'ing the entire file; if the file is
approximately as large as physical memory, will this cause excessive
paging?  (I am assuming an infinite amount of virtual memory,
but a limited amount of physical memory.)  Will the program degrade
the performance of other programs which are running?  Would the mmap
be likely to fail?

In most cases I expect the mmap'ed file to be small (< 16K), but
I want the program to be a "good citizen" under extreme conditions.
I'm pretty clueless about the details of virtual memory and how
it is implemented in FreeBSD.

Hmm, I just noticed the madvise(2) man page: is this what I need
to use?  Maybe I could say MADV_DONTNEED to pages scanned past,
and MADV_WILLNEED to pages about to be accessed?

Any thoughts appreciated.

Dave
--
David Hovemeyer    | aclawisaclawandnobodyhasseenatalking | http://infoco
daveho@infocom.com | clawunlessthatclawisthefamousMr.Klaw | m.com/~daveho




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.951216123927.19249G-100000>