In this tutorial, I will show you how to free up as much memory as possible by using a very simple command in Linux, it’s may applied on Ubuntu, CentOS, openSUSE or any Unix system. By using this command, you don’t need to normally reboot your server to clear the cache from the memory.
First, you should check your current memory usage by using command below:
$ free -m
There are 3 ways to help you free up a lot of memory, you can use either of following methods:
1. Free pagecache
$ echo 1 > /proc/sys/vm/drop_caches
2. Free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches
3. Free pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
All of them are quite easy but I always choose command number 3 for my server. You can create a cron job in your system to automatically free up your memory at a time specified.
After run one of 3 commands above, you should run free -m to check how it works.