Subject: Re: mmap eats memory
To: None <"Jaromír"@andrewkilpatrick.org, Dolecek@andrewkilpatrick.org,>
From: Andrew Kilpatrick <email@example.com>
Date: 02/20/2001 11:15:51
Thanks for the clarification. madvise works great, and SEQUENTIAL
access mode seems right for my application.
On Tue, Feb 20, 2001 at 07:59:42AM +0100, Jaromír Dolecek wrote:
> 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! @@@@