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.

centos free详解的更多相关文章

  1. centos LVM详解

    title: centos LVM详解 date: 2018-04-24 14:00:03 tags: [linux,centos,LVM] --- 知识了解 LVM关系图 fdisk命令详解 [ro ...

  2. (转)CentOS分区操作详解

    CentOS分区操作详解 原文:http://blog.csdn.net/yonggeit/article/details/77924393 磁盘分区 分区格式的两种选择:MBR和GPT 分区命令: ...

  3. Vmware12安装centos系统详解

    vmware12安装centos7系统详解 用虚拟机12安装centos7系统详细安装过程,后附centos7下载地址. 工具/原料 虚拟机12 centos7系统镜像 方法/步骤 1 1.百度搜索c ...

  4. Linux学习之CentOS(八)----详解文件的搜寻、查找(转)

    which (寻找『运行档』) [root@www ~]# which [-a] command 选项或参数: -a :将所有由 PATH 目录中可以找到的命令均列出,而不止第一个被找到的命令名称 分 ...

  5. CentOS 6.5自动化运维之基于DHCP和TFTP服务的PXE自动化安装centos操作系统详解

    前言    如果要给很多台客户端主机安装操作系统,要是每一台都拿张安装光盘一台一台主机的去装系统那就太浪费时间和精力了.在生产环境中也不实际,要实现为多台主机自动安装操作系统,那我们怎么实现自动化安装 ...

  6. centos crontab详解

    1.crontab安装 [root@CentOS ~]# yum install vixie-cron [root@CentOS ~]# yum install crontabs 说明:vixie-c ...

  7. CentOS 6.3下Samba服务器的安装与配置方法(图文详解)

    这篇文章主要介绍了CentOS 6.3下Samba服务器的安装与配置方法(图文详解),需要的朋友可以参考下   一.简介  Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件, ...

  8. 【转】centos关机与重启命令详解

    连接:http://blog.csdn.net/jiangzhengdong/article/details/8036594 Linux centos关机与重启命令详解与实战 Linux centos ...

  9. centos中crontab(计时器)用法详解

    关于crontab: crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行.该 ...

随机推荐

  1. javascript mqtt 发布订阅消息

    js client使用paho-mqtt,官网地址:http://www.eclipse.org/paho/,参考http://www.eclipse.org/paho/clients/js/官网给出 ...

  2. ubuntu16.04 安装最新版nodejs

    ubuntu软件仓库中自带的nodejs版本过低 $ apt-cache policy nodejs nodejs: Installed: (none) Candidate: 4.2.6~dfsg-1 ...

  3. C/C++中的volatile简单描述

    首先引入一篇博客: 1. 为什么用volatile? C/C++ 中的 volatile 关键字和 const 对应,用来修饰变量,通常用于建立语言级别的 memory barrier.这是 BS 在 ...

  4. CSS之checkbox&radio&textarea&select

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Hive环境的安装

    hive是什么:hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能(HQL) hive有什么用 1.通过类SQL语句快速实现简单的Map ...

  6. java的String的乱码浅析

    Java又乱码了,怎么办:乱码了说明编码与解码不一致导致.所以使用统一的编码方式即可. 本文并不是一定能解决乱码,本文主要用来了解jvm默认编码,以及string编码与解码一致性问题. jvm的默认编 ...

  7. django补充和form组件

    Model常用操作: - 参数:filter - all,values,values_list [obj(id,name,pwd,email),obj(id,name,pwd,email),] mod ...

  8. 保存数据到Excel中

    调用的方法传值 Export(dt, "Cal_Report_" + DateTime.Now.ToString("yyyyMMddhhmmss") + &qu ...

  9. vue slot

    一直觉得vue的slot比较申请,而且比较深奥,总有点不想用的感觉,事实上,在一定程度上,也真的可以完全避开slot就能把一个项目完全搭建完成. 但是随着用的次数越来越多,看到的内容也越来越多的情况, ...

  10. 关于javabean

    [javabean定义]定义:JavaBeans是Java语言中可以重复使用的软件组件,实质上是一种特殊的Java类.特点是可序列化,提供无参构造器,提供getter方法和setter方法访问对象的属 ...