Clearing cached ram on a linux server
You can force the Linux OS to free up any stored Cached memory.
First of all login to your server via SSH.
To check the current ram statistics, run the following command:
# free -mYou will get output similar to the following:
[root@server ~]# free -m
total used free shared buffers cached
Mem: 7851 7763 88 0 107 6365
-/+ buffers/cache: 1290 6561
Swap: 4095 98 3997
[root@server ~]# free -m
total used free shared buffers cached
Mem: 7851 7763 88 0 107 6365
-/+ buffers/cache: 1290 6561
Swap: 4095 98 3997
This server has a total of 8GB Ram and currently only has 88MB free.
To clear cached ram, run the following command:
# sync; echo 3 > /proc/sys/vm/drop_cachesDepending on your system, it can take few moments for the OS to process this request. Once it has been done, you can check the RAM again with the first command free -m.
[root@server ~]# free -m
total used free shared buffers cached
Mem: 7851 1397 6454 0 5 220
-/+ buffers/cache: 1170 6680
Swap: 4095 98 3997
[root@server ~]# free -m
total used free shared buffers cached
Mem: 7851 1397 6454 0 5 220
-/+ buffers/cache: 1170 6680
Swap: 4095 98 3997
The server now has 6454 MB of free RAM available. This is the easiest way of clearing cached ram via the command line interface.