Linux – Limit linux file cache memory usage (to avoid hypervisor memory exhaustion)

cachekvm-virtualizationlinuxvirtualization

I have a server with 16GB RAM running several linux virtual machines (around 10), which perform several different tasks. These machines, with the default configuration, will fill up the memory I give them to the max with cache.

Even as this is a desirable behavior for physical hosts, on my setup, this cache is actually consuming real host RAM which is not freeable from the host, and forces me to set relatively low amounts of ram to the vms (no more than (16 - host cache)/number of vms). This is quite undesirable, as the system loses flexibility making impossible to handle sporadic requests of RAM from concrete vms.

The only approach that comes to my mind is to limit the amount of RAM the kernel can use for caching (or make cache expire sooner), but I haven't found any documentation on how to do it. Most forum posts refer to linuxatemyram.com or alike, and I haven't seem any relevant parameter exposed under /proc/sys/vm/ either.

Maybe some can offer some insights on this? I'd be really grateful.

Best Answer

You can modify the value of /proc/sys/vm/vfs_cache_pressure to a value greater than 100 (default value). With increased value beyond 100, it causes the kernel to prefer to reclaim dentries and inodes.