使用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

參考資料:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章