brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: vm.vfs_cache_pressure sets how eagerly Linux drops cached folder listings

Linux
~/tips/tip-memory-vfs-cache-pressure

sysctl vm.vfs_cache_pressure

Controls how strongly the kernel reclaims directory and inode caches, with 100 as the default.

On a box that walks huge folder trees, like a media library or a backup target, every directory lookup needs the disk again once the kernel has dropped that cache. One sysctl tells it how hard to throw that cache away.

sysctl vm.vfs_cache_pressure

The default is 100 and the output looks like this:

vm.vfs_cache_pressure = 100

The kernel docs describe it as the tendency to reclaim the memory used for caching directory and inode objects. At 100 the kernel reclaims dentries and inodes at a fair rate compared with page cache and swap cache. A lower value makes it keep them longer. A value above 100 makes it prefer reclaiming them.

sudo sysctl -w vm.vfs_cache_pressure=50

That applies at once and is gone after a reboot. To keep it, put the line in a file under /etc/sysctl.d/ that ends in .conf, for example /etc/sysctl.d/99-cache.conf:

vm.vfs_cache_pressure = 50

Then load it with sudo sysctl --system.

You can see how much of this memory the kernel considers reclaimable in /proc/meminfo:

grep -E 'Slab|SReclaimable' /proc/meminfo

SReclaimable is the part of the slab memory that might be reclaimed, such as caches.

The caveats are written into the docs. At 0 the kernel never reclaims dentries and inodes under memory pressure, and that can easily lead to out-of-memory conditions. Very high values can hurt performance, because the reclaim code has to take locks to find objects to free. Newer kernels also have vm.vfs_cache_pressure_denom, which defaults to 100, and the setting is relative to it. I’d leave the default alone until there is a reason, and then move in small steps.

Further reading: Kernel documentation: sysctl vm, proc_meminfo(5) man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link