GNU/Linux systems often cache a lot of stuff and for testing purposes I need to clear it.
Note the fact that emptying the cache does not actually mean freeing ram, the cached memory is freed instantly once more memory than available is requested.
If you have a kernel older than 2.6.12 this will not work for you, previous kernel versions do not have this feature.
We will empty dentries and inodes, page cache and both, this is done by echoing (writing) a number to /proc/sys/vm/drop_caches file.
In order to better understand what dentries and inodes are I suggest you to visit the Anatomy of the Linux virtual file system switch.
Also, it is recommended to flush the file system buffers by running the sync command before.
1. In order to clear the page cache use:
sync; echo 1 > /proc/sys/vm/drop_caches
2. If you want to free up the inodes and dentries use:
sync; echo 2 > /proc/sys/vm/drop_caches
3. And if you want to clear page cache and free up dentries and inodes use:
sync; echo 3 > /proc/sys/vm/drop_caches