I have an application that mmap
s a large read-only data structure into memory and reads parts of it. After some time, around 1 GB of physical memory is filled with pages loaded from this data structure. When the amount of free memory on that machine drops below a certain threshold (~750 MB or so), the kernel seems to release all (or almost all) pages loaded through mmap
.
How does Kernel decide when to start unloading mmapped pages? Is there a way to control that threshold? (e.g. anything in /proc/sys/vm
or cgroups
)
From manual, the munmap() system call deletes the mappings for the specified address range, causing further references to addresses within the range to generate invalid memory references.
DIRTY PAGE HANDLING How munmap() handles a dirty page, depends on what type of memory is being unmapped:
Tweaking the thresholds is a bit tricky. There always needs to be some buffer of free memory, for good performance. And personally, I don't fully understand virtual memory tuning with regards to mmap pages vs anonymous.
For more of the working set in memory, add RAM to the host. Or maybe a faster storage system, to read parts of the file in.