Blog Tags: 

Invalidating the disk cache on Linux

Here's a super easy way to invalidate the disk cache, which is useful for testing IO performance in the real world, where you can't rely on all of your reads being served up from a super-fast RAM cache rather than a vastly slower physical disk drive.

This will free up everything in the disk cache:

echo 3 > /proc/sys/vm/drop_caches

Or if you want more control over exactly what is being freed...

  1. This frees up the pagecache (e.g., cache of contents of files):

    echo 1 > /proc/sys/vm/drop_caches
  2. This frees up dentries and inodes:

    echo 2 > /proc/sys/vm/drop_caches

    In a nutshell, Dentries are directory structures in memory. Inodes are the headers of files in memory. Inodes have links to page blocks, which is where the actual file data is stored.

Keep in mind you need root privileges to do this.


Faheem's picture

You can signal the Linux Kernel to drop various aspects of cached items by changing the numeric argument to the above command.



mary esther's picture

what about free pagecache dentries or inodes? i have doubt , Is clear disk cache code or pagecache are same?


Add new comment