Alexander Oberdörster
2003-06-21 10:31:01 UTC
mmap() seems to allocate and retain memory very aggressively in OS X.
When I mmap() a large file (~200 MB in size) read-only and access it
sequentially from start to end, the RSIZE of my program quickly grows
to the size of the file. If the free physical memory is insufficient to
accomodate the whole file, the system starts swapping heavily: first
other data is paged out (running applications etc), then (after my
application has finished and when the paged-out applications are needed
again) it has to be swapped back in. During this time, the system is
very unresponsive. The whole process can take several minutes.
Has anyone else observed this behaviour? Is there a workaround?
(besides the obvious 'don't use memory mapped files')
Note that other UNIXes I tested (Linux, IRIX) seem to handle mmap()
more gracefully and the system remains fully usable during and after
the mmap(). The amount of swapping is minimal. This was not due to the
amount of free memory: The Linux box has about 256 MB RAM with ca. 150
MB free, the IRIX machine has only 64 MB with ca. 30 MB free. The Mac
(a PowerBook 12") has 640 MB RAM, 180 MB were unused (inactive). All
data was gathered with 'top'.
I know that I can give the VM manager hints about the memory usage (I
use it sequentially), but memadvise() seems to be broken in OS X. I
have this impression from previous posts to several mailing lists and
my own experience.
The OS version is 10.2.6. I'm using mmap() as recommended by Apple on
the following web page:
http://developer.apple.com/techpubs/macosx/Essentials/Performance/
FilesNetworksThreads/Reading_Lar_ile_Mapping.html
Alexander Oberdörster
When I mmap() a large file (~200 MB in size) read-only and access it
sequentially from start to end, the RSIZE of my program quickly grows
to the size of the file. If the free physical memory is insufficient to
accomodate the whole file, the system starts swapping heavily: first
other data is paged out (running applications etc), then (after my
application has finished and when the paged-out applications are needed
again) it has to be swapped back in. During this time, the system is
very unresponsive. The whole process can take several minutes.
Has anyone else observed this behaviour? Is there a workaround?
(besides the obvious 'don't use memory mapped files')
Note that other UNIXes I tested (Linux, IRIX) seem to handle mmap()
more gracefully and the system remains fully usable during and after
the mmap(). The amount of swapping is minimal. This was not due to the
amount of free memory: The Linux box has about 256 MB RAM with ca. 150
MB free, the IRIX machine has only 64 MB with ca. 30 MB free. The Mac
(a PowerBook 12") has 640 MB RAM, 180 MB were unused (inactive). All
data was gathered with 'top'.
I know that I can give the VM manager hints about the memory usage (I
use it sequentially), but memadvise() seems to be broken in OS X. I
have this impression from previous posts to several mailing lists and
my own experience.
The OS version is 10.2.6. I'm using mmap() as recommended by Apple on
the following web page:
http://developer.apple.com/techpubs/macosx/Essentials/Performance/
FilesNetworksThreads/Reading_Lar_ile_Mapping.html
Alexander Oberdörster