Thursday, July 3, 2014

How To Clear Memory Cache in Linux

3:02 PM

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@linuxstorages ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3763       3630        132          0       1374        147
-/+ buffers/cache:       2108       1655
Swap:         4095         22       4073


[root@linuxstorages ~]# sync


[root@linuxstorages ~]# echo 3 > /proc/sys/vm/drop_caches

Memory after:

[root@linuxstorages ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3763       1083       2680          0          2         84
-/+ buffers/cache:        996       2767
Swap:         4095         22       4073

Written by

0 comments :

Post a Comment

 

© 2014 Linux Storages | Updated . All rights resevered. Designed by Templateism