ThisCalculator

Everyday

Free Linux Buffers Caches?

Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered

Free Linux Buffers Caches?

Yes, Linux automatically frees buffers and caches when memory is needed by applications, but it does not drop them proactively to show more “free” memory. The kernel treats unused RAM as wasted RAM, so it fills it with cached file data and buffer metadata; when a program requests memory, the kernel reclaims those pages instantly. This article explains what buffers and caches actually are, how the reclaim process works, how to monitor them, and when (and whether) you should manually intervene.

Formula

The calculator above computes running pace and speed from a finish time and distance. The formulas are:

  • Pace = Finish time (minutes) ÷ Distance (km)  â†’  result in min/km
  • Speed = Distance (km) ÷ (Finish time (minutes) ÷ 60)  â†’  result in km/h

Where:

  • t = finish time in minutes (e.g., 50 min)
  • d = distance in kilometers (e.g., 10 km)

Both outputs are derived directly from the two inputs; no other factors are involved.

Worked Example

Using the default values (50 minutes for 10 km):

  1. Pace = 50 ÷ 10 = 5.00 min/km
  2. Speed = 10 ÷ (50 ÷ 60) = 10 ÷ 0.8333 = 12.00 km/h

The calculator shows 5.00 min/km as the headline answer and 12.00 km/h as the secondary output.

What Are Buffers and Caches in Linux?

In Linux memory statistics, buffers are the kernel’s temporary storage for raw disk blocks (metadata, inodes, superblocks) and are relatively small. Caches (often called “page cache”) hold the actual contents of files and directories that have been read from or written to disk. Both are parts of the kernel’s page cache, which is designed to speed up repeated access to disk data. When you run free -h, you see a row like:

              total        used        free      shared  buff/cache   available
Mem:           15Gi       2.1Gi       1.2Gi       200Mi        12Gi        12Gi

The buff/cache column shows memory that is currently used for caching, but that memory is not permanently occupied—it is reclaimable. The available column is the real number to watch: it estimates how much memory can be given to new applications without swapping.

How the Kernel Frees Buffers and Caches Automatically

Linux uses a lazy reclaim mechanism. When an application calls malloc() or similar and the system is low on free pages, the kernel’s memory management code (the mm subsystem) shrinks the caches. It does this by:

  1. Scanning for clean pages (file data that is already written to disk) and simply dropping them.
  2. Writing back dirty pages (modified file data) to disk and then dropping them.
  3. Reclaiming buffer heads and other metadata.

This happens in milliseconds, and the reclaimed memory is immediately available to the requesting process. The kernel also runs background reclaim (kswapd) when memory pressure crosses certain thresholds, and it can use vm.vfs_cache_pressure to tune how aggressively it reclaims inode/dentry caches. The default value of 100 means the kernel reclaims them at a “normal” rate; lowering it (e.g., to 50) makes the kernel keep more of those caches, while raising it (e.g., to 200) makes it drop them faster.

Why You Should NOT Manually Drop Caches (Usually)

Many tutorials suggest running sync; echo 3 > /proc/sys/vm/drop_caches to free buffers and caches. This command forces the kernel to drop clean caches, but it is rarely beneficial and can hurt performance:

  • Dropping caches removes useful data that would speed up future file access, so your next read will be slower.
  • The kernel already frees caches automatically when needed; manual drops only make sense before benchmarking (to get a cold-cache baseline) or after testing a kernel feature.
  • It does not free memory that is actually in use by processes; it only drops reclaimable pages.

If you are troubleshooting a “high memory usage” alarm, first check the available column. If it is high (say, 80% of total RAM), the system is fine. Only if available is low and the system is swapping heavily should you consider tuning vm.swappiness or investigating which process is consuming memory.

How to Monitor and Interpret Memory Usage

Use free -h (with the -h for human-readable units) or cat /proc/meminfo for the raw numbers. Key fields:

  • MemFree – truly unused pages; this is often small because the kernel uses free memory for caches.
  • Buffers – raw disk block cache.
  • Cached – page cache (file contents).
  • SwapCached – memory that was swapped out and then read back but still present in swap.
  • Available – an estimate of memory that can be given to applications without swapping; this is the best indicator of real headroom.

For a dynamic view, vmstat 1 shows si and so (swap in/out) columns; if those are non-zero, the system is under memory pressure. htop or top display a bar for memory, but they often show “used” as including caches, which confuses users. In htop, the green bar is used memory, blue is buffers, and orange/yellow is cache; the total bar is not a measure of pressure.

Common Misconceptions and Pitfalls

The most common misconception is that “buff/cache” memory is wasted and should be freed. In reality, it is a performance feature. Another pitfall is confusing free with available: a system with 1 GiB free but 12 GiB available is perfectly healthy. A third issue is using drop_caches on a production server without understanding that it will cause a temporary performance dip. Also, be aware that drop_caches requires root privileges and that writing to /proc/sys/vm/drop_caches is not persistent—it only affects the current state. If you want to tune cache behavior permanently, edit /etc/sysctl.conf with parameters like vm.vfs_cache_pressure or vm.swappiness and run sysctl -p.

When Manual Intervention Makes Sense

There are a few legitimate cases where you might want to drop caches:

  • Benchmarking: Before running a performance test, you want a cold cache to measure worst-case disk performance.
  • After testing a kernel patch: To ensure the cache doesn’t mask a regression.
  • On a system that is about to be decommissioned: Not really useful, but harmless.

In all other cases, let the kernel do its job. If you are concerned about memory pressure, look at the processes using the most memory with ps aux --sort=-%mem or top, and consider closing or restarting those applications.

Alternatives to Dropping Caches

Instead of manually dropping caches, you can:

  • Adjust vm.swappiness (default 60) to control how aggressively the kernel swaps out anonymous memory vs. reclaiming page cache. Lower values (e.g., 10) make the system prefer keeping file caches over swapping.
  • Use vm.vfs_cache_pressure to tune how quickly inode/dentry caches are reclaimed.
  • Use cgroups memory limits to constrain specific processes, so a runaway process can’t consume all RAM.
  • For a server with plenty of RAM, you can increase the amount of memory used for caching by setting vm.zone_reclaim_mode appropriately (though this is rarely needed).

These approaches give you control without the blunt hammer of drop_caches.

Frequently Asked Questions

Does Linux automatically free buffers and caches when memory is needed?

Yes. The kernel reclaims clean page cache and buffer pages as soon as an application requests memory and the free list is low. This is a core part of the memory manager; you don’t need to do anything.

Why does my system show very little “free” memory when I run free -h?

Because the kernel uses available memory for caching. The free column only shows truly unused pages, which is often small. Look at the available column instead—it tells you how much memory can be given to apps without swapping.

Is it safe to run “echo 3 > /proc/sys/vm/drop_caches”?

It is safe in the sense that it won’t crash your system, but it is not recommended for normal use. It drops clean caches, which can slow down subsequent file reads. Only use it for benchmarking or testing when you need a cold cache.

What is the difference between buffers and caches?

Buffers are small and hold raw disk block metadata (like inodes and superblocks). Caches are larger and hold the actual contents of files. Both are reclaimable and both speed up disk I/O.

How do I make Linux keep more caches?

You can lower vm.swappiness (e.g., to 10) so the kernel prefers to keep file caches over swapping out processes. You can also raise vm.vfs_cache_pressure to keep more inode/dentry caches, but the defaults are usually fine.

Does dropping caches free memory that is used by applications?

No. drop_caches only drops reclaimable pages (clean caches and buffers). It does not affect memory that is actively used by processes. So it won’t help if you have a memory leak.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.