Linux caches as much data as possible in RAM to speed up disk reads. When applications need more memory, the kernel automatically reclaims this cache. However, in some situations — benchmarking, after bulk file operations, or troubleshooting — you may want to manually drop the page cache, dentries, and inodes. This guide explains how, and when you should (and shouldn’t) do it.
Understanding Linux Memory Cache
Running free -h shows a “buff/cache” column that can look alarming. This memory is not wasted — it’s used productively to cache files and will be released automatically when applications need RAM. You rarely need to clear it manually on a production server.
free -h
# total used free shared buff/cache available
# Mem: 16Gi 4.2Gi 892Mi 312Mi 10.8Gi 11.2Gi
How to Drop Linux Page Cache
# Step 1: Flush dirty pages to disk first (always do this before dropping cache)
sync
# Step 2: Choose what to drop:
# Drop page cache only
echo 1 > /proc/sys/vm/drop_caches
# Drop dentries and inodes only
echo 2 > /proc/sys/vm/drop_caches
# Drop page cache, dentries, and inodes (most thorough)
echo 3 > /proc/sys/vm/drop_caches
Combine both steps in one line:
sync && echo 3 > /proc/sys/vm/drop_caches
Verify the Cache Was Cleared
free -h
# The buff/cache value should now be significantly lower
Permission Denied on VPS / Containers
On OpenVZ/Virtuozzo containers, /proc/sys/vm/drop_caches is read-only from inside the container. Cache management must be done at the hardware node level by your hosting provider. This is expected behaviour — contact your host’s support team.
When NOT to Clear the Cache
- Never on production under load — dropping the cache causes a flood of disk I/O as the kernel rebuilds it, which can spike load average significantly
- Not as a regular maintenance task — the kernel manages cache automatically and efficiently
- Not to “free up memory” for applications — the kernel already does this automatically when apps need RAM
