Home » Linux, OS Concepts and Networking » Operating System Concepts » Understanding /proc/meminfo – Analysing Linux memory utilisation

Understanding /proc/meminfo – Analysing Linux memory utilisation

/proc/meminfo Provides valuable information about the system’s RAM usage. (utilization of run time memory).  This varies by architecture and compile options.  The following is from a 4GB RAM, 64bit Ubuntu Desktop

>$ cat /proc/meminfo
MemTotal: 4103420 kB
MemFree: 449084 kB
MemAvailable: 1149688 kB
Buffers: 170416 kB
Cached: 1031280 kB
SwapCached: 0 kB
Active: 2808536 kB
Inactive: 677736 kB
Active(anon): 2289572 kB
Inactive(anon): 175532 kB
Active(file): 518964 kB
Inactive(file): 502204 kB
Unevictable: 64 kB
Mlocked: 64 kB
HighTotal: 3245320 kB
HighFree: 237920 kB
LowTotal: 858100 kB
LowFree: 211164 kB
SwapTotal: 4157436 kB
SwapFree: 4157436 kB
Dirty: 844 kB
Writeback: 0 kB
AnonPages: 2284636 kB
Mapped: 574512 kB
Shmem: 180532 kB
Slab: 84428 kB
SReclaimable: 59308 kB
SUnreclaim: 25120 kB
KernelStack: 6944 kB
PageTables: 31480 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 6209144 kB
Committed_AS: 13246396 kB
VmallocTotal: 122880 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
AnonHugePages: 1040384 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 45048 kB
DirectMap2M: 868352 kB

MemTotal: Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code) MemTotal is the sum of HighTotal and LowTotal.

MemFree: The amount of physical RAM, in kibibytes, left unused by the system. MemFree is the total amount of physical memory not used by the system. MemFree: Is sum of LowFree + HighFree.

MemAvailable : MemAvailable is An estimate of how much memory is available for starting new applications, without swapping. Many load balancing and workload placing programs check /proc/meminfo to estimate how much free memory is available. They generally do this by adding up “free” and “cached”, which was fine ten years ago, but is pretty much guaranteed to be wrong today. It is wrong because Cached includes memory that is not freeable as page cache, for example shared memory segments, tmpfs, and ramfs, and it does not include reclaimable slab memory, which can take up a large fraction of system memory on mostly idle systems with lots of files. Currently, the amount of memory that is available for a new workload, without pushing the system into swap, can be estimated from MemFree, Active(file), Inactive(file), and SReclaimable, as well as the “low” watermarks from /proc/zoneinfo. kernel.org reference

Buffers: Relatively temporary storage for raw disk blocks shouldn’t get tremendously large (20MB or so) OR The amount, in kibibytes, of temporary storage for raw disk blocks. The buffers remember what’s in directories, what file permissions are, and keep track of what memory is being written from or read to for a particular block device. Buffer is for storing file metadata (permissions, location, etc).

Cached: in-memory cache for files read from the disk (the page cache).  Cached is the size of the Linux page cache, minus the memory in the swap cache, which is represented by SwapCached (thus the total page cache size is Cached + SwapCached). Linux performs all file I/O through the page cache. Writes are implemented as simply marking as dirty the corresponding pages in the page cache; the flusher threads then periodically write back to disk any dirty pages. Reads are implemented by returning the data from the page cache; if the data is not yet in the cache, it is first populated. On a modern Linux system, Cached can easily be several gigabytes. It will shrink only in response to memory pressure. The system will purge the page cache along with swapping data out to disk to make available more memory as needed.

SwapCached: Memory that once was swapped out, is swapped back in but still also is in the swapfile (if memory is needed it doesn’t need to be swapped out AGAIN because it is already in the swapfile. This saves I/O)

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

The sum of these two ( Active & Inactive ) corresponds to all memory under control of the page replacement algorithm (i.e. anonymous pages plus page/swap cache (‘buffers’ + ‘cached’ + ‘swap cache’)). The distinction active vs. inactive refers to the method the page replacement algorithm uses to decide when to swap pages out; the basic idea is that a page goes from ‘active’ to ‘inactive’ state after it hasn’t been used for some time, and if an ‘inactive’ page continues to remain unused from some more time, it’ll get swapped out. Reference

Active is the total of Active(anon) and Active(file). Similarly, Inactive is the total of Inactive(anon) + Inactive(file).

Active(anon) — The amount of anonymous and tmpfs/shmem memory, in kibibytes, that is in active use, or was in active use since the last time the system moved something to swap.
Inactive(anon) — The amount of anonymous and tmpfs/shmem memory, in kibibytes, that is a candidate for eviction.
Active(file) — The amount of file cache memory, in kibibytes, that is in active use, or was in active use since the last time the system reclaimed memory.
Inactive(file) — The amount of file cache memory, in kibibytes, that is newly loaded from the disk, or is a candidate for reclaiming.

HighTotal: is the total amount of memory in the high region. Highmem is all memory above (approx) 860MB of physical RAM. Kernel uses indirect tricks to access the high memory region. Data cache can go in this memory region.

HighFree: Highmem is all memory above ~860MB of physical memory. Highmem areas are for use by userspace programs, or for the pagecache.  The kernel must use tricks to access this memory, making it slower to access than lowmem.

LowFree: Lowmem is memory which can be used for everything that highmem can be used for, but it is also availble for the kernel’s use for its own data structures.  Among many other things, it is where everything from the Slab is allocated.  Bad things happen when you’re out of lowmem.

MemFree: Is sum of LowFree + HighFree

LowFree: The amount of free memory of the low memory region. This is the memory the kernel can address directly. All kernel datastructures need to go into low memory.

MemTotal: HighTotal + LowTotal

SwapTotal: Total amount of swap space available
SwapFree: The total amount of swap free, in kilobytes.

Dirty: Memory which is waiting to get written back to the disk. The Dirty field refers to data that is stored in memory and still needs to be written to the disk.
You can easily verify this by trying to create a 10MB text file in home folder as,

 $ cat /proc/meminfo | grep Dirty 
 $ dd if=/dev/zero of=./testfile.txt bs=1M count=10 
 $ cat /proc/meminfo | grep Dirty 

From this you can see as, Dirty is shown around 10MB of memory. Now, if you do “sync” which is clearing of any pending writes, we can see Dirty memory gets reduced by 10MB which is actually what we created for testfile.txt file.

 $ sync 

Writeback: Memory which is actively being written back to the disk

Mapped: files which have been mmaped, such as libraries

Slab: in-kernel data structures cache

Committed_AS: An estimate of how much RAM you would need to make a 99.99% guarantee that there never is OOM (out of memory) for this workload. Normally the kernel will overcommit memory. That means, say you do a 1GB malloc, nothing happens, really. Only when you start USING that malloc memory you will get real memory on demand, and just as much as you use. So you sort of take a mortgage and hope the bank doesn’t go bust. Other cases might include when you mmap a file that’s shared only when you write to it and you get a private copy of that data. While it normally is shared between processes. The Committed_AS is a guesstimate of how much RAM/swap you would need worst-case.

PageTables: amount of memory dedicated to the lowest level of page

ReverseMaps: number of reverse mappings performed

VmallocTotal: total size of vmalloc memory area

VmallocUsed: amount of vmalloc area which is used

VmallocChunk: largest contigious block of vmalloc area which is free

Reference: http://lwn.net/Articles/28345/

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment