900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Linux free 查看内存使用情况 常用命令

Linux free 查看内存使用情况 常用命令

时间:2021-07-03 21:28:54

相关推荐

Linux free 查看内存使用情况 常用命令

Intro

常用命令

free

free -h以更易读(human-readable)的格式输出

free -s 3每3秒输出一次

示例

wuyujin1997@budy:~$ free -htotal used freeshared buff/cache availableMem: 985M 253M 124M 2.7M 607M 566MSwap: 0B0B0Bwuyujin1997@budy:~$

行列意义

先区分行:

Mem真正的物理内存Swap交换空间(物理量内存过小时利用了硬盘空间进行“中转”的空间)

再区分列:

total机器的整体内存大小(物理内存 + 处于硬盘区的交换空间)

used已使用的内存大小,计算方式:total - free - buffers - cache

free未使用/空闲的内存

shared共享内存(tmpfs使用的内存)

buff/cache内核使用的缓冲块buffer、页面缓存cache。

available估算在不使用交换空间的前提下,有多少内存可用于新启动的程序运行。

表格分析

total used freeshared buff/cache availableMem: 985M 253M 124M 2.7M 607M 566MSwap: 0B0B0B

由表格可见,我的机器:

内存大小total为:985M

已使用内存used为:253M

空闲内存free为:124M

buff/cache之和为607M

而:已使用内存 + 空闲内存 +buff/cache= 253 + 124 + 607 = 984M 约等于整体内存985M

两个核心指标:

total机器整体内存有985M

available新运行程序的可用内存大小为566M(而非free的124M)

available是大于free值的,因为如果新启动的程序内存不够用,可以去回收buff/cache的大小来运行新的程序。

可得available的值上限:free+buff/cache

即:0 < available < (free + buff/cache)毕竟buff/cache使用的内存是不能被全部回收的。

程序文档

查看free命令的使用手册

man free

NAMEfree - Display amount of free and used memory in the systemSYNOPSISfree [options]DESCRIPTIONfree displays the total amount of free and used physical and swap memory in the system, as well as the buffersand caches used by the kernel. The information is gathered by parsing /proc/meminfo. The displayed columns are:total Total installed memory (MemTotal and SwapTotal in /proc/meminfo)used Used memory (calculated as total - free - buffers - cache)free Unused memory (MemFree and SwapFree in /proc/meminfo)shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)buffersMemory used by kernel buffers (Buffers in /proc/meminfo)cache Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)buff/cacheSum of buffers and cacheavailableEstimation of how much memory is available for starting new applications, without swapping. Unlike thedata provided by the cache or free fields, this field takes into account page cache and also that not allreclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo,available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)...

可见:free命令的输出信息是基于/proc/meminfo文件的

查看系统文件

more /proc/meminfo

wuyujin1997@budy:~$ more /proc/meminfoMemTotal: 1008720 kBMemFree:123096 kBMemAvailable:575792 kBBuffers:145400 kBCached: 398732 kBSwapCached: 0 kBActive: 622084 kBInactive: 141012 kBActive(anon):219436 kBInactive(anon):2348 kBActive(file):402648 kBInactive(file): 138664 kBUnevictable: 0 kBMlocked:0 kBSwapTotal: 0 kBSwapFree: 0 kBDirty:372 kBWriteback: 0 kBAnonPages: 219020 kBMapped: 9 kBShmem: 2820 kBSlab: 93564 kBSReclaimable:77848 kBSUnreclaim: 15716 kBKernelStack: 2988 kBPageTables: 7156 kBNFS_Unstable:0 kBBounce:0 kBWritebackTmp:0 kBCommitLimit:504360 kBCommitted_AS:906428 kBVmallocTotal: 34359738367 kBVmallocUsed: 0 kBVmallocChunk:0 kBHardwareCorrupted:0 kBAnonHugePages: 0 kBShmemHugePages: 0 kBShmemPmdMapped: 0 kBCmaTotal: 0 kBCmaFree:0 kBHugePages_Total: 0HugePages_Free: 0HugePages_Rsvd: 0HugePages_Surp: 0Hugepagesize: 2048 kBDirectMap4k: 85888 kBDirectMap2M:962560 kBDirectMap1G: 0 kBwuyujin1997@budy:~$

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。