Thursday 10 July 2014

How To Clear Memory Cache In Linux

Clearning the Linux Memory cache can be a quick way to regain system resources. Writing to the drop_cache process will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.


 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, the user should run "sync" first in order to make sure all cached objects are freed.

Example - Memory before:


[root@server ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3259       2288        970          0        120        828
-/+ buffers/cache:       1340       1919
Swap:         6206          0       6206
[root@server ~]# sync
[root@server ~]# echo 3 > /proc/sys/vm/drop_caches

Example - Memory before:
[root@server ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3259       1563       1696          0          2        281
-/+ buffers/cache:       1279       1980
Swap:         6206          0       6206



Enjoy the tricksss............. Have fun !!!!!!!!!!!!!!!!!!!!







No comments:

Post a Comment