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.

Add new comment