How to clear the cache memory in Linux - Using drop_caches

Linux OS is maintaining cache for file-systems, memory pages etc to speedup the cpu process reducing the hard disk i/o. From 2.6.16 kernel a new mechanism has been introduced to have the kernel drop the pagecache, 
dentries or inodes cache which helps the administrator to throw away that script that allocated a ton of memory just to get rid of the cache.

Below is the steps we need to follow to clear the pagecache / and memory cache.

0 -> Will give the Kernel full control to the cache memory 
1 -> Will free the page cache 
2 -> Will free dentries and inodes 
3 -> Will free dentries and inodes as well as page cache

So, just enter those values to the file /proc/sys/vm/drop_caches, with echo, and as root:

sync; echo 0 > /proc/sys/vm/drop_caches

sync; echo 1 > /proc/sys/vm/drop_caches

sync; echo 2 > /proc/sys/vm/drop_caches

sync; echo 3 > /proc/sys/vm/drop_caches

Post a Comment