问题 如何判断文件是否在linux中缓存在内存中?


基本上我的问题是,有没有人知道检查的实用程序 缓冲区缓存 在linux中?


9857
2017-10-17 01:16


起源

linux内核不缓存文件,它缓存块。一个文件可能包含许多块,其中一些可能被缓存,一些可能没有。你想要完成什么? - Robert Gamble


答案:


看一眼 Linux的ftools。这套工具专门用于分析缓冲区和缓存。它包括以下工具:

  • fincore
  • fadvise
  • fallocate

在这三个工具中,将显示缓冲区和缓存中的文件列表的工具是 fincore

$ fincore [options] files...

  --pages=false      Do not print pages
  --summarize        When comparing multiple files, print a summary report
  --only-cached      Only print stats for files that are actually in cache.

root@xxxxxx:/var/lib/mysql/blogindex# fincore --pages=false --summarize --only-cached * 
stats for CLUSTER_LOG_2010_05_21.MYI: file size=93840384 , total pages=22910 , cached pages=1 , cached size=4096, cached perc=0.004365 
stats for CLUSTER_LOG_2010_05_22.MYI: file size=417792 , total pages=102 , cached pages=1 , cached size=4096, cached perc=0.980392 
stats for CLUSTER_LOG_2010_05_23.MYI: file size=826368 , total pages=201 , cached pages=1 , cached size=4096, cached perc=0.497512 
stats for CLUSTER_LOG_2010_05_24.MYI: file size=192512 , total pages=47 , cached pages=1 , cached size=4096, cached perc=2.127660 
...

9
2017-08-23 09:05



不幸的是,默认情况下这些工具在大多数Linux发行版中都不可用(我检查过Ubuntu和SuSE,我手头没有redhat)。 - guettli


我不确定你是否在问我认为你在问什么,但是 vmtouch 可能对你有所帮助。只需输入 vmtouch [file or folder you want to check for presence in cache]


1
2017-11-11 08:12