Informational Website publish

Blog

News about our company, tutorials about IT and much more you will find in this page.

How to Flush (RAM) Memory Cache on Linux Server

Janeiro 30th, 2018

Many times Linux systems face low memory issues when they’re running for a while. The reason Linux uses so much memory for disk cache is because the RAM is wasted if it isn’t used. Cache is used to keep data frequently used by the operating system easily accessible. Reading data from cache is 1000’s times faster than reading data from the hard drive.

It’s good for the OS to get data from cache on memory. But if any data is not found in the cache, it reads from the hard disk. So it’s not a problem to flush cache memory. This article has details about how to Flush Memory Cache on a Linux Server.

Use slabtop display kernel slab cache information:

  • slabtop

You can also see with “vmstat -m”:

  • vmstat -m

And look /proc/slabinfo:

  • cat /proc/slabinfo

Free pagecache, dentries and inodes in cache memory

  • sync; echo 3 > /proc/sys/vm/drop_caches

Free dentries and inodes use following command

  • sync; echo 2 > /proc/sys/vm/drop_caches

Free only the pagecache using the following command

  • sync; echo 1 > /proc/sys/vm/drop_caches

Schedule Cron to Flush Cache Regularly

It’s a good idea to schedule the following in crontab to automatically flush cache on regular interval.

  • crontab -e
0 * * * * sync; echo 3 > /proc/sys/vm/drop_caches