Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
I don't know the answer but 2 things are of interest: How do you flush the caches? Why is that of interest, I'm not implying anything here - just interested in the use case –  Server Horror Jun 8 '11 at 20:05
1  
This flushes both the buffers and cached: sysctl -w vm.drop_caches=3. You might want to read more on it, before using. Sometimes its just needed. Its available - this should be another reason :) –  ssapkota Jun 8 '11 at 20:07
    
A lot of people are asking for it. There should be some reason. –  ssapkota Jun 8 '11 at 20:18
    
dropping caches comes handy if you want to do some I/O related performance measurements and do not want to have them "spoiled" by O/S caching –  the-wabbit Jun 9 '11 at 8:22

2 Answers 2

up vote 10 down vote accepted

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.

share|improve this answer
    
Thanks, I will look into it. –  ssapkota Jun 9 '11 at 8:33
    
This is some seriously awesome sauce. Thanks! –  Cobra_Fast Jan 22 '13 at 13:35
    
fincore does inform if a file is present in cache or not. However, is there any tool which will list all the files that are cached (fincore takes the file name as input and searches. I want to look into all the entries that are currently cached) –  Joe Nov 12 at 9:06
    
@Joe I suppose that 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 doing the reverse - getting a file name belonging to a data block would require reading all inodes and indirect blocks on the file system. Thus, algorithmically you will be better off supplying a list of all files on your file system to fincore if you really need this level of information. –  the-wabbit Nov 12 at 11:45
    
@the-wabbit Thanks. Other than files, are there other things that are part of cache, such as descriptors, shared memory etc. –  Joe Nov 12 at 15:43

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.

[root@xt ~]# vmtouch -v /usr/local/var/orca/procallator.cfg
/usr/local/var/orca/procallator.cfg
[     ] 0/5

           Files: 1
     Directories: 0
  Resident Pages: 0/5  0/20K  0%
         Elapsed: 0.000215 seconds

Now I can "touch" it into cache.

[root@xt ~]# vmtouch -vt /usr/local/var/orca/procallator.cfg
/usr/local/var/orca/procallator.cfg
[OOOOO] 5/5

           Files: 1
     Directories: 0
   Touched Pages: 5 (20K)
         Elapsed: 0.005313 seconds

Now to see how much is cached...

[root@xt ~]# vmtouch -v /usr/local/var/orca/procallator.cfg
/usr/local/var/orca/procallator.cfg
[OOOOO] 5/5

           Files: 1
     Directories: 0
  Resident Pages: 5/5  20K/20K  100%
         Elapsed: 0.000241 seconds
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.