Linux caches more than file contents. It also caches directory entries (dentries) and inodes — the metadata that maps names to files. Together these caches make repeated file access fast, especially for workloads that touch many small files, like web servers and build systems.
Three caches
| Cache | What it holds | Helps with |
|---|---|---|
| Page cache | File contents in RAM | Re-reading the same files |
| Dentry cache | Results of path lookups (/var/www/site/index.php → inode) |
Opening files by path, stat(), listing directories |
| Inode cache | File metadata: size, permissions, owner, timestamps, block locations | Any operation that needs file metadata |
Writes also pass through the page cache — see Linux disk caching and I/O for dirty pages and fsync.
See how much is cached
free -h # buff/cache column
grep -E '^(Cached|Buffers|SReclaimable)' /proc/meminfo
slabtop -o | head -20 # kernel object caches; look for dentry and *_inode_cache
SReclaimable is kernel memory (including dentries and inodes) that can be freed when applications need it.
Watch caching work
# Cold: drop caches (test systems only)
sync; echo 3 > /proc/sys/vm/drop_caches
time find /usr -type f | wc -l
# Warm: run again
time find /usr -type f | wc -l
The second run is much faster: every directory and inode is already in memory.
vfs_cache_pressure
This setting controls how aggressively the kernel reclaims dentry and inode caches compared with the page cache:
100(default) — balanced.- Lower (e.g.
50) — keep metadata cached longer. Useful for servers with millions of small files (mail servers, file servers, large web roots). - Higher — reclaim metadata sooner, favouring file contents.
# /etc/sysctl.d/90-vfs.conf
vm.vfs_cache_pressure = 50
Apply with sysctl --system. Don’t set it to 0 — the kernel would never reclaim those caches and could run out of memory.
Which files are in the page cache?
fincore /var/www/html/*.php # util-linux
# or install vmtouch:
vmtouch -v /var/lib/mysql/
vmtouch -t can preload (“touch”) files into cache, and vmtouch -l can lock them in memory — occasionally useful for small, hot datasets.
What this means for your server
- Don’t fight the cache. Memory used for cache is given back instantly when applications need it. Dropping caches to “free memory” just slows the server down.
- More RAM = faster disk for read-heavy workloads, because more of the working set stays cached.
- Databases double-cache. InnoDB and PostgreSQL keep their own buffers and the OS caches the files. PostgreSQL relies on the OS cache on purpose; InnoDB with
O_DIRECTbypasses it. Size database buffers with this in mind. - Containers share the cache. Page cache used by one container counts towards its memory limit in cgroups v2, which can trigger reclaim inside that container.
Monitoring over time
Plot MemAvailable rather than MemFree. If available memory drops low and stays low, or you see swapping (vmstat si/so), the server needs more RAM — the cache can no longer hold your working set.
Related: Linux disk performance, swap file vs swap partition and how Linux works.