Clear Memory Cache on Linux centos

Linux memory cache
Linux memory cache

By default, every Linux OS has an efficient memory management system used to clear the buffer cache periodically. You can manually free up the memory cache with the following simple command:

linux:~$ sudo sh -c “sync; echo 3 > /proc/sys/vm/drop_caches”

However, if you want to force the Linux OS to do clearing memory cache on a particular interval, just add the command to cron job.

There are three options available to flush cache of linux memeory. Use one of below as per your requirements.

More Options:

1. To free pagecache, dentries and inodes in cache memory

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

2. To free dentries and inodes use following command

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

3. To free pagecache only use following command

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

Setup Cron to Flush Cache Regularly

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

Click here to learn more about linux cron job schedule

Linux Cron Job – Schedule Job in linux: crontab

Leave a Reply