使用linux-fincore查看Linux系统缓存哪些文件

概述

  • linux-fincore 包含linux-fincore,linux-fincore,linux-fincore 三个工具。其中linux-fincore可以用来查看cache中有哪些文件。

编译安装

  • 该工具最初发布于googlecode,但googlecode现在已经关闭了。可以从github上找到其代码。
  • 本人选用的是 https://github.com/waleedmazhar/linux-ftools 这个链接的版本, 执行 ./configure; make; make install 可以直接编译安装。
  • 如果因选择版本以及编译环境差异,执行make时可能会报错: 例如aclocal-1.10: command not foundautomake-1.10: command not found
cd . && /bin/sh /home/linux-ftools-master/missing --run aclocal-1.10 
/home/linux-ftools-master/missing: line 54: aclocal-1.10: command not found
WARNING: `aclocal-1.10' is missing on your system.  You should only need it if
         you modified `acinclude.m4' or `configure.ac'.  You might want
         to install the `Automake' and `Perl' packages.  Grab them from
         any GNU archive site.
 cd . && /bin/sh /home/linux-ftools-master/missing --run automake-1.10 --gnu 
/home/linux-ftools-master/missing: line 54: automake-1.10: command not found
WARNING: `automake-1.10' is missing on your system.  You should only need it if
         you modified `Makefile.am', `acinclude.m4' or `configure.ac'.
         You might want to install the `Automake' and `Perl' packages.
         Grab them from any GNU archive site.
cd . && /bin/sh /home/linux-ftools-master/missing --run autoconf
configure.ac:7: error: possibly undefined macro: AM_INIT_AUTOMAKE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
make: *** [configure] Error 1
  • 对于类似错误,网上一般会说要安装automake对应版本之类的。但实际上,服务器上已经有更高版本的automake工具。这其实是因为Makefile.in中写死了使用低版本的automake工具导致的,可以通过以下步骤解决:

    1. 执行aclocal,产生aclocal.m4文件
    2. 执行autoconf,生成configure文件
    3. 执行automake命令,产生Makefile.in: automake --add-missing
    4. 执行configure命令,生成Makefile文件
    5. 重新执行makemake install,一切顺利.

    使用说明

    • help信息如下:
[root]# /usr/local/bin/linux-fincore 
fincore version 1.3.0
fincore [options] files...

  -s --summarize          When comparing multiple files, print a summary report
  -p --pages              Print pages that are cached
  -o --only-cached        Only print stats for files that are actually in cache.
  -g --graph              Print a visual graph of each file's cached page distribution.
  -S --min-size           Require that each files size be larger than N bytes.
  -C --min-cached-size    Require that each files cached size be larger than N bytes.
  -P --min-perc-cached    Require percentage of a file that must be cached.
  -h --help               Print this message.
  -L --vertical           Print the output of this script vertically.
  • 通常用法:执行 linux-fincore --pages=false --summarize --only-cached * 即可,其中*代表查看任意文件的cache。也可以指定某个目录/*,表示该目录中的所有文件。或指定某个具体的文件。
  • 实例:
[root]#./linux-fincore  --pages=false --summarize --only-cached  *
filename                                                                                       size        total_pages    min_cached page       cached_pages        cached_size        cached_perc
--------                                                                                       ----        -----------    ---------------       ------------        -----------        -----------
aclocal.m4                                                                                   34,611                  9                  0                  9             36,864             100.00
Could not mmap file: autom4te.cache: No such device
config.log                                                                                   19,768                  5                  0                  5             20,480             100.00
config.status                                                                                29,788                  8                  0                  8             32,768             100.00
configure                                                                                   171,672                 42                  0                 42            172,032             100.00
configure.ac                                                                                    864                  1                  0                  1              4,096             100.00
Could not mmap file: debian: No such device
depcomp                                                                                      17,574                  5                  0                  5             20,480             100.00
INSTALL                                                                                       9,416                  3                  0                  3             12,288             100.00
install-sh                                                                                   13,184                  4                  0                  4             16,384             100.00
linux-fadvise                                                                                22,466                  6                  0                  6             24,576             100.00
linux-fadvise.c                                                                               4,875                  2                  0                  2              8,192             100.00
linux-fadvise.o                                                                              26,544                  7                  0                  7             28,672             100.00
linux-fallocate                                                                              19,150                  5                  0                  5             20,480             100.00
linux-fallocate.c                                                                             3,252                  1                  0                  1              4,096             100.00
linux-fallocate.o                                                                            17,952                  5                  0                  5             20,480             100.00
linux-fincore                                                                                42,137                 11                  0                 11             45,056             100.00
linux-fincore.c                                                                              14,967                  4                  0                  4             16,384             100.00
linux-fincore.o                                                                              67,592                 17                  0                 17             69,632             100.00
linux-ftools.h                                                                                   83                  1                  0                  1              4,096             100.00
Makefile                                                                                     20,772                  6                  0                  6             24,576             100.00
Makefile.am                                                                                     209                  1                  0                  1              4,096             100.00
Makefile.in                                                                                  20,055                  5                  0                  5             20,480             100.00
missing                                                                                      11,135                  3                  0                  3             12,288             100.00
NEWS                                                                                             65                  1                  0                  1              4,096             100.00
README                                                                                        6,001                  2                  0                  2              8,192             100.00
RELEASE                                                                                         372                  1                  0                  1              4,096             100.00
showrlimit.c                                                                                  1,961                  1                  0                  1              4,096             100.00
waste_memory.c                                                                                  699                  1                  0                  1              4,096             100.00
---
total cached size: 643,072

遇到问题

  • 实测发现,直接执行 linux-fincore --pages=false --summarize --only-cached * 有时并不能完全显示所有的缓存。比如:
    • 在测试中构造一个32GB大小的文本文件file1.csv,然后wc -l file1.csv,
    • 执行完毕后通过free可以看到系统cache已经有30多GB了,但执行上述linux-fincore命令却找不到file1.csv的cache记录(没有仔细分析其源码,不太清楚是什么原因)
  • 但是直接指定file1.csv文件名或其目录的话,是可以看到具体的缓存信息的:
[root]# ./linux-fincore  --pages=false --summarize --only-cached /home/cache_test/file1.csv 
filename                                                                                       size        total_pages    min_cached page       cached_pages        cached_size        cached_perc
--------                                                                                       ----        -----------    ---------------       ------------        -----------        -----------
/home/cache_test/file1.csv                                                       33,792,286,436          8,250,070                  0          6,802,594     27,863,425,024              82.45
---
total cached size: 27,863,425,024

参考资料:

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页