/proc/meminfo
总结起来有哪些要素MemTotal
?
的例子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
以下是帮助我检查不同配置的片段:
# 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
我缺少什么?我应该对哪些元素/proc/meminfo
求和才能得到MemTotal
?
答案1
我不确定您需要的所有内容都已在/proc/meminfo
的输出中公开,以便您可以MemTotal
自己计算。来自Linux内核的文档proc.txt
文件:
MemTotal: Total usable ram (i.e. physical ram minus a few reserved
bits and the kernel binary code)
消息
如果您查看输出dmesg
或日志文件,/var/log/dmesg
您可以找到以下信息:
$ 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)
相信这个信息可以用来判断MemTotal
。这篇博文更详细地介绍了它,标题为:了解“vmalloc 区域重叠”。另外这篇文章提供了一些额外的信息,标题为:内存中程序的剖析。