Wednesday, September 18, 2013

How to clear memory cache & swap space on your Linux system

If you think your Linux system has decreased performance,you can try  some workarounds such  clear the memory cache and clear the swap space.

To clear the filesystem's memory cache, run the following commands:

[root@development ~]# sync
[root@development ~]# echo 3 > /proc/sys/vm/drop_caches
[root@development ~]# echo 0 > /proc/sys/vm/drop_caches
[root@development ~]# sync



To clear the swap space, run the following command:

[root@development ~]# swapoff -a && swapon -a


For daily automation, paste the above two commands in your cron jobs, such as the following:

0 1 * * * /sbin/swapoff -a && /sbin/swapon -a
0 0 * * * /bin/sync; echo 3 > /proc/sys/vm/drop_caches; echo 0 > /proc/sys/vm/drop_caches; /bin/sync


Note : i use CentOS 6.4 with root privilege

Hope these tricks helps 

No comments:

Post a Comment

Leave your comments with attitude please. This blog does DOFOLLOW :-)