使用Free命令查看Linux服务器内存使用状况(-/+ buffers/cache详解)
free命令可选参数
- -b,-k,-m,-g show output in bytes, KB, MB, or GB
- -h human readable output (automatic unit scaling)
- -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
- -a show available memory if exported by kernel (>80 characters per line)
- -V display version information and exit
常用参数演示
[root@ ~]# free -b #以Byte为单位显示
total used free shared buffers cached
Mem: 1044611072 552603648 492007424 57344 39006208 124108800
-/+ buffers/cache: 389488640 655122432
Swap: 1572855808 245936128 1326919680
[root@ ~]# free -k #以KB为单位显示
total used free shared buffers cached
Mem: 1020128 536520 483608 56 38108 121200
-/+ buffers/cache: 377212 642916
Swap: 1535992 240172 1295820
[root@ ~]# free -m #以MB为单位显示
total used free shared buffers cached
Mem: 996 523 472 0 37 118
-/+ buffers/cache: 368 627
Swap: 1499 234 1265 [root@ ~]# free -h #人性化输出显示
total used free shared buffers cached
Mem: 996M 521M 474M 56K 35M 118M
-/+ buffers/cache: 368M 628M
Swap: 1.5G 234M 1.2G [root@ ~]# free -o #不显示-/+buffers/cache line,不建议
total used free shared buffers cached
Mem: 1020128 536892 483236 56 38468 121284
Swap: 1535992 240172 1295820 [root@ ~]# free -th #算上swap
total used free shared buffers cached
Mem: 996M 524M 471M 56K 37M 118M
-/+ buffers/cache: 368M 627M
Swap: 1.5G 234M 1.2G
Total: 2.4G 758M 1.7G [root@ ~]# time free -s 1 -c 3 #表示持续每隔1s更新更新一次mem信息,更新3次
total used free shared buffers cached
Mem: 1020128 537512 482616 56 38868 121328
-/+ buffers/cache: 377316 642812
Swap: 1535992 240172 1295820 total used free shared buffers cached
Mem: 1020128 537512 482616 56 38868 121328
-/+ buffers/cache: 377316 642812
Swap: 1535992 240172 1295820 total used free shared buffers cached
Mem: 1020128 537512 482616 56 38868 121328
-/+ buffers/cache: 377316 642812
Swap: 1535992 240172 1295820 real 0m2.002s
user 0m0.000s
sys 0m0.001s
[root@ ~]#
free 命令输出结果信息说明
total used free shared buffers cached
Mem: 996M 525M 470M 56K 38M 118M
-/+ buffers/cache: 368M 627M
Swap: 1.5G 234M 1.2G
第一行
- total: 内存总数
- used: 已经使用内存数
- free: 完全空闲内存
- shared: 多个进程共享的内存
- buffers: 用于块设备数据缓冲,记录文件系统metadata(目录,权限,属性等)
- cached: 用于文件内容的缓冲
第一列
- Mem: 物理内存
- -/+ buffers/cache: 基于应用角度考虑(计算已使用内存时减去buffers/cache,计算可使用内存时加上buffers/cache)的内存情况,也可理解为真实的内存使用情况.
- Swap: 交换分区
当我们获取系统内存用量的时候我们应该以“-/+ buffers/cached”行的used和free作为参考.因为第一行的buffers和cached被系统作为了缓存(这里包括缓冲了metadata数据和曾经打开过的内容,是为了加快我们系统处理的速度),而这部分缓存可以根据我们的应用内存使用情况随时释放掉(也可以手动释放).
这里的话我系统可用内存实际为:可用627M,已使用368M,而不是525M和470M.
buffers/cahed手动释放测试
释放前
[root@ ~]# free -h
total used free shared buffers cached
Mem: 996M 531M 465M 56K 42M 119M
-/+ buffers/cache: 369M 626M
Swap: .5G 234M .2G
[root@ ~]#
使用命令手动释放
[root@ ~]# echo 3 > /proc/sys/vm/drop_caches
[root@ ~]# free -h
total used free shared buffers cached
Mem: 996M 391M 604M 56K 420K 26M
-/+ buffers/cache: 364M 631M
Swap: .5G 234M .2G
[root@ ~]#
手动释放后我们看到 第一行Mem的used和free有了很大的提升,我们上述的观点得到了验证
使用find 命令让buffers增加
[root@ backup]# free -h;find .>/dev/null;free -h
total used free shared buffers cached
Mem: 996M 397M 598M 56K 2.6M 32M
-/+ buffers/cache: 362M 633M
Swap: .5G 234M .2G
total used free shared buffers cached
Mem: 996M 415M 581M 56K 17M 32M
-/+ buffers/cache: 364M 631M
Swap: .5G 234M .2G
[root@ backup]#
使用cat 命令让cached增加
[root@zwj python]# free -h;find /mydata/backup/python/ -type f|xargs cat>/dev/null 2>&1;free -h
total used free shared buffers cached
Mem: 996M 434M 561M 56K 18M 50M
-/+ buffers/cache: 365M 630M
Swap: .5G 234M .2G
total used free shared buffers cached
Mem: 996M 767M 228M 56K 20M 367M
-/+ buffers/cache: 379M 617M
Swap: .5G 234M .2G
Done!!!
使用Free命令查看Linux服务器内存使用状况(-/+ buffers/cache详解)的更多相关文章
- 如何使用Linux命令行查看Linux服务器内存使用情况?
一个服务器,最重要的资源之一就是内存,内存够不够用,是直接关系到系统性能的关键所在. 本文介绍如何查看Linux服务器内存使用情况, 1.free命令 free -m [root@localhost ...
- 查看Linux服务器内存使用情况
一个服务器,最重要的资源之一就是内存,内存够不够用,是直接关系到系统性能的关键所在. 本文介绍如何查看Linux服务器内存使用情况, 1.free命令 free -m [root@localhost ...
- 如何查看linux服务器内存使用情况
1. free命令 free 命令显示系统使用和空闲的内存情况,包括物理内存.交互区内存(swap)和内核缓冲区内存. 直接输入free命令,显示如下 free命令默认是显示单位kb,可以采用fr ...
- 查看linux服务器内存信息
查看服务器内存信息 dmidecode|grep -P -A5 "Memory\s+Device"|grep Size [root@localhost home]# dmideco ...
- Linux服务器access_log日志分析及配置详解(二)
默认nginx / Linux日志在哪个文件夹? 一般在 xxx.xxx.xxxx.com/home/admin 路径下面的error.log文件和access.log文件error_log logs ...
- Linux服务器access_log日志分析及配置详解(一)
nginx的log日志分为access log 和 error log 其中access log 记录了哪些用户,哪些页面以及用户浏览器.ip和其他的访问信息 error log 则是记录服务器错误日 ...
- 全面了解 Linux 服务器 - 2. 查看 Linux 服务器的内存使用情况
2. 查看 Linux 服务器的内存使用情况 liuqian@ubuntu:~$ free -m total used free shared buffers cached Mem: 1983 186 ...
- Linux 服务器的网络配置 - 2. 查看 Linux 服务器的进程
2. 查看 Linux 服务器的进程 1)ps [主要选项] -a 显示系统中所有进程的信息 -e 显示所有进程的信息 -f 显示进行的所有信息 -l 以长格式显示进程信息 -r 只显示正 ...
- 使用 dmidecode 查看Linux服务器信息
使用 dmidecode 查看Linux服务器信息 来源 http://www.laozuo.org/6682.html 对于大部分普通服务器用户来说,我们选择VPS.服务器产品的时候比较关心的是产 ...
随机推荐
- mybatis的foreach写用法
一.mybatis查询 public abstract List<Model> findByIds(@Param("ids")List<Integer> i ...
- VirtualBox错误ID: PAEmode解决
今天在导入virtualbox的虚拟机ubuntu系统时,报错,无法打开虚拟机 报错内容如下: 错误 ID: PAEmode 严重: 致命错误 The guest is trying to switc ...
- js删除数组中某一项,splice()
' ","childTagName":"高中"}, {","childTagName":"初中"}] ...
- python web框架 推荐
Flask 很轻,花很少的成本就能够开发一个简单的网站.非常适合初学者学习. 学会以后,可以考虑学习插件的使用,用 SQLAlchemy + Flask-SQLAlchemy 来对你的数据库进行控制. ...
- Batch Normailzation
转自:http://blog.csdn.net/malefactor/article/details/51476961
- 转载:ResNeXt算法详解
原文连接:http://blog.csdn.net/u014380165/article/details/71667916, 大神"AI之路”有很多经典的总结,推荐前往.. 论文:Agg ...
- LNK2005 _DllMain@12 mfcs100d.lib
起因是将之前使用 MFC 规则 DLL 的动态库都改为了 MFC 扩展 DLL,在将动态库中从 CWinApp 继承的类替换为 DllMain 函数后,就出现 LNK2005 错误,说 DllMain ...
- 简述synchronized和java.util.concurrent.locks.Lock异同
主要相同点:Lock能完成synchronized所实现的所有功能.主要不同点:Lock有比synchronized更精确的线程语义和更好的性能.syncronized会自动释放锁,而Lock一定要程 ...
- 编写高质量代码--改善python程序的建议(四)
原文发表在我的博客主页,转载请注明出处! 建议十八:有节制的使用from...import语句 python提供了三种方式引入外部模块: import语句 from...import... __imp ...
- Mininet加强版——DOT(分布式OpenFlow试验平台)
前言 之前在做SDN实验的时候,需要用到包含2000+个交换机的fattree拓扑,当时用的是mininet,生成整个拓扑需要十五六个小时,最终在异常艰苦的环境下做完了实验,之后听说了有DOT(Dis ...