1. Introduction

The /proc/meminfo file inside the /proc pseudo-filesystem provides a usage report about memory on the system. When we want to find out statistics like used and available memory, swap space, or cache and buffers, we can analyze this file’s contents. However, there are tons more data on top of the basic information.

In this article, we’re going to examine every data field in the /proc/meminfo file.

2. Data Fields in /proc/meminfo

To see what a file contains, we can use the cat command:

$ cat /proc/meminfo
MemTotal:         994548 kB
MemFree:           65228 kB
MemAvailable:     263724 kB
Buffers:           21396 kB
Cached:           304440 kB
SwapCached:        25260 kB
Active:           267424 kB
Inactive:         503720 kB
Active(anon):     110956 kB
Inactive(anon):   351176 kB
...

As we can see above, the /proc/meminfo file contains memory statistics in kilobytes. Now, let’s take a look at each of them by category.

3. General Memory

Usually, we only need basic information about memory, such as how much RAM our system has or how much is available at the current moment:

$ cat /proc/meminfo | grep "Mem"
MemTotal:         994328 kB
MemFree:           66428 kB
MemAvailable:     207192 kB

Basically, we get a simple memory snapshot:

  • MemTotal: total usable RAM
  • MemFree: free RAM, the memory which is not used for anything at all
  • MemAvailable: available RAM, the amount of memory available for allocation to any process

However, these basic values are available in other tools as well.

4. Buffers and Cache

Sometimes, we may want to check buffer and cache sizes. Specifically, buffers are temporary storage components for process input and output. They don’t increase the processing speed. On the other hand, cache stores some data to serve future requests faster. As a result, the cache increases the processing speed.

Of course, we can access the memory size information for both:

$ cat /proc/meminfo | grep -e "Buffers" -we "Cached" 
Buffers:           12820 kB
Cached:           254592 kB

Let’s define these two attributes:

  • Buffers: temporary storage element in memory, which doesn’t generally exceed 20 MB
  • Cached: page cache size (cache for files read from the disk), which also includes tmpfs and shmem but excludes SwapCached

Indeed, distinguishing different caching levels enables better memory management in terms of hierarchy.

5. Swap Space

Furthermore, we can learn all about the swap space on the system:

$ cat /proc/meminfo | grep "Swap" 
SwapCached:        13936 kB
SwapTotal:        945416 kB
SwapFree:         851064 kB

Basically, swap space is a backup space on the disk for RAM. When the physical memory is full, the system uses the swap space:

  • SwapCached: recently used swap memory, which increases the speed of I/O
  • SwapTotal: the total amount of swap space available in the system
  • SwapFree: unused swap space, the memory that has been transferred from RAM to the disk temporarily

Importantly, the /proc/swap file lists the different available swap areas.

6. Memory Activeness

Moreover, the /proc/meminfo file also contains data about memory dynamics:

$ cat /proc/meminfo | grep -e "Active" -e "Inactive" 
Active:           194308 kB
Inactive:         553172 kB
Active(anon):      59024 kB
Inactive(anon):   437264 kB
Active(file):     135284 kB
Inactive(file):   115908 kB

In this case, there are two categories: file or non-file (anon). Here, we are interested in the general result:

  • Active: memory that has been used more recently, not very suitable to reclaim for new applications
  • Inactive: memory that hasn’t been used recently, more suitable to reclaim for new applications

Knowing the breakdown of active and inactive memory enables better handling of memory-intensive applications such as servers.

7. Writeback Into the Disk

Moreover, we’re able to get information about the amount of memory that’s being or is about to be written back:

$ cat /proc/meminfo | grep -e "Dirty" -e "Writeback" 
Dirty:                 0 kB
Writeback:             0 kB
WritebackTmp:          0 kB

Following is a summary of the fields:

  • Dirty: memory that currently waits to be written back to the disk
  • Writeback: memory that is being written back at the moment
  • WritebackTmp: temporary buffer for writebacks used by the FUSE module

Of course, operations are much slower when they involve secondary memory. Because of this, monitoring how much data is pending enables an administrator to properly balance loads.

8. Mapped Memory

In addition, we can look at how much memory is mapped. Essentially, memory-mapped files are part of the virtual memory system, which contains a direct byte-level correlation with other resources. Memory mapping increases the maximum number of I/O operations, especially on large files:

$ cat /proc/meminfo | grep -w -e "AnonPages" -e "Mapped" -e "DirectMap4k" -e "DirectMap2M"
AnonPages:        470224 kB
Mapped:           144264 kB
DirectMap4k:      149440 kB
DirectMap2M:      899072 kB

To be sure, these mappings provide the following information:

  • AnonPages: anon (non-file) pages mapped into the page tables
  • Mapped: files that have been mapped into memory with mmap
  • DirectMap4k: the total amount of memory mapped by the kernel in 4 kB pages
  • DirectMap2M: the total amount of memory mapped by the kernel in 2 MB pages

While memory mapping has its benefits, it also blocks parts of the main memory from being used for actual data.

9. Shared Memory

Moreover, we can learn about the shared memory in the system. Shared memory is an additional memory location for processes with separate address spaces. Such processes can share a portion of memory:

$ cat /proc/meminfo | grep "Shmem"
Shmem:             16520 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB

There are several ways to represent the shared memory:

  • Shmem: the amount used by shared memory and the tmpfs filesystem
  • ShmemHugePages: the amount used by shared memory and the tmpfs filesystem with huge pages
  • ShmemPmdMapped: userspace-mapped shared memory with huge pages

While convenient, shared memory presents challenges that may make it problematic.

10. Kernel Memory

The Linux kernel has lots of inner low-level operations to take care of memory. Fortunately, the /proc/meminfo file provides several kernel-level pieces of information as well:

$ cat /proc/meminfo | grep -ie "reclaim" -e "slab" -e "kernel"
KReclaimable:      35008 kB
Slab:              88752 kB
SReclaimable:      35008 kB
SUnreclaim:        53744 kB
KernelStack:        5988 kB

In fact, the kernel uses memory in different ways:

  • KReclaimable: kernel allocated memory, reclaimable under memory pressure (includes SReclaimable)
  • Slab: kernel-level data structures cache, allocation of contiguous pages for caches by the slab allocator
  • SReclaimable: reclaimable parts of Slab, e.g., caches
  • SUnreclaim: unreclaimable parts of Slab
  • KernelStack: memory for kernel stacks of entire tasks

For example, the kernel memory holds all open file descriptors. Running out of kernel memory can cause the forceful termination of processes.

11. Allocation Availability

If we want to learn the amount of memory eligible for allocation or already allocated on the system, we can take a look at two data fields:

$ cat /proc/meminfo | grep -ie "commit"
CommitLimit:     1442580 kB
Committed_AS:    3035924 kB

Markedly, these data points demonstrate the allocation ability of the system:

  • CommitLimit: amount currently available for allocation on the system
  • Committed_AS: amount already allocated on the system

Note the difference between Committed_AS and the Inactive field we already saw. In fact, there’s a formula for calculating the current allocatable amount of memory.

12. Virtual Memory

Besides, /proc/meminfo contains some data about the virtual memory system:

$ cat /proc/meminfo | grep -e "PageTables" -e "Vmalloc"
PageTables:        11520 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       34780 kB
VmallocChunk:          0 kB

Using the output above, let’s define the meaning of each field:

  • PageTables: the amount of memory consumed by page tables used by the virtual memory system
  • VmallocTotal: total size of vmalloc memory space to allocate virtually contiguous memory
  • VmallocUsed: the size of the used vmalloc memory space
  • VmallocChunk: largest free contiguous block of vmalloc memory

Critically, these fields differ from the information about swap, as there is a difference between swap and virtual memory.

13. Huge Pages

Since the Linux kernel supports huge (larger than the default) pages, we can see data about them as well:

$ cat /proc/meminfo | grep -ie "huge" -e "filepmd" | grep -v "Shmem"
AnonHugePages:         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

Obviously, we get lots of information to look at:

  • AnonHugePages: anon (non-file) huge pages mapped into the page tables
  • FileHugePages: memory consumed by page cache allocated with huge pages
  • FilePmdMapped: mapped page cache in the userspace allocated with huge pages
  • HugePages_Total: total size of the huge pages pool
  • HugePages_Free: amount of unallocated huge pages
  • HugePages_Rsvd: number of reserved huge pages for allocation from the pool, which guarantees the allocation for processes when undesired behavior occurs
  • HugePages_Surp: number of surplus huge pages above a specific base value in /proc/sys/vm/nr_hugepages
  • Hugepagesize: the default size of huge pages
  • Hugetlb: the total amount of memory allocated for huge pages of all sizes

Generally, systems that process data in larger chunks can benefit greatly from huge pages. In such cases, controlling and monitoring the current huge page settings is crucial.

14. Others

Finally, we can also get some miscellaneous information along the rest of the categories:

$ cat /proc/meminfo | grep -e "Unevictable" -e "Mlocked" -e "NFS" -e "Bounce" -e "Percpu" -e "Hardware"
Unevictable:           0 kB
Mlocked:               0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
Percpu:             1312 kB
HardwareCorrupted:     0 kB

Each field in this set refers to a distinct attribute of memory:

  • Unevictable: unreclaimable memory consumed by userspace like mlock-locke, ramfs backing, and anonymous memfd pages
  • Mlocked: amount of memory locked with mlock
  • NFS_Unstable: Network File System pages that have been written to the disk but not yet committed to stable storage, always zero
  • Bounce: amount of memory for bounce buffers, which are low-level memory areas that enable devices to copy and write data
  • Percpu: memory used for the percpu interface allocations
  • HardwareCorrupted: memory that the kernel spots as corrupted

Of these, HardwareCorrupted is usually very helpful, as it points out potential issues with memory, affecting all other discussed fields.

15. Conclusion

In this article, we learned about the structure of data inside /proc/meminfo. In fact, we saw that this file contains most of the information we might need about memory. We then inspected every piece of data by splitting them into categories.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.