Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
You can just force a cache flush:… – 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
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


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.