CentOS7 free字段含义

###

1、字段详解

###
[root@config ~]# free -h total used free shared buff/cache available Mem: 976M 82M 69M 6.7M 824M 734M Swap: 2.0G 0B 2.0G ###总内存 total = used + free + buff/cache
#可用的内存 available
= free + buff/cache(部分)
el7中free的available其实对应: [root@config
~]# cat /proc/meminfo | grep MemAvailable MemAvailable: 751776 kB
### buff: 写 IO 缓存
### cache: 读 IO 缓存

2、测试 buff/cache 和 available 关系

2.1、用 watch 命令监控内存变化(实时监控)

[root@config ~]# watch 'free -h'
Every 2.0s: free -h                                   Fri May  7 11:23:55 2021
              total        used        free     shared  buff/cache   available
Mem:           1.8G         94M        1.5G        8.6M        181M        1.5G
Swap:          2.0G          0B        2.0G

2.2、用 dd 命令生成一个1G的大文件,并查看内存变化

#生成1G的bigfile文件
# dd if=/dev/zero of=/home/bigfile bs=1M count=1000

2.3、测试前清空缓存, buff/cache值会变小

# 清空缓存
# echo 3 > /proc/sys/vm/drop_caches
  

2.4、清除缓存后首次读取文件,测试消耗的时间,查看内存情况

# 读取文件
[root@config ~]# time cat /home/bigfile >/dev/null
real 0m0.809s
user 0m0.001s
sys 0m0.802s
  

2.5、再次读取该文件,发现消耗的时间少了很多,读取速度提高了

# 再次读取文件
[root@config ~]# time cat bigfile >/dev/null
real 0m0.131s
user 0m0.003s
sys 0m0.128s

2.6、此时再清空缓存,cache/buffer 减少了近1000M; 再读取文件时间将恢复到未缓存的时间

[root@config ~]# echo 3 > /proc/sys/vm/drop_caches
  

###

原文地址:https://www.cnblogs.com/faithH/p/14738486.html