free 输出解读

  • total 内存总数
  • used 使用内存
  • free 未使用内存
  • shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)
  • buffers Memory used by kernel buffers (Buffers in /proc/meminfo)
  • cached Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
  • available 可用内存

Ubuntu / CentOS 7

[root@localhost ~]# LANGUAGE=en free
              total        used        free      shared  buff/cache   available
Mem:        4039180     2708092      152012       40528     1179076     1044600
Swap:       2097148      119040     1978108
[root@localhost ~]# LANGUAGE=en free -w
              total        used        free      shared     buffers       cache   available
Mem:        4039180     2708092      152012       40528      108088     1070988     1044600
Swap:       2097148      119040     1978108

total = used + free + buff/cache
buff/cache = buffers + cache
available = free + buff/cache - 不可释放部分

CentOS 6

[root@localhost ~]# free -o
             total       used       free     shared    buffers     cached
Mem:        955272     863332      91940          0     321012     190408
Swap:       524280     110180     414100
[root@localhost ~]# free
             total       used       free     shared    buffers     cached
Mem:        955272     863332      91940          0     321012     190408
-/+ buffers/cache:     351912     603360
Swap:       524280     110180     414100

total = used + free

PS:第一行 buff/cache 算成 used,第二行(-/+ buffers/cache)buff/cache 算成 free。

[root@localhost ~]# python
Python 3.6.5 (default, Apr  1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> sum([int(i) for i in '91940          0     321012     190408'.split(' ') if i])
603360

参考