Clear Cached Memory On Linux Without Reboot

Clear Cached Memory On Linux Without Reboot

If a Linux server appears to have inodes or dentries filling up cached memory, here is how you can flush it without putting the server through a reboot.

This will only work with linux kernels equal to or greater then version 2.6.16+ which was introduced around late 2005.

1 ) Check available, used, cached memory with this command:

[root@localhost]# top -n1 | grep -i "used," ; free -t -m
Mem:   4035004k total,  1478408k used,  2556596k free,   225932k buffers
Swap:  6088624k total,      156k used,  6088468k free,   675708k cached
             total       used       free     shared    buffers     cached
Mem:          3940       1443       2496          0        220        659
-/+ buffers/cache:        563       3377
Swap:         5945          0       5945
Total:        9886       1443       8442

In this case, approximately 659MB is cached, in most cases it can reach gigabyte ranges on production servers. Follow step #2.

2 ) Commit any buffers to disk first with following command:

sync

root@localhost]# sync
[root@localhost]# 

3 ) Next Let's send signal now to kernel to flush pagecaches, inodes, and dentries:

echo 3 > /proc/sys/vm/drop_caches

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

4 ) Check system RAM again

[root@localhost]# top -n1 | grep -i "used," ; free -t -m
Mem:   4035004k total,   563996k used,  3471008k free,     1224k buffers
Swap:  6088624k total,      156k used,  6088468k free,    35912k cached
             total       used       free     shared    buffers     cached
Mem:          3940        550       3389          0          1         35
-/+ buffers/cache:        514       3425
Swap:         5945          0       5945
Total:        9886        550       9335

We have now cleared cached memory and freed up several hundred MB without a server reboot. 
    • Related Articles

    • Linux

      Linux     System Information: Print Kernel and OS Release Versions: uname -r (or uname -a for all info) 2.6.32-531.29.2.lve1.3.11.1.el6.x86_64 cat /etc/*release* CloudLinux Server release 6.6 (Leonid Kizim) Linux Watch Limit: ...
    • Clear DNS Cache

      Microsoft Windows Windows 10 Flushing the DNS cache on Windows 10 is a very easy process. Due to system security permissions, you must ensure that you run the command prompt as an administrator user. Ensure that you're on the Windows 10 desktop. ...
    • New Access Management User setup on Linux

      1) Login to your accounts.cartika.com account 2) Select your access management service (customers with managed infrastructure in both the US and CAD will have two) 3) Navigate to Login to SolidCP -> Click Login 4) Click on Users under your Hosted ...
    • Linux BMR (ReaR)

      Cartika has developed a new Linux BMR tool into our backups/dr and BaaS offerings.  This is more tightly integrated with our GUI and is based on the ReaR *nix server imaging technology. This new Linux BMR replaces the legacy/original Linux BMR. AS ...
    • Force www.MyDomain.com or without www (MyDomain.com) in a URL

      I would like to force my sites to show www.MyDomain.com or to show without www. How can I do this? This is easily done with our linux servers by using the following .htaccess directives. .htaccess is a regular text file that can be created in the ...