/proc/meminfo: Explanation & Insights
Contains information about system memory, including total, free, and used memory
The file /proc/meminfo
is a virtual file in the Linux operating system that provides information about the system's
memory usage and configuration. This file contains details such as the amount of total RAM available, the amount of
memory used, the amount of swap space, and other relevant information about the system's memory.
Why is /proc/meminfo Important?
Understanding /proc/meminfo
is crucial for system administrators and developers alike. This file can provide insights
into memory-related performance issues, helping to identify whether a system is running low on memory, if there is an
excessive amount of swapping occurring, or if certain areas of memory are under or over-utilized.
How to Use /proc/meminfo?
Reading the /proc/meminfo
file is as simple as issuing the cat
command:
cat /proc/meminfo
The output of this command will provide a detailed snapshot of the system's memory state. Here's an example of how the output would look like:
MemTotal: 131813512 kB
MemFree: 89161572 kB
MemAvailable: 97127992 kB
Buffers: 1336600 kB
Cached: 7516016 kB
SwapCached: 0 kB
Active: 4409240 kB
Inactive: 37493748 kB
Active(anon): 2208 kB
Inactive(anon): 33065296 kB
Active(file): 4407032 kB
Inactive(file): 4428452 kB
Unevictable: 54308 kB
Mlocked: 54184 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Zswap: 0 kB
Zswapped: 0 kB
Dirty: 144 kB
Writeback: 0 kB
AnonPages: 33104876 kB
Mapped: 180096 kB
Shmem: 7476 kB
KReclaimable: 289524 kB
Slab: 394088 kB
SReclaimable: 289524 kB
SUnreclaim: 104564 kB
KernelStack: 9456 kB
PageTables: 131764 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 65906756 kB
Committed_AS: 2739456 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 33656 kB
VmallocChunk: 0 kB
Percpu: 11264 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 177400 kB
DirectMap2M: 10215424 kB
DirectMap1G: 123731968 kB
Understanding /proc/meminfo Contents
Let's break down what each of the entries in the /proc/meminfo
file signify:
MemTotal: Total usable RAM (i.e. physical RAM minus a few reserved bits and the kernel binary code)
MemFree: The sum of currently unused memory
MemAvailable: An estimate of how much memory is available for starting new applications, without swapping.
Buffers: Relatively temporary storage for raw disk blocks.
Cached: In-memory cache for files read from the disk (the page cache).
SwapCached: Memory that once was swapped out, is swapped back in but still also is in the swap file.
Active: Memory that has been used more recently and usually not reclaimed unless absolutely necessary.
Inactive: Memory which has been less recently used. It is more eligible to be reclaimed for other purposes.
Active(anon): anon pages that are part of a process' working set.
Inactive(anon): anon pages that are swapped out more aggressively than anonymous Active(anon) pages.
Active(file): file pages that may be reclaimed under memory pressure.
Inactive(file): file pages that may be reclaimed under memory pressure.
Unevictable: Memory which is never to be reclaimed, such as mlock-ed memory.
Mlocked: Pages that are mlock-ed and cannot be swapped out.
SwapTotal: Total swap space available.
SwapFree: Unused swap space.
Dirty: Memory waiting to be written back to the disk.
Writeback: Memory actively being written back to the disk.
AnonPages: Non-file pages mapped into userspace page tables.
Mapped: Files and libraries mapped into memory.
Shmem: Total memory used by shared memory (shmem) and tmpfs.
Slab: In-kernel data structures cache.
SReclaimable: Part of Slab, that might be reclaimed, such as caches.
SUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure.
PageTables: Amount of memory dedicated to the lowest level of page tables.
NFS_Unstable: NFS pages sent to the server, but not yet committed to stable storage.
Bounce: Memory used for block device "bounce buffers".
WritebackTmp: Memory used by FUSE for temporary writeback buffers.
CommitLimit: Based on the overcommit ratio (
vm.overcommit_ratio
), this is the total amount of memory currently available to be allocated on the system.Committed_AS: The total amount of memory presently allocated on the system.
VmallocTotal: Total size of vmalloc memory area.
VmallocUsed: Amount of vmalloc area which is used.
VmallocChunk: Largest contiguous block of vmalloc area which is free.
Percpu: Memory used by the percpu allocator.
HardwareCorrupted: Amount of RAM the kernel identified as broken and unusable.
AnonHugePages: Non-file backed pages mapped into userspace page tables with huge pages.
ShmemHugePages: Amount of hugepages used for shared memory (shmem) and tmpfs.
ShmemPmdMapped: Shared memory mapped into userspace with huge pages.
FileHugePages: File-backed pages mapped into userspace with huge pages.
FilePmdMapped: File-backed pages mapped into userspace with transparent huge pages.
HugePages_Total: Total number of hugepages for the system.
HugePages_Free: Number of hugepages available for the system.
HugePages_Rsvd: Number of hugepages reserved for the system.
HugePages_Surp: Number of surplus hugepages for the system.
Hugepagesize: Size of hugepages.
Hugetlb: Total amount of memory, in bytes, used by the hugepage tables.
DirectMap4k: Number of bytes of RAM linearly mapped with 4k pages.
DirectMap2M: Number of bytes of RAM linearly mapped with 2M pages.
DirectMap1G: Number of bytes of RAM linearly mapped with 1G pages.
Typical Problems Diagnosed with /proc/meminfo
From identifying memory leaks to investigating high load,
the /proc/meminfo
file can be a powerful tool. Here are some other common problems you can investigate
using /proc/meminfo
:
Memory Exhaustion: If the system is experiencing memory exhaustion, it may be evident from metrics such as the amount of free memory (
MemFree
), available memory (MemAvailable
), or the amount of memory used (MemTotal
-MemFree
). If these values are consistently low, it indicates that the system is running out of memory resources.Memory Leaks: Memory leaks occur when a program allocates memory but fails to release it when it's no longer needed. Monitoring the values of
MemFree
,Cached
, andBuffers
can help detect memory leaks. If these values continuously decrease over time while the system is under consistent load, it may indicate a memory leak issue.Swap Usage: Swap space is a portion of the hard disk used as virtual memory when the physical RAM is fully utilized. High swap usage (
SwapTotal
-SwapFree
) combined with low free memory (MemFree
) can indicate that the system is experiencing memory pressure, which may result in degraded performance due to excessive swapping.High Memory Usage by Processes: By examining the
MemInfo
of individual processes in/proc
, you can identify processes that are consuming excessive memory. This can help diagnose memory-hungry applications or processes that may need optimization or troubleshooting.Page Faults: Page faults occur when a program tries to access memory that is not currently in physical RAM and must be fetched from the disk or swap space. Monitoring page fault-related metrics such as
pgpgin
(pages paged in from disk) andpgpgout
(pages paged out to disk) can help diagnose performance issues related to disk I/O and memory management.Buffer and Cache Usage: The
Buffers
andCached
fields indicate memory used for file system metadata and cache data, respectively. Monitoring these values can help assess the efficiency of file system caching and identify any anomalies that may affect system performance.Memory Fragmentation: Memory fragmentation can occur when the available memory is divided into small, non-contiguous blocks, making it challenging for the system to allocate large contiguous memory regions. Although
/proc/meminfo
may not directly provide information about fragmentation, observing patterns of memory allocation and deallocation over time can help diagnose fragmentation-related issues.
By analyzing the information provided by /proc/meminfo
and correlating it with system behavior and performance
metrics, administrators can diagnose various memory-related problems and take appropriate actions to optimize system
performance and stability.