/proc/meminfo
一种最简单的方法是通过“/proc/meminfo”来检查内存使用状况。这个动态更新的虚拟文件事实上是诸如free,top和ps这些与内存相关的工具的信息来源。从可用/闲置物理内存数量到等待被写入缓存的数量或者已写回磁盘的数量,只要是你想要的关于内存使用的信息,“/proc/meminfo”应有尽有。特定进程的内存信息也可以通过“/proc//statm”和“/proc//status”来获取。
命令:cat /proc/meminfo
结果:
MemTotal: 131904896 kB
MemFree: 603800 kB
MemAvailable: 102514524 kB
Buffers: 3552932 kB
Cached: 96904864 kB
SwapCached: 0 kB
Active: 31346020 kB
Inactive: 97106916 kB
Active(anon): 27475172 kB
Inactive(anon): 541828 kB
Active(file): 3870848 kB
Inactive(file): 96565088 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 999420 kB
SwapFree: 999420 kB
Dirty: 18509364 kB
Writeback: 145496 kB
AnonPages: 27995080 kB
Mapped: 137556 kB
Shmem: 21976 kB
Slab: 2603612 kB
SReclaimable: 2538160 kB
SUnreclaim: 65452 kB
KernelStack: 7824 kB
PageTables: 78160 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 66951868 kB
Committed_AS: 29698188 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 125628 kB
DirectMap2M: 6041600 kB
DirectMap1G: 130023424 kB
free
free命令是一个用来获得内存使用概况的快速简单的方法,这些信息从“/proc/meminfo”获取。它提供了一个快照,用于展示总计/闲置的物理内存和系统交换区,以及已使用/闲置的内核缓冲区。free -h
结果如图所示:>>> free -h
total used free shared buff/cache available
Mem: 125G 29G 506M 21M 95G 94G
Swap: 975M 0B 975M