linux内存使用系列(一):free命令详解

来源:互联网 发布:网络广告发布软件 编辑:程序博客网 时间:2024/06/04 19:11

free命令用于查看linux的内存使用情况,我们先看看free的注解:

$ free -hfree: invalid option -- 'h'usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]  -b,-k,-m,-g show output in bytes, KB, MB, or GB  -l show detailed low and high memory statistics  -o use old format (no -/+buffers/cache line)  -t display total for RAM + swap  -s update every [delay] seconds  -c update [count] times  -V display version information and exit

其中,-b,-k,-m,-g代表输出的数据使用的单位,分别是B,KB,MB,GB。
-l显示详细最高和最低内存统计。
-o不显示-/+buffers/cache这行。
-t显示总内存,total = mem + swap。
-s delay 每隔delay秒更新输出一次。
-c count与-s配合使用,控制更新count 次。
-V大写,打印版本号信息。

$free -Vprocps version 3.2.8

我们以free -lm命令来分析free输出的每个数据的含义,如下:

$free -lm             total       used       free     shared    buffers     cachedMem:          1877       1802         75          0         79       1179Low:          1877       1802         75High:            0          0          0-/+ buffers/cache:        542       1334Swap:         2015         22       1993

可以看出,使用-l命令打印出了Low和High这两行(目前不知道为啥high都是0),我们暂且不分析这两行,剩下的是常规输出内容。
横轴有:total,used,free,shared,buffers,cached。
纵轴有:Mem,Low,High,-/+buffers/cache,Swap。
total:表示物理总内存。
used:表示总计分配给缓存(包含buffers与cache)使用的数量,但其中可能部分缓存并未实际使用。
free:未被分配的内存。
shared:共享内存,是进程间互相共享的内存部分,一般系统不会用到,这里不作讨论。
buffers:系统分配但未被使用的buffers的数量。
cached:系统分配但未被使用的cache的数量。
Mem:物理内存统计。
-/+ buggers/cache:表示物理内存的缓存统计。
Swap:表示硬盘上交换分区的统计(这次不作分析)。
其中:mTotal = mUsed + mFree
mTotal = bcUsed + bcFree
mUsed = bcUsed + mCached + mBuffers
bcFree = mFree + mCached + mBuffers
m和bc的区别在于,m是对于OS来说的,对于系统来说,只要被分配了,包括buffers和cached都是属于被使用的,used中包含OS+application使用的内存+buffers+cached。bc是对于应用程序来说的,对于application来说,buffers+cached是等于可用的,因为buffers/cached是为了提高文件读取的性能,当应用程序需在用到内存的时候,buffer/cached会很快地被回收。

原创粉丝点击