What elements of /proc/meminfo sum up to MemTotal?

Example of tee /tmp/proc/meminfo < /proc/meminfo

MemTotal:        1279296 kB
MemFree:          164092 kB
Buffers:           62392 kB
Cached:           378116 kB
SwapCached:            0 kB
Active:           715176 kB
Inactive:         307800 kB
Active(anon):     583268 kB
Inactive(anon):     3384 kB
Active(file):     131908 kB
Inactive(file):   304416 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                44 kB
Writeback:             0 kB
AnonPages:        582480 kB
Mapped:           112904 kB
Shmem:              4192 kB
Slab:              47524 kB
SReclaimable:      33588 kB
SUnreclaim:        13936 kB
KernelStack:        1568 kB
PageTables:        12092 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      639648 kB
Committed_AS:    1298132 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       24012 kB
VmallocChunk:   34359696868 kB
HardwareCorrupted:     0 kB
AnonHugePages:     77824 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:        8832 kB
DirectMap2M:     1300480 kB

Here are snippets that helps me in checking different configurations:

# Let's load them into CLI variables
all=$(sed 's!:[^0-9]\+!=!;s! kB!!;s![()]!_!g' /tmp/proc/meminfo) ; eval $all
# Let's make overview sorted by values (helps in tracking missing one)
echo $all | sed 's! !\n!g' | sort -n -k 2 -t '=' 
# Let's try Memtotal=MemFree+Active+Cached+Buffers ? (should be zero)
echo $[ $MemTotal - $MemFree - $Active - $Cached - $Buffers ]
# But gives -40480

What am I missing? Which elements of /proc/meminfo should I sum to get MemTotal?

  • 1
    You're assuming the format includes redundant information. I'm not sure, but I think it's possible that all the fields are actually useful... maybe MemTotal tells you something you can't calculate from all the other numbers. The free tool displays "total, used, free" memory, and it calculates used = total - free itself rather than looking for a "Used" field in meminfo. – user41515 Jul 28 '13 at 14:31

I'm not sure everything you need is exposed in /proc/meminfo's output so that you can calculate MemTotal yourself. From the Linux Kernel's documentation proc.txt file:

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


If you look through either the output of dmesg or the log file /var/log/dmesg you can find the following information:

$ grep -E "total|Memory:.*available" /var/log/dmesg
[    0.000000] total RAM covered: 8064M
[    0.000000] On node 0 totalpages: 2044843
[    0.000000] Memory: 7970012k/9371648k available (4557k kernel code, 1192276k absent, 209360k reserved, 7251k data, 948k init)

I believe this information can be used to determine MemTotal. This blog post covers it in more details, it's titled: Understanding “vmalloc region overlap”. Also this post, which provides some additional info, titled: Anatomy of a Program in Memory.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.