#free -h
? ? ? ? ? ? ? total? ? ? ? used? ? ? ? free? ? ? shared? buff/cache? available
Mem:? ? ? ? ? ? 15G? ? ? ? 10G? ? ? ? 2.3G? ? ? ? 1.9G? ? ? ? 2.8G? ? ? ? 2.7G
Swap:? ? ? ? ? 7.7G? ? ? ? 289M? ? ? ? 7.5G
total = used + free + buff/cache
available = free + buff/cache(部分)
el7中free的available其實對應:cat /proc/meminfo? | grep MemAvailable
buff: 寫 IO 緩存
cache: 讀 IO 緩存
測試 buff/cache 和 available 關系:
1. 用 dd 命令生成一個1G的大文件
# ddif=/dev/zero of=bigfile bs=1M count=1000
2. 用 watch 命令監(jiān)控內存變化
# watch 'free -h'
3. 測試前清空緩存, buff/cache值會變小
# echo 3 > /proc/sys/vm/drop_caches
4. 首次讀取文件继准,測試消耗的時間
# time cat bigfile >/dev/null
real 0m5.785s
user 0m0.021s
sys 0m0.668s
5. 再次讀取該文件握童,發(fā)現(xiàn)消耗的時間少了很多果善,讀取速度提高了30多倍
# time cat bigfile >/dev/null
real 0m0.176s
user 0m0.012s
sys 0m0.161s
6. 此時再清空緩存,cache/buffer 減少了1000M惶看; 再讀取文件時間將恢復到未緩存的時間(參見步驟4)
reference: https://www.cnblogs.com/muahao/p/6401350.html