The /proc filesystem is pseudo filesystem. It does not exist on a disk. Instead, the kernel creates it in memory. It is used to provide information about the system (originally about processes, hence the name).
The ‘/proc/meminfo’ is used by to report the amount of free and used memory (both physical and swap) on the system as well as the shared memory and buffers used by the kernel.
The /proc filesystem is described in more detail in the proc manual page.
# cat /proc/meminfo MemTotal: 16344972 kB MemFree: 13634064 kB Buffers: 3656 kB Cached: 1195708 kB SwapCached: 0 kB Active: 891636 kB Inactive: 1077224 kB HighTotal: 15597528 kB HighFree: 13629632 kB LowTotal: 747444 kB LowFree: 4432 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 968 kB Writeback: 0 kB Mapped: 280372 kB Slab: 684068 kB Committed_AS: 1576424 kB PageTables: 24448 kB ReverseMaps: 1080904 VmallocTotal: 112216 kB VmallocUsed: 428 kB VmallocChunk: 111088 kB
$ cat /proc/meminfo MemTotal: 16464260 kB MemFree: 5206868 kB Buffers: 17980 kB Cached: 7395552 kB SwapCached: 114124 kB Active: 5590956 kB Inactive: 4426264 kB Active(anon): 2191992 kB Inactive(anon): 416676 kB Active(file): 3398964 kB Inactive(file): 4009588 kB Unevictable: 32204 kB Mlocked: 13808 kB SwapTotal: 2096476 kB SwapFree: 1264996 kB Dirty: 144 kB Writeback: 0 kB AnonPages: 2547488 kB Mapped: 55404 kB Shmem: 56 kB Slab: 956820 kB SReclaimable: 884568 kB SUnreclaim: 72252 kB KernelStack: 4792 kB PageTables: 44052 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 10328604 kB Committed_AS: 3304140 kB VmallocTotal: 34359738367 kB VmallocUsed: 307816 kB VmallocChunk: 34359426296 kB HardwareCorrupted: 0 kB AnonHugePages: 1689600 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 7488 kB DirectMap2M: 16764928 kB
Above output information devided into two high and low-statistics. At the top you see a summary of the most common values people would like to look at.
MemTotal: Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code)
MemFree: Is sum of LowFree+HighFree (overall stat)
MemShared: 0; is here for compat reasons but always zero.
Buffers: Memory in buffer cache. mostly useless as metric nowadays Relatively temporary storage for raw disk blocks shouldn’t get tremendously large (20MB or so)
Cached: Memory in the pagecache (diskcache) minus SwapCache, Doesn’t include SwapCached
SwapCache: 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 )
VM splits the cache pages into “active” and “inactive” memory. The idea is that if you need memory and some cache needs to be sacrificed for that, you take it from inactive since that’s expected to be not used. The vm checks what is used on a regular basis and moves stuff around.
When you use memory, the CPU sets a bit in the pagetable and the VM checks that bit occasionally, and based on that, it can move pages back to active. And within active there’s an order of “longest ago not used” (roughly, it’s a little more complex in reality). The longest-ago used ones can get moved to inactive. Inactive is split into two in the above kernel (2.4.18-24.8.0). Some have it three.
The statistics are:
Active: Memory that has been used more recently and usually not reclaimed unless absolut necessary.
Inact_dirty: Dirty means “might need writing to disk or swap.” Takes more work to free. Example might be files that have not been written to yet. They aren’t written to memory too soon in order to keep the I/O down. For instance, if you’re writing logs, it might be better to wait until you have a complete log ready before sending it to disk.
Inact_clean: Assumed to be easily freeable. The kernel will try to keep some clean stuff around always to have a bit of breathing room.
Inact_target: Just a goal metric the kernel uses for making sure there are enough inactive pagesaround. When exceeded, the kernel will not do work to move pages from active to inactive. A page can also get inactive in a few other ways, e.g. if you do a long sequential I/O, the kernel assumes you’re not going to use that memory and makes it inactive preventively. So you can get more inactive pages than the target because the kernel marks some cache as “more likely to be never used” and lets it cheat in the “last used” order.
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.
LowTotal: The total amount of non-highmem memory.
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.
SwapTotal: Total amount of physical swap memory.
SwapFree: Total amount of swap memory free. Memory which has been evicted from RAM, and is temporarily on the disk
Dirty: Memory which is waiting to get written back to the disk
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 tables.
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
Estimating the resource usage, especially the memory consumption of processes is by far more complicated than it looks like at a first glance. The philosophy is an unused resource is a wasted resource.The kernel therefore will use as much RAM as it can to cache information from your local and remote filesystems/disks. This builds up over time as reads and writes are done on the system
trying to keep the data stored in RAM as relevant as possible to the processes that have been running on your system. If there is free RAM available, more caching will be performed and thus more memory ‘consumed’. However this doesn’t really count as resource usage, since this cached memory is available in case some other process needs it. The cache is reclaimed, not at the time of process exit (you might start up another process soon that needs the same data), but upon demand.
When you start a process that needs a lot of memory to run, the OS kernel will reclaim memory that had been storing cached data and give it to the new process.
The system numbers normally are trust, but even they can be misinterpreted quite easily i.e.: using ‘top’
00 processes: 397 sleeping, 2 running, 1 zombie, 0 stopped CPU0 states: 0.1% user, 0.3% system, 0.0% nice, 99.1% idle CPU1 states: 0.3% user, 2.0% system, 0.0% nice, 97.1% idle CPU2 states: 2.3% user, 8.1% system, 0.0% nice, 88.4% idle CPU3 states: 100.0% user, 0.0% system, 0.0% nice, 0.0% idle Mem: 16167672K av, 16124948K used, 42724K free, 1710184K shrd, 351304K buff Swap: 12582608K av, 15892K used, 12566716K free 13326028K cache
top - 05:49:20 up 59 days, 19:01, 36 users, load average: 3.00, 3.05, 3.01 Tasks: 344 total, 3 running, 340 sleeping, 0 stopped, 1 zombie Cpu(s): 7.0%us, 27.8%sy, 0.0%ni, 64.7%id, 0.4%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 16464260k total, 11263872k used, 5200388k free, 18148k buffers Swap: 2096476k total, 831480k used, 1264996k free, 7400016k cached
What sometimes confuses people is the buffer and cache on Linux:
Mem: 16167672K av, 16124948K used, 42724K free, 1710184K shrd, 351304K buff Swap: 12582608K av, 15892K used, 12566716K free 13326028K cache
Looking at 16124948K used, This means the you system is buffering and caching 15Gb of RAM and in case this RAM is available for any process that need it.
$ free total used free shared buffers cached Mem: 16167672 16129820 37852 1710184 351312 13330324 -/+ buffers/cache: 2448184 13719488 Swap: 12582608 15892 12566716 Looking at the third line: -/+ buffers/cache: 2448184 13719488
The system is using 2448184K (= 2GB) for your applications/process and it has a potentially free RAM of 13Gb. This one used for buffering & caching. In order to evaluate the memory process consumption you should use the ‘free’ command before, during and after running process doing this several time you can to get an average of what you are searching for.
If you want to know per process memory consumption you can also use commands below:
$ cat /proc/<pid>/maps ... $ cat /proc/<pid>/status