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.

I'm testing whether some changes I made to some code are effective or not. For this, I need to know how the file system cache normally works. I'm assuming the default is what we're getting, since we probably haven't tweaked anything interesting regarding this.

Essentially, if from my code I ask "does this file exist?", the answer comes back in "x" milliseconds. If I ask again a few minutes later, the answer comes back much, much quicker, so I'm guessing there's some caching going on there.

How long should I wait if I want to test again, with the cache flushed, so it'll take "long" again? (I want to see if I fixed a performance problem in my web app, but I can only know that it's fixed if the info about files existence isn't cached, because if it is, it does run fast)

I know this is not the most eloquent question, and the answer is probably "it depends", I'm asking for a sane default. In other words, if I test again in 3 hours, or 6, or whatever, can I count on it not being cached?

As far as I can tell... This is a Ubuntu server, kernel version: 3.9.3-x86-linode52, Ubuntu version: Ubuntu 12.04.3 LTS, hosted on Linode. The file system is ext3

Thank you!
Daniel

share|improve this question
1  
You can just force a cache flush: stackoverflow.com/questions/2384202/… –  tmo Aug 22 '13 at 20:33
    
Is running the command "sync" the way to flush the cache? Because if it is, that doesn't seem to be doing it for me. I don't need to flush pending writes to HDD, I need to kill the cache that makes it unnecessary to "read" from the HDD –  Daniel Magliola Aug 22 '13 at 20:43

1 Answer 1

up vote 7 down vote accepted

What you're probably running into is inode caching, since exists queries can be satisfied just by looking at the inode. File-caching is a bit different. Happily, linux does provide you a way to drop that cache through the drop_caches mechanism exposed in /proc/sys/vm/dropcaches.

To free dentries and inodes:
    echo 2 > /proc/sys/vm/drop_caches
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.