Pages

Tuesday, October 5, 2010

How to Clear filesystem memory cache

he linux Kernels 2.6.16 and Newer kernels provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory.

You have to first check the memory usage with command

#free -m

To use /proc/sys/vm/drop_caches, Now echo a number to it.

To free pagecache:
# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:
# echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:
# echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, run sync first!
sync; echo 3 > /proc/sys/vm/drop_caches

How the command works :

root@sserver # free -m
total used free shared buffers cached
Mem: 12174 7824 4349 0 414 5953
-/+ buffers/cache: 1456 10718
Swap: 24003 241 23761

root@server # sync; echo 3 > /proc/sys/vm/drop_caches

root@server # free -m
total used free shared buffers cached
Mem: 12174 1684 10489 0 9 125
-/+ buffers/cache: 1549 10624
Swap: 24003 241 23761


No comments: