Low memory alert that was not real: free vs available and buff/cache on Linux
Our memory alert paged every night on healthy servers because it watched MemFree, which page cache always drives toward zero. We switched to MemAvailable, added a pressure signal, and learned which cache really cannot be reclaimed.
For two weeks our on-call rotation was paged almost every night between 01:00 and 03:00 for "memory critically low" on the application fleet. Each time someone logged in, the services were responsive, latency was flat, nothing had been killed, and by morning the alert had resolved itself. People started acknowledging it without looking, which is exactly how a real incident gets missed.
The alert rule was simple:
- alert: HostMemoryLow
expr: node_memory_MemFree_bytes / node_memory_MemTotal_bytes < 0.05
for: 10m
labels:
severity: page
During one of the pages, free -h on an affected host showed:
total used free shared buff/cache available
Mem: 15Gi 4.1Gi 312Mi 180Mi 11Gi 11Gi
Swap: 2.0Gi 0B 2.0Gi
Only 312 MiB free out of 15 GiB, so the alert's arithmetic was right. But 11 GiB was available.
Reproducing it
The nightly timing gave it away. A backup job ran at 01:00 and read about 40 GB of uploaded files from local disk to stream them to object storage. Running the same read by hand reproduced the drop:
free -m | awk 'NR==2 {print "free:", $4, "available:", $7}'
tar -cf /dev/null /srv/uploads
free -m | awk 'NR==2 {print "free:", $4, "available:", $7}'
free fell from several gigabytes to a few hundred megabytes; available barely moved.
What we ruled out
A memory leak in the application. Process
RSSfor the app workers was flat across the night in our per-process metrics.The backup tool holding memory. Its own resident size stayed around 60 MB.
Kernel memory (slab) growth.
SUnreclaimin/proc/meminfostayed under 300 MB.
Root cause
The alert measured MemFree, memory the kernel is not using for anything. Linux deliberately keeps that number low by filling idle RAM with page cache, copies of file data that make re-reads fast. The backup read 40 GB of files, so the cache grew until free memory hit the kernel's low watermark. That cache is reclaimable: the kernel drops clean pages instantly when a process asks for memory. The machine was never short of memory; our alert was reading the wrong field.
What is happening under the hood
/proc/meminfo exposes the kernel's view. The fields that matter here:
Field | Meaning |
|---|---|
| Usable RAM |
| Pages not used for anything at all |
| Block device metadata cache |
| Page cache for files, including tmpfs and shared memory |
| Kernel slab caches that can be freed (dentries, inodes) |
| tmpfs and shared memory; counted inside |
| Kernel estimate of memory available for new workloads without swapping |
free builds its columns from these. In procps-ng 3.3.10 and later, buff/cache is Buffers + Cached + SReclaimable, and available is MemAvailable, which the kernel has provided since version 3.14. The kernel's estimate accounts for page cache, reclaimable slab and low watermarks, and it excludes things like Shmem that look like cache but cannot be dropped.
Before MemAvailable existed, people calculated free + buffers + cached by hand. That overestimates whenever a lot of tmpfs or shared memory is in use, which is why the kernel added a proper field instead of letting every tool guess.
Environment
Component | Version / value |
|---|---|
OS | Ubuntu 24.04 LTS, kernel 6.8 |
procps-ng ( | 4.0.4 |
Exporter | Prometheus node_exporter 1.8 |
Prometheus | 2.53 |
Host size | 4 vCPU, 16 GB RAM, no memory limits on the app |
Nightly job | Backup reading about 40 GB of files from local ext4 |
Minimal reproduction
# Watch the two numbers side by side every 2 seconds
watch -n2 "grep -E '^(MemFree|MemAvailable|Cached|Shmem):' /proc/meminfo"
# In another terminal, read a large file set
find /srv/uploads -type f -exec cat {} + > /dev/null
MemFree falls steadily while Cached rises by the same amount; MemAvailable stays nearly constant.
Who is affected
Any alert, dashboard or autoscaling rule built on MemFree, on used from very old free versions, or on 100 - free%. It hits hardest on hosts that read lots of files: backup targets, build agents, log shippers, database replicas and anything serving static content.
The fix
We changed the alert to the kernel's own estimate and lengthened the window so a brief dip during a deploy does not page:
- alert: HostMemoryLow
- expr: node_memory_MemFree_bytes / node_memory_MemTotal_bytes < 0.05
- for: 10m
+ expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes < 0.10
+ for: 15m
labels:
severity: page
+ annotations:
+ summary: "{{ $labels.instance }} has under 10% memory available for 15m"
Available memory is necessary but not sufficient. A host can have 12% available and still be thrashing if the working set does not fit, so we added a ticket-level alert on memory pressure using Pressure Stall Information, which node_exporter reports from /proc/pressure/memory:
- alert: HostMemoryPressure
expr: rate(node_pressure_memory_waiting_seconds_total[5m]) > 0.10
for: 10m
labels:
severity: ticket
annotations:
summary: "Tasks on {{ $labels.instance }} stalled on memory over 10% of the time"
The waiting counter is the PSI "some" line: the share of time at least one task was stalled waiting for memory. Sustained values above a few percent mean real slowdown, whatever the free numbers say.
Finally we kept the dashboard panel but relabelled it: "Available" as the main line, "Page cache" as a stacked area underneath, and "Free" removed. A graph that shows free memory invites the same misreading the alert had.
Alternatives and trade-offs
Alert on major page faults or swap-in rate (
node_vmstat_pgmajfault,node_vmstat_pswpin). Good early signal of thrashing, but noisy on hosts that legitimately page in large files.Alert on OOM kills (
node_vmstat_oom_kill). Precise, but it fires after damage is done; keep it as a ticket, not a substitute.Drop caches before the backup (
echo 3 > /proc/sys/vm/drop_caches). Do not. It throws away useful cache, makes every following read slower, and changes nothing about real availability.Use
posix_fadviseor--nocache-style options in the backup tool so it does not evict the application's hot cache. Worth it if the backup visibly slows the app the next morning; unrelated to the alert itself.
How to test the fix
We pushed the rule to staging and replayed the nightly read with promtool checking the rule file first:
promtool check rules memory-alerts.yml
Then on a staging host we ran the large read and confirmed in the Prometheus UI that node_memory_MemFree_bytes dropped below 5% while the new expression stayed around 0.70 and no alert entered pending. To confirm the alert still fires on real pressure, we ran a memory hog that keeps its pages resident:
stress-ng --vm 1 --vm-bytes 90% --vm-keep --timeout 20m
MemAvailable fell under 10%, the PSI rate rose, and both alerts fired as expected.
Confirming in production
For the following two weeks we tracked three things:
# Should never page during the backup window now
ALERTS{alertname="HostMemoryLow", alertstate="firing"}
# The healthy pattern: available stays high while cache churns
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes
# Real pressure, near zero on this fleet
rate(node_pressure_memory_waiting_seconds_total[5m])
Nightly pages dropped to zero. During the backup window available memory stayed between 65% and 75%, and the PSI rate stayed below 0.01.
Regression guard
We added a unit test for the rule file using promtool test rules, feeding a synthetic series where MemFree is 2% and MemAvailable is 70%, and asserting no alert. A second case sets MemAvailable to 5% for 20 minutes and asserts the alert fires. The test runs in CI on every change to the alerting repository.
Security implications
None directly. Indirectly, alert fatigue is a security problem: an on-call team trained to ignore pages will also ignore the page that matters, including resource exhaustion caused by abuse. Removing a false-positive page restores trust in the channel. The drop_caches "fix" we rejected also requires root on every host, which is another reason not to script it.
Prevention checklist
Build memory alerts on
MemAvailable, neverMemFree.Pair availability with a pressure signal (PSI or major faults) for real thrashing.
Remove "free memory" panels from dashboards or label them clearly as cache-driven.
Test alert rules with
promtool test rulesusing both healthy and unhealthy series.Review any alert that pages and resolves on its own more than twice in a week.
References
/proc/meminfofields andMemAvailable: https://docs.kernel.org/filesystems/proc.htmlfree(1)manual: https://man7.org/linux/man-pages/man1/free.1.htmlPressure Stall Information: https://docs.kernel.org/accounting/psi.html
node_exporter collectors: https://github.com/prometheus/node_exporter
Prometheus alerting rules and rule unit tests: https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/
Add a label
Embed this post
<iframe src="https://hibug.me/linux-free-memory-low-buff-cache-misread" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I lead a small team responsible for observability and quality tooling, and I spend a fair share of my time on application security reviews. That mix means I see many incidents twice: once when they happen and again when we ask why nothing warned us. The posts here come from that second look. An alert that never fired because the metric disappeared, sampling that dropped exactly the traces we needed, a catch-all that reported success for weeks, a secret recoverable from an image layer, tests that passed against mocks while production failed. Each one covers how the gap was found, what we changed in code or configuration, and how we verified the fix with a test or a drill. Security topics stay defensive and practical: controls you can add to your own code and a way to test each one.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.