Here the output of free -m
:
total used free shared buffers cached
Mem: 7188 6894 294 0 249 5945
-/+ buffers/cache: 698 6489
Swap: 0 0 0
I can see almost 6GB
(5945MB) memory out of 7GB
is used in caching the files. I know how to flush the caches. My question is: Is possible see which files(or inodes) are being cached?
Well, there is an easy way to take a look at the kernel's page cache if you happen to have ftools - "fincore" gives you some summary information on what files' pages are the content of the cache.
You will need to supply a list of file names to check for their presence in the page cache. This is because the information stored in the kernel's page cache tables only will contain data block references and not filenames.
fincore
would resolve a given file's data blocks through inode data and search for respective entries in the page cache tables.There is no efficient search mechanism for doing the reverse - getting a file name belonging to a data block would require reading all inodes and indirect blocks on the file system. If you need to know about every single file's blocks stored in the page cache, you would need to supply a list of all files on your file system(s) to
fincore
. But that again is likely to spoil the measurement as a large amount of data would be read traversing the directories and getting all inodes and indirect blocks - putting them into the page cache and evicting the very page cache data you were trying to examine.You can use the vmtouch utility to see if a named file or directory is in cache. You can also use the tool to force items into cache or lock them into cache.
Now I can "touch" it into cache.
Now to see how much is cached...
You can also use pcstat (Page Cache Stat) https://github.com/tobert/pcstat
Hope it helps someone.
I write a very simple shell script to show the cached files by using of linux-fincore. Since cache is one part of memory, my code is find the top 10 RSZ usage of process, and the use lsof to find out the files that process opened, finally use linux-fincore to find out whether these files are cached or not.
Please correct me if I am thinkg wrong.
I wrote following script which prints all files and their cache status using pcstat command. It is self-contained script for x86_64 linux systems. It downloads pcstat if needed .
First argument is filesystem location to analyze and second argument is number of result (Top N by number of pages in cache).