how to totally clear the filesytem's cache on linux?

18,387

(it actually drops so..) run sync first, then

free pagecache:

echo 1 > /proc/sys/vm/drop_caches

free dentries and inodes:

echo 2 > /proc/sys/vm/drop_caches

free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

Then you can start with a clean cache, but of course caching will still work.

Share:
18,387

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    In a performance test, I want to bypass the influence of cache of linux system (including page cache/inode cache and so on).

    I have tried O_DIRECT flag, but it's turned out that direct I/O is still "enjoy" the effect of some cache.

    Is there a thorough way to close the effect of system cache?

  • Aceofgods
    Aceofgods almost 13 years
    @tom_cat: You need a kernel newer than 2.6.16, and Ubuntu 10.04 came with 2.6.32 if I am not mistaken, so this should work. I've just checked my 11.04 install for what it's worth, which does have this proc entry (unluckily no 10.04 here any more)
  • Aceofgods
    Aceofgods almost 13 years
    @Damon: Yeah,you are right. thanks so much. I have found that I had logged on a remote machine of older kernel.