欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

缓冲区/高速缓存内存优化_posix_fadvise_active_release_read_cache 高速缓存-2 问题原因

最编程 2024-10-15 07:03:16
...

原理

  • cache 读数据保存到内存,加速下次读速度
  • buffer 写缓冲区
    linux 系统为了提高下一次读取速度, 从内存cache中读取

cache加速读实例

第一次读取

dd if=/dev/zeroo of=test.img bs=1M count=512
free -h # 查看内存
total used free shared buff/cache available
Mem: 15Gi 3.7Gi 10Gi 516Mi 993Mi 11Gi
Swap: 4.0Gi 0B 4.0Gi
time grep 123 test.img
real 0m0.480s
user 0m0.138s
sys 0m0.110s

第二次读取

free -h # 查看内存, 确认cache是否增加
total used free shared buff/cache available
Mem: 15Gi 3.7Gi 10Gi 516Mi 1.5Gi 11Gi
Swap: 4.0Gi 0B 4.0Gi
time grep 123 test.img
real 0m0.163s
user 0m0.102s
sys 0m0.061s

结论:

  1. buffer/cache 由 993Mi 变为1.5Gi
  2. 第二次读取, 匹配关键字速度提升 0.480s --> 0.163s