Am 17.06.2005 um 09:24 schrieb Stephen Deasey:


I believe this is pretty common, but I'm not sure if this is what you
want.  An anonymous mapping is still going to account against the
processes memory budget, and I don't think it's going to be any more
likely to be swapped out than malloc'ed memory.

In fact, on Linux (well, glibc) if you ask malloc for a chunk of
memory over a certain size then mmap is used internally.  I think the
advantage is reduced memory fragmentation, but there is some overhead
for small sizes and you have to allocate in multiples of the page size
(4k).

tempfs would be a better bet.  Modern Linux systems have this mounted
at /dev/shm.  I think this is a Solaris thing.  This is a very low
overhead file system where the file data springs into existence when
you ask for it.  So, no files, no overhead.  Under memory pressure
it's sent to swap.  It was designed for sharing memory between
processes using mmap, but it's handy for /tmp and some other things.

You could try setting the TMPDIR environment variable to some tempfs
file system if you wanted to experiment with this.

Not to forget: Darwin, Windows... I think I will have to find a
common acceptable solution for all OS'es. Fortunately, mapping
a regular (temp) file will always work. The rest is just optimizations.

Cheers
Zoran


Reply via email to