Subject: Re: mmap eats memory
To: Andrew Kilpatrick <email@example.com>
From: Jaromír <firstname.lastname@example.org>
Date: 02/20/2001 07:59:42
Andrew Kilpatrick wrote:
> I'm using mmap to provide access to very large audio
> files. (possibly 300-600 megs) When I scan through an
> entire file, the resident size of my process grows
> and grows until the RAM on the machine is full and all
> other processes are swapped to disk.
> Is this normal? And is there any way of preventing
> huge memory usage while still giving simple memory-mapped
> access to very large files?
Yes, that is quite normal. I believe there is some mechanism
to unmap the pages after they were inactive for a while, but
that might not be fast enough for you.
You probably want to use madvise(2) to tell kernel you access the
pages sequentially via MADV_SEQUENTIAL - that makes kernel unmap
the previous pages as you move to next. Works quite nice e.g. in
mpg123, should be good for you as well. Also, you probably want to
use flags MAP_FILE|MAP_SHARED for the mmap(2) call if you don't
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
@@@@ Wanna a real operating system ? Go and get NetBSD, dammit! @@@@