Clear Linux RAM cache and free up SWAP memory
IN this tutorial I’ll show you how you can easily clear ram cache and swap memory to speed up the Linux server.
You all are familiar with word CACHE which usually represents performance benefits like cache can improve website’s loading speed and similarly cache will improve Linux server performance too in some places. Normally cache are managed by Linux Kernel efficiently and will be cleaned overtime when not in use. Cache cleaning is necessary to refresh and free up the system memory so a new version of cache can be built by eliminating old cache. In result it will help your Server to run even faster with fresh cache.
Let’s get started with the tutorial :
Please note it is not recommended running Level 3 cache on regular basis, use it when you need to free up memory and cache. It is recommend to use level 1 cache clearing only.
Here there are 3 levels of RAM cache clearing commands :
vm.drop_caches=1 : This is will clear pagecache – recommended
sync; echo 1 > /proc/sys/vm/drop_caches
vm.drop_caches=2 : This is will clear dentries and inodes
sync; echo 2 > /proc/sys/vm/drop_caches
vm.drop_caches=3 : This is will clear pagecache, dentries and inodes i.e. all cache are cleared
sync; echo 3 > /proc/sys/vm/drop_caches
Clear Swap Memory :
Clearing swap memory can take time depending disk speed and the size of the swap memory usage, to clear it simply run this command :
swapoff -a && swapon -a
** also don’t use cache clearing command under cron jobs, this commands should be run manually and automation is not recommended.