Why Linux’s Buffer/Cache Isn’t Always Free Memory – A Deep Dive
This article explains how the Linux free command reports memory usage, clarifies the roles of buffer and page cache, shows how to manually drop caches, and reveals scenarios—such as tmpfs, shared memory, and mmap—where cached memory cannot be reclaimed, helping readers achieve a deeper understanding of system memory behavior.
In Linux, the free command is commonly used to view memory usage, but many users misinterpret its output.
Level 1 – Unaware: Users see large memory usage and think Linux is consuming too much memory.
Level 2 – Think they understand: Users notice buffers/cache and assume the memory is readily available.
Level 3 – Truly aware: Users recognize that free’s output alone does not answer whether memory is sufficient.
Understanding the difference between buffer cache (Linux’s Buffer cache) and page cache (Linux’s Page cache) is essential. Buffer cache handles block‑device writes, while page cache stores file data for read/write operations and is also used by many other subsystems.
What is page cache?
Page cache caches file data on the filesystem, accelerating read/write operations and is used by system calls like mmap.
What is buffer cache?
Buffer cache caches block‑device data during I/O, allowing the kernel to write back only modified portions of a page.
How is cache reclaimed?
When memory is low, the kernel frees buffer/cache memory, but clearing cache incurs I/O overhead because dirty data must be written back.
Cache can be manually dropped by writing to /proc/sys/vm/drop_caches: echo 1 > /proc/sys/vm/drop_caches – drop page cache echo 2 > /proc/sys/vm/drop_caches – drop slab objects (dentries, inodes) echo 3 > /proc/sys/vm/drop_caches – drop both page cache and slab objects
Can all cache be reclaimed?
Some cache cannot be freed:
tmpfs
Files stored in a tmpfs filesystem occupy page cache; the cache is released only when the files are deleted.
Shared memory (shm)
Shared memory created with shmget uses tmpfs internally, so its cache persists until the segment is removed with shmctl IPC_RMID or ipcrm.
mmap with MAP_SHARED
Memory mapped with MAP_SHARED is also backed by tmpfs and remains in cache until the mapping is unmapped.
These examples show that cache is not always reclaimable as free memory, and clearing it can increase I/O.
Key takeaways
Releasing file cache raises I/O load.
Files in tmpfs keep cache until deleted.
Shared memory segments keep cache until explicitly removed.
MAP_SHARED mmap regions keep cache until unmapped.
Both shm and MAP_SHARED ultimately rely on tmpfs, which uses cache.
Understanding these details helps you interpret the free command at a deeper level and assess whether your system’s memory usage is truly optimal.
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.
