参考:Linux cache占用大量内存,如何分析是哪些进程、文件导致?
查看cache工具
工具 | fincore | pcstat | hcache | vmtouch |
---|---|---|---|---|
说明 | 该工具最初发布于googlecode,但googlecode现在已经关闭了。可以从github上找到其代码。 | 很多工具基于该工具二次开发 | 基于pcstat二次开发 | 功能多 |
代码 | https://github.com/waleedmazhar/linux-ftools | https://github.com/tobert/pcstat | https://github.com/silenceshell/hcache | https://github.com/hoytech/vmtouch |
查询进程关联文件 cache | x | ✓ | ✓ | x |
统计文件cache总和 | x | x | ✓ | ✓ |
将文件载入cache | x | x | x | ✓ |
将文件cache锁住在内存(不被换出到磁盘) | x | x | x | ✓ |
将文件从cache中清除 | x | x | x | ✓ |
查询全局最大缓存文件 | x | x | ✓ | x |
docker内运行获取容器内文件cache | 未试验 | ✓ | ✓ | 容器内运行只能查宿主机的文件的cache |
vmtouch
# ./vmtouch
./vmtouch: no files or directories specifiedvmtouch v1.3.1 - the Virtual Memory Toucher by Doug Hoyte
Portable file system cache diagnostics and controlUsage: vmtouch [OPTIONS] ... FILES OR DIRECTORIES ...Options:-t touch pages into memory-e evict pages from memory-l lock pages in physical memory with mlock(2)-L lock pages in physical memory with mlockall(2)-d daemon mode-m <size> max file size to touch-p <range> use the specified portion instead of the entire file-f follow symbolic links-F don't crawl different filesystems-h also count hardlinked copies-i <pattern> ignores files and directories that match this pattern-I <pattern> only process files that match this pattern-b <list file> get files or directories from the list file-0 in batch mode (-b) separate paths with NUL byte instead of newline-w wait until all pages are locked (only useful together with -d)-P <pidfile> write a pidfile (only useful together with -l or -L)-o <type> output in machine friendly format. 'kv' for key=value pairs.-v verbose-q quiet
# ./vmtouch test.binFiles: 1Directories: 0Resident Pages: 109159/109159 426M/426M 100%Elapsed: 0.069863 seconds
# echo 3 > /proc/sys/vm/drop_caches
# ./vmtouch test.bin Files: 1Directories: 0Resident Pages: 0/109159 0/426M 0%Elapsed: 0.01347 seconds
continue…