free命令常用参数详解
free命令常用参数详解及常用内存工具介绍
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.内存空间使用状态
1>."-b"参数(以字节为单位显示内存使用情况)
[root@node101.yinzhengjie.org.cn ~]# free -b
total used free shared buff/cache available
Mem:
Swap:
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -b
2>."-k"参数(默认选项,以“kb”为单位显示内存使用情况)
[root@node101.yinzhengjie.org.cn ~]# free -k
total used free shared buff/cache available
Mem:
Swap:
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -k
3.“-m”参数(以“mb”为单位显示内存使用情况)
[root@node101.yinzhengjie.org.cn ~]# free -m
total used free shared buff/cache available
Mem:
Swap:
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -m
4>.“-g”参数(以"gb"为单位显示内存使用情况)
[root@node101.yinzhengjie.org.cn ~]# free -g
total used free shared buff/cache available
Mem:
Swap:
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -g
5>.以易读格式显示
[root@node101.yinzhengjie.org.cn ~]# free -h
total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -h
6>.“-s”参数(后面需要跟个数字,单位是"s",显示每隔多少秒数来显示一次内存使用情况)
[root@node101.yinzhengjie.org.cn ~]# free -h -s
total used free shared buff/cache available
Mem: .6G 132M .2G 8.6M 288M .3G
Swap: .9G 0B .9G total used free shared buff/cache available
Mem: .6G 132M .2G 8.6M 288M .3G
Swap: .9G 0B .9G total used free shared buff/cache available
Mem: .6G 132M .2G 8.6M 288M .3G
Swap: .9G 0B .9G total used free shared buff/cache available
Mem: .6G 132M .2G 8.6M 288M .3G
Swap: .9G 0B .9G total used free shared buff/cache available
Mem: .6G 132M .2G 8.6M 288M .3G
Swap: .9G 0B .9G total used free shared buff/cache available
Mem: .6G 132M .2G 8.6M 288M .3G
Swap: .9G 0B .9G ^C
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -h -s 1
7>.“-t”参数(在末尾活多出一行“Total”,表示显示总和列)
[root@node101.yinzhengjie.org.cn ~]# free -t -h -s
total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
Total: 15G 131M 15G total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
Total: 15G 131M 15G total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
Total: 15G 131M 15G total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
Total: 15G 131M 15G total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
Total: 15G 131M 15G total used free shared buff/cache available
Mem: .6G 131M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
Total: 15G 131M 15G ^C
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -t -h -s 1
8.“-o”参数(不显示包含“-/+ buffers/cache”的这一列,新版本已经移除了该选项),
[root@yinzhengjie ~]# free -t -o -m -s
total used free shared buffers cached
Mem:
Swap:
Total: total used free shared buffers cached
Mem:
Swap:
Total: total used free shared buffers cached
Mem:
Swap:
Total: total used free shared buffers cached
Mem:
Swap:
Total: total used free shared buffers cached
Mem:
Swap:
Total: ^C
[root@yinzhengjie ~]#
free -t -o -m -s 1
9>."-C"参数(刷新n次后即退出)
[root@node101.yinzhengjie.org.cn ~]# free -t -c -m -s
total used free shared buff/cache available
Mem:
Swap:
Total: total used free shared buff/cache available
Mem:
Swap:
Total: total used free shared buff/cache available
Mem:
Swap:
Total:
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -t -c 3 -m -s 1
10>.输出结果说明
total used free shared buffers cached #第一行
Mem: #第二行
-/+ buffers/cache: #第三行
Swap: #第四行 我们知道这个是"free -m"的输出结果,我只不过是将结果取出来了,然后进行标号,用坐标的方式来讲解如何查看内容:
第一行:
total(,):总计物理内存的大小。
used(,):已使用的空间。
free(,):可用的空间。
shared(,):多个进程共享的内存总额。现在已经deprecated,其值总是0(当然在一些系统上也可能不是0,主要取决于free命令是怎么实现的)。
buffers(,):用于存放要输出到disk(块设备)的数据的,[A buffer is something that has yet to be "written" to disk. ]即提高了内存网硬盘加速写的能力
cached(,):存放从disk上读出的数据,['A cache is something that has been "read" from the disk and stored for later use.'] (cached往往比buffers数字大就是为了提高IO read的性能)即提高了加速读的能力 第二行:(输出时从操作系统(OS)来看的)
看了第一行的解释,我能知道了第一行输出时从操作系统(OS)来看的。也就是说,从OS的角度来看
(3.3):即7855MB物理内存;
(,):7718MB已经被使用了;
(,):137MB可用被使用。
因此,我们可以得到一个公式哟:(3.3)= (,)+ (,) 第三行:(是从一个应用程序的角度看系统内存的使用情况)
(,,):即-buffers/cache,表示一个应用程序认为系统被用掉多少内存;
(,):即+buffers/cache,表示一个应用程序认为系统还有多少内存;
因此我们又可以得到2个公式哟:
>.(,) = (,) - (,) - (,)
>.(,) = (,) + (,) - (,)
第四行:
free的输出一共有四行,第四行为交换区的信息,分别是交换的总量(total),使用量(used)和有多少空闲的交换区(free) 温馨提示:
free命令由procps.*.rpm提供(在Redhat系列的OS上)。free命令的所有输出值都是从/proc/meminfo中读出的。“-/+ buffers/cache”其对应的used表示实际使用内存,对应的free对应的才是实际空闲的内存。
二.vmstat命令(查看虚拟内存信息)
[root@node101.yinzhengjie.org.cn ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st [root@node101.yinzhengjie.org.cn ~]# 参数说明:
procs:
r:
可运行(正运行或等待运行)进程的个数,和核心数有关
b:
处于不可中断睡眠态的进程个数(被阻塞的队列的长度) memory:
swpd:
交换内存的使用总量
free:
空闲物理内存总量
buffer:
用于buffer的内存总量
cache:
用于cache的内存总量 swap:
si:
从磁盘交换进内存的数据速率(kb/s)
so:
从内存交换至磁盘的数据速率(kb/s) io:
bi:
从块设备读入数据到系统的速率(kb/s)
bo:
保存数据至块设备的速率 system:
in:
interrupts 中断速率,包括时钟
cs:
context switch 进程切换速率 cpu:
us:
Time spent running non-kernel code
sy:
Time spent running kernel code
id:
Time spent idle. Linux 2.5.41前,包括IO-wait time.
wa:
Time spent waiting for IO. 2.5.41前,包括in idle.
st:
Time stolen from a virtual machine. 2.6.11前, unknown.
1>."-s" 参数显示内存的统计数据
[root@node101.yinzhengjie.org.cn ~]# vmstat -s
K total memory
K used memory
K active memory
K inactive memory
K free memory
K buffer memory
K swap cache
K total swap
K used swap
K free swap
non-nice user cpu ticks
nice user cpu ticks
system cpu ticks
idle cpu ticks
IO-wait cpu ticks
IRQ cpu ticks
softirq cpu ticks
stolen cpu ticks
pages paged in
pages paged out
pages swapped in
pages swapped out
interrupts
CPU context switches
boot time
forks
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# vmstat -s
2>.动态观察虚拟内存情况
[root@node101.yinzhengjie.org.cn ~]# vmstat 10 #指定每秒查看一次虚拟内存的情况,总共查询10次。
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st [root@node101.yinzhengjie.org.cn ~]#
3>.用于测试内存的相关命令
[root@node101.yinzhengjie.org.cn ~]# dd if=/dev/zero of=/dev/null bs=2G #从内存到内存 [root@node101.yinzhengjie.org.cn ~]# dd if=/dev/sda of=/dev/null #从磁盘读数据到内存 [root@node101.yinzhengjie.org.cn ~]# dd if=/dev/zero of=bigfile.txt #从内存写数据到磁盘(有可能会先放入Buffer)
三.交换分区管理
[root@node101.yinzhengjie.org.cn ~]# free -h
total used free shared buff/cache available
Mem: .6G 130M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# swapoff /dev/mapper/centos-swap #禁用交换内存
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -h
total used free shared buff/cache available
Mem: .6G 125M .2G 8.6M 288M .3G
Swap: 0B 0B 0B
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# swapon /dev/mapper/centos-swap #启用交换内存
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# free -h
total used free shared buff/cache available
Mem: .6G 130M .2G 8.6M 288M .3G
Swap: .9G 0B .9G
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
四.内存工具介绍
1>.iostat(统计CPU和设备IO信息)
[root@node101.yinzhengjie.org.cn ~]# yum -y install sysstat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package sysstat.x86_64 :10.1.-.el7 will be installed
--> Processing Dependency: libsensors.so.()(64bit) for package: sysstat-10.1.-.el7.x86_64
--> Running transaction check
---> Package lm_sensors-libs.x86_64 :3.4.-.20160601gitf9185e5.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =======================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================
Installing:
sysstat x86_64 10.1.-.el7 base k
Installing for dependencies:
lm_sensors-libs x86_64 3.4.-.20160601gitf9185e5.el7 base k Transaction Summary
=======================================================================================================================================
Install Package (+ Dependent package) Total download size: k
Installed size: 1.2 M
Downloading packages:
(/): lm_sensors-libs-3.4.-.20160601gitf9185e5.el7.x86_64.rpm | kB ::
(/): sysstat-10.1.-.el7.x86_64.rpm | kB ::
---------------------------------------------------------------------------------------------------------------------------------------
Total kB/s | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lm_sensors-libs-3.4.-.20160601gitf9185e5.el7.x86_64 /
Installing : sysstat-10.1.-.el7.x86_64 /
Verifying : lm_sensors-libs-3.4.-.20160601gitf9185e5.el7.x86_64 /
Verifying : sysstat-10.1.-.el7.x86_64 / Installed:
sysstat.x86_64 :10.1.-.el7 Dependency Installed:
lm_sensors-libs.x86_64 :3.4.-.20160601gitf9185e5.el7 Complete!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# yum -y install sysstat #需要安装该软件包才能使用
[root@node101.yinzhengjie.org.cn ~]# iostat 3 #每秒查询1次,共计查询3次
Linux 3.10.-.el7.x86_64 (node101.yinzhengjie.org.cn) // _x86_64_ ( CPU) avg-cpu: %user %nice %system %iowait %steal %idle
0.09 0.00 0.84 0.05 0.00 99.01 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 5.45 43.10 1992.06
dm- 5.02 35.74 1991.30
dm- 0.03 0.93 0.00
dm- 0.02 0.96 0.38 avg-cpu: %user %nice %system %iowait %steal %idle
4.58 0.00 21.37 2.80 0.00 71.25 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 171.00 0.00 87552.00
dm- 329.00 0.00 168448.00
dm- 0.00 0.00 0.00
dm- 0.00 0.00 0.00 avg-cpu: %user %nice %system %iowait %steal %idle
4.80 0.00 23.20 4.00 0.00 68.00 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 559.00 0.00 286208.00
dm- 545.00 0.00 279040.00
dm- 0.00 0.00 0.00
dm- 0.00 0.00 0.00 [root@node101.yinzhengjie.org.cn ~]#
2>.pmap命令(进程对应的内存映射)
[root@node101.yinzhengjie.org.cn ~]# pidof dd [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /proc/`pidof dd`/maps
- r-xp fd: /usr/bin/dd
- r--p fd: /usr/bin/dd
- rw-p fd: /usr/bin/dd
0152c000-0154d000 rw-p : [heap]
7f36062e0000-7f360c80a000 r--p fd: /usr/lib/locale/locale-archive
7f360c80a000-7f360c9cc000 r-xp fd: /usr/lib64/libc-2.17.so
7f360c9cc000-7f360cbcc000 ---p 001c2000 fd: /usr/lib64/libc-2.17.so
7f360cbcc000-7f360cbd0000 r--p 001c2000 fd: /usr/lib64/libc-2.17.so
7f360cbd0000-7f360cbd2000 rw-p 001c6000 fd: /usr/lib64/libc-2.17.so
7f360cbd2000-7f360cbd7000 rw-p :
7f360cbd7000-7f360cbf9000 r-xp fd: /usr/lib64/ld-2.17.so
7f360cdec000-7f360cdef000 rw-p :
7f360cdf7000-7f360cdf8000 rw-p :
7f360cdf8000-7f360cdf9000 r--p fd: /usr/lib64/ld-2.17.so
7f360cdf9000-7f360cdfa000 rw-p fd: /usr/lib64/ld-2.17.so
7f360cdfa000-7f360cdfb000 rw-p :
7fff6d857000-7fff6d878000 rw-p : [stack]
7fff6d9ce000-7fff6d9d0000 r-xp : [vdso]
ffffffffff600000-ffffffffff601000 r-xp : [vsyscall]
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# pmap `pidof dd`
: dd if=/dev/zero of=bigfile.txt
68K r-x-- dd
4K r---- dd
4K rw--- dd
000000000152c000 132K rw--- [ anon ]
00007f36062e0000 103592K r---- locale-archive
00007f360c80a000 1800K r-x-- libc-2.17.so
00007f360c9cc000 2048K ----- libc-2.17.so
00007f360cbcc000 16K r---- libc-2.17.so
00007f360cbd0000 8K rw--- libc-2.17.so
00007f360cbd2000 20K rw--- [ anon ]
00007f360cbd7000 136K r-x-- ld-2.17.so
00007f360cdec000 12K rw--- [ anon ]
00007f360cdf7000 4K rw--- [ anon ]
00007f360cdf8000 4K r---- ld-2.17.so
00007f360cdf9000 4K rw--- ld-2.17.so
00007f360cdfa000 4K rw--- [ anon ]
00007fff6d857000 132K rw--- [ stack ]
00007fff6d9ce000 8K r-x-- [ anon ]
ffffffffff600000 4K r-x-- [ anon ]
total 108000K
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# pmap `pidof dd` #读取效果要比上面的命令要好的多
3>.进程对应的内存映射的另外一种实现
[root@node101.yinzhengjie.org.cn ~]# pidof dd
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /proc/`pidof dd`/maps
- r-xp fd: /usr/bin/dd
- r--p fd: /usr/bin/dd
- rw-p fd: /usr/bin/dd
- rw-p : [heap]
7f4886004000-7f488c52e000 r--p fd: /usr/lib/locale/locale-archive
7f488c52e000-7f488c6f0000 r-xp fd: /usr/lib64/libc-2.17.so
7f488c6f0000-7f488c8f0000 ---p 001c2000 fd: /usr/lib64/libc-2.17.so
7f488c8f0000-7f488c8f4000 r--p 001c2000 fd: /usr/lib64/libc-2.17.so
7f488c8f4000-7f488c8f6000 rw-p 001c6000 fd: /usr/lib64/libc-2.17.so
7f488c8f6000-7f488c8fb000 rw-p :
7f488c8fb000-7f488c91d000 r-xp fd: /usr/lib64/ld-2.17.so
7f488cb10000-7f488cb13000 rw-p :
7f488cb1b000-7f488cb1c000 rw-p :
7f488cb1c000-7f488cb1d000 r--p fd: /usr/lib64/ld-2.17.so
7f488cb1d000-7f488cb1e000 rw-p fd: /usr/lib64/ld-2.17.so
7f488cb1e000-7f488cb1f000 rw-p :
7ffe3fad1000-7ffe3faf2000 rw-p : [stack]
7ffe3fbfc000-7ffe3fbfe000 r-xp : [vdso]
ffffffffff600000-ffffffffff601000 r-xp : [vsyscall]
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /proc/`pidof dd`/maps #易读性较差
free命令常用参数详解的更多相关文章
- chattr的常用参数详解
chattr的常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在实际生产环境中,有的运维工程师不得不和开发和测试打交道,在我们公司最常见的就是部署接口.每天每个人部署的 ...
- find常用参数详解
find常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在linux系统中,在init 3模式情况下都是命令行模式,这个时候我们想要找到一个文件的就得依赖一个非常好用的 ...
- cat常用参数详解
cat常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 最近,我的一个朋友对linux特别感兴趣,于是我觉得每天交给他一个命令的使用,这样一个月下来也会使用30个命令,基 ...
- rsync常用参数详解
rsync常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在linux中,一切皆是文件,包括你的终端,硬件设备信息,目录,内核文件等等.所以工作中我们难免会遇到拷贝文件 ...
- 以太坊客户端Geth命令用法-参数详解
Geth在以太坊智能合约开发中最常用的工具(必备开发工具),一个多用途的命令行工具. 熟悉Geth可以让我们有更好的效率,大家可收藏起来作为Geth命令用法手册. 本文主要是对geth help的翻译 ...
- nmap常用参数详解
nmap常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 借用英雄联盟的一个英雄赵信的一句话:“即使敌众我寡,末将亦能万军丛中取敌将首级!”.三国关羽,万军丛中斩了颜良, ...
- tcpdump常用参数详解
tcpdump常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 好久没有更新我的博客了,看来自己最近还没有在放假中回过神来啊,哈哈~是不是也有小伙伴跟我一样呢?回归正题, ...
- DB2创建数据库常用参数详解
转自http://czmmiao.iteye.com/blog/1335801 DB2创建数据库常用参数详解 本文只介绍DB2 create database语法中的常用参数http://publib ...
- NFS和mount常用参数详解 本文目录
NFS和mount常用参数详解 本文目录 NFS权限参数配置 mount挂载参数 原始驱动程序的挂载选项. 新驱动程序的挂载选项. 怎样改变已经挂载的NTFS卷的权限? 怎样自动挂载一个NTFS卷 ...
随机推荐
- Daily Scrum 12-25
Meeting Minutes 针对设计师提出的问题完成了layout的微调: 讨论alpha测试反馈反映出的一些问题: 完成了代码的merge(与bing词典 1.5版本): Progress ...
- Bootstrap Validator使用特性,动态(Dynamic)添加的input的验证问题
http://1000hz.github.io/bootstrap-validator/#validator-usage Validated fields By default, the valida ...
- A KeyValuePair in Java
A KeyValuePair in Java Programming & English tuble 元组 pair 对(两)元组 tuple 三元组 dozen 一打(12个).有 ...
- Wshshell 脚本简单学习
WshShell 的简单语法 学习 同事给了一个脚本自动执行 部署命令 感觉挺好的 , 年前一直说要学习一下 但是一直没有学习(自己太懒了) 这次简单总结一下. 创建对象: Set WshShell ...
- git 快捷键
实际上就是弄了个别名 $ git config --global alias.st status $ git config --global alias.ci commit $ git config ...
- OneZero——Review报告会
1. 时间: 2016年4月20日. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http://www.cnb ...
- BatchNormalization的使用
# import BatchNormalization from keras.layers.normalization import BatchNormalization # instantiate ...
- xhtml的3種文檔聲明類型
xhtml有三種文檔聲明類型: strict:使用嚴格的標記,避免語法上的混亂: trasitional:為不支持的css的瀏覽器編寫xhtml時: frameset:利用框架將窗口分割為兩個部分或多 ...
- js數據類型
js的數據類型有:字符串.數字.布爾型.數組.undfined.null: js擁有動態類型,同樣的變量可以賦值多個類型: 變量賦值可以聲明后賦值,或者聲明時賦值: 字符串: 字符串用單引號或者雙引號 ...
- Oracle数据库导入导出 imp/exp备份还原
Oracle数据导入导出imp/exp Oracle数据导入导出imp/exp 在cmd的dos命令提示符下执行,而不是在sqlplus里面,但是格式一定要类似于: imp/exp 用户名/密 ...