CentOS 6及以前

$ free
total used free shared buffers cached
Mem: 4040360 4012200 28160 0 176628 3571348
-/+ buffers/cache: 264224 3776136
Swap: 4200956 12184 4188772
$
内存的使用分作4部分:
  • A. 程序使用的;
  • B. 未被分配的;
  • C. Buffers (buffer cache)
  • D. Cached (page cache)
显然,A (程序使用的) 肯定是used,B (未被分配的) 肯定是free。但是,C (Buffers) 和 D (Cached) 是算作used还是算作free呢?一方面,它们已经被分配了,可以算作used;另一方面,当程序需要时,可以回收它们来使用,可以算作free。所以,怎么算都合理。这就是在free命令的output中,第一行和第二行的区别
  • 第一行(Mem):Buffers和Cached被算作used。也就是说,它的free是指 B (未被分配的);它的used是指 A + C + D;
  • 第二行(-/+ buffers/cache):Buffers和Cached被算作free。也就是说,它的used是指 A (程序使用的);它的free是指 B + C + D;行名称“-/+ buffers/cache”的含义就是“把Buffers和Cached从used减下来,加到free里”。
搞清这些之后,我们可以算出A,B,C和D各自的值:
  • A=264224
  • B=28160
  • C=176628
  • D=3571348
可见验证一下:
  • total=A + B + C + D
  • 第一行used = A + C + D
  • 第二行free  = B + C + D

CentOS 7

free命令的out:
              total        used        free      shared  buff/cache   available
Mem: 1012952 252740 158732 11108 601480 543584
Swap: 1048572 5380 1043192
 
首先,C (Buffers) 和D (Cached)被和到一起,即buff/cache;
其次,used就是指A (程序使用的);free就是指B (未被分配的);
另外,CentOS 7中加入了一个available,它是什么呢?手册上是这么说的:
 
  • MemAvailable: An estimate of how much memory is available for starting new applications, without swapping.

前面说过,当程序需要时,可以回收C (Buffers)和D (Cached),那么MemAvailabe不就是B+C+D吗?当程序需要时可以回收C和D,这句话以前是正确,但是现在就不精确了:因为, 现在,C和D中不是所有的内存都可以被回收。所以,大致可以这么理解,MemAvailable = B (未被分配的) + C (Buffers) + D (Cached) - 不可回收的部分。哪些不可回收呢?共享内存段,tmpfs,ramfs等。详细的介绍如下:

 
/proc/meminfo: provide estimated available memory
Many load balancing and workload placing programs check /proc/meminfo to estimate how much free memory
is available. They generally do this by adding up "free" and "cached", which was fine ten years
ago,
but is pretty much guaranteed to be wrong today.
It is wrong because Cached includes memory that is not freeable as page cache, for example shared
memory
segments, tmpfs, and ramfs, and it do esnot include reclaimable slab memory, which can take up
a large
fraction of system memory on mostly idle systems with lots of files.
Currently, the amount of memory that is available for a new workload,without pushing the system
into swap,
can be estimated from MemFree, Active(file), Inactive(file), and SReclaimable, as well as the
"low"watermarks
from /proc/zoneinfo.
However, this may change in the future, and user space really should not be expected to know kernel
internals
to come up with an estimate for the amount of free memory.
It is more convenient to provide such an estimate in /proc/meminfo. If things change in the future,
we only
have to change it in one place.

最新文章

  1. Redis命令拾遗五(有序集合)
  2. printf(),类型修饰符
  3. DataGridView in TabControl and CellValidating lead to problems
  4. JavaWeb---总结(九)通过Servlet生成验证码图片
  5. android实现通过浏览器点击链接打开本地应用(APP)并拿到浏览器传递的数据
  6. HDU 4122
  7. POJ 1155 TELE 背包型树形DP 经典题
  8. 【笨嘴拙舌WINDOWS】Dj,oh!nonono,It is about DC
  9. Web 网页常见问题集锦
  10. jQuery CSS 的操作函数
  11. Oauth支持的5类 grant_type 及说明
  12. 让Solr返回JSON数据
  13. 简单制作 OS X Yosemite 10.10 正式版U盘USB启动安装盘方法教程 (全新安装 Mac 系统)
  14. Mysql 5.6到5.7的mysql.user改变
  15. mysql数据库的基本操作:索引、视图,导入和导出,备份和恢复
  16. FFmpeg 结构体学习(五): AVCodec 分析
  17. HDU 3518 Boring counting
  18. 11076: 小P的集合 位运算
  19. 拿什么守护你的Node.JS进程: Node出错崩溃了怎么办?
  20. 开发微信小程序——古龙小说阅读器

热门文章

  1. PhpAdmin支持登录远程数据库服务器
  2. calibre的注册表残留删除
  3. mysql 将行拼接成字符串的方法
  4. # 20175227 2018-2019-2 《Java程序设计》第一周学习总结
  5. 刘志梅 201771010115 《面向对象程序设计(java)》 第八周学习总结
  6. CSS的background
  7. 红外NEC协议
  8. 经典技术之URL
  9. python——数字问题之_ 变量
  10. leetcode101