Understanding Linux Memory: Read free Output and Manage Buffers/Cache
This guide explains how to interpret the Linux free command, clarifies the roles of total, used, free, shared, buffers, and cached memory, and provides practical commands to clear swap and drop caches for better system performance.
1. Viewing Linux Memory with the free Command
Total : total physical memory size.
Used : memory currently in use (including cached, buffers, and shared portions).
Free : amount of idle memory.
Shared : memory shared between processes (generally can be ignored).
Buffers : data that has been written to memory and is cached for quick response before being flushed to disk.
Cached : memory occupied by cached read data to speed up subsequent accesses.
-/+ buffers/cache is considered as two parts:
-buffers/cache : memory actively used (note this is not the same as the used column because buffers and cache can be reclaimed); value = used - buffers - cached.
+buffers/cache : memory available for use (also not the same as the free column); value = free + buffers + cached.
Swap: the amount of swap space used on disk.
The design purpose is that when the +buffers/cache memory is exhausted, new read/write requests trigger the kernel to write some memory data to disk, using disk space as virtual memory.
2. Buffer and Cache Overview
Cache is designed to accelerate data exchange between CPU and memory, while Buffer improves data exchange between memory and storage devices.
Cache mainly targets read operations. Modern CPUs have multiple levels of cache (L1, L2, L3) to store frequently used instructions and data, reducing latency. In Linux, the cached column represents data cached in RAM for faster future reads.
Buffer focuses on write operations, aggregating writes between memory and disk to reduce fragmentation and improve performance. The kernel periodically flushes buffers to disk, and the sync command can trigger this manually.
3. Common Symptoms
Symptom 1: Frequent file access causes physical memory to be quickly consumed while the cached value keeps growing.
Explanation: Linux caches data that has been read to speed up subsequent accesses, leveraging the CPU's faster processing speed compared to memory.
Symptom 2: Swap space becomes occupied.
Explanation: When physical memory is insufficient, the system starts using swap; monitoring swap usage can indicate memory pressure.
4. Manually Clearing Swap and Buffers/Cache
(1) Clear Swap swapoff -a && swapon -a Explanation: If swap is in use and there is enough free memory (+buffers/cache), executing swapoff -a moves swap contents back to RAM without data loss.
(2) Clear Buffers/Cache
sync; sync; sync && echo 3 > /proc/sys/vm/drop_caches
sleep 2
echo 0 > /proc/sys/vm/drop_cachesExplanation:
sync -> flushes dirty pages to disk
echo 3 > /proc/sys/vm/drop_caches -> tells the kernel to drop pagecache, dentries and inodes
sleep 2 -> pause to ensure the previous command completes
echo 0 > /proc/sys/vm/drop_caches -> restores the default setting5. Summary
When free physical memory is low, it does not necessarily mean poor system health because buffers and cache can be reclaimed on demand, effectively acting as additional free memory.
Frequent swap usage, or non‑zero values for buffers and cache over extended periods, indicates genuine memory pressure; focusing on the -/+ buffers/cache line from free provides a clearer picture of usable memory.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
