How Linux /proc/meminfo Displays Real-Time Memory
This article explains how the Linux operating system monitors and
reports live memory consumption through the /proc/meminfo
virtual file. You will learn about the underlying mechanics of the
procfs virtual filesystem, how the Linux kernel dynamically
collects memory statistics at the exact moment of request, and the
meaning of key metrics such as MemAvailable,
Buffers, and Cached.
The Mechanism Behind /proc/meminfo
Unlike conventional files stored on a physical drive (such as an SSD
or HDD), /proc/meminfo does not consume disk space. It
exists entirely in system memory as part of procfs, a
pseudo-filesystem created and managed by the Linux kernel.
When a user or application reads /proc/meminfo (using
commands like cat /proc/meminfo), the kernel intercepts
this read operation. Instead of retrieving pre-recorded data from a
disk, the kernel triggers an internal function—primarily
meminfo_proc_show()—to inspect its active memory management
subsystems and compile the statistics instantly. Because this data is
compiled on demand, every read provides a microsecond-accurate snapshot
of the current state of RAM.
Dynamic Data Collection
The Linux kernel continuously tracks memory usage using global
internal counters and page descriptors. When generating the contents of
/proc/meminfo, the kernel calculates metrics across several
key categories:
- Page Allocations: The kernel checks the state of pages managed by its buddy allocator, tracking free pages, active pages, and inactive pages.
- Kernel Data Structures: Memory dedicated to slab caches (tracked via SLUB or SLAB allocators) is queried to report structures like directory caches (dentries) and inode caches.
- I/O Caching: The kernel calculates how many memory pages are currently buffering data destined for disk writes or caching read data.
Because maintaining lockless, global counters for every single memory
event across multiple CPU cores would cause severe performance
bottlenecks, the kernel uses per-CPU counters. During a read of
/proc/meminfo, the kernel sums these per-CPU values to
present unified, system-wide metrics.
Key Metrics in /proc/meminfo
The file displays values in kibibytes (KiB), organized line by line. The most critical entries include:
- MemTotal: Total usable physical RAM, calculated by subtracting the kernel’s own binary code and reserved regions from the system's raw memory.
- MemFree: The amount of physical RAM that is completely unallocated and sitting idle.
- MemAvailable: An estimate of how much memory is
available for starting new applications without swapping. Unlike
MemFree, this includes memory currently used for caches and buffers that the kernel can reclaim instantly. - Buffers: Temporary storage for raw disk blocks waiting to be processed or written.
- Cached: In-memory cache for files read from disk (the page cache), excluding swap cache.
- SwapTotal and SwapFree: Total configured swap space and the amount currently unused.
- Dirty: Memory waiting to be written back to disk.
How User-Space Tools Rely on /proc/meminfo
Standard Linux diagnostic utilities do not implement proprietary
methods to read memory states. Tools such as free,
top, htop, and vmstat act as
parsers that read /proc/meminfo, extract the relevant
lines, perform simple formatting calculations, and present the resulting
figures in user-friendly formats. Consequently, any tool reporting
real-time memory stats in Linux relies fundamentally on the on-demand
generation mechanism of the /proc/meminfo virtual
interface.