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

Related Posts

  • 40
    Clear Memory Cache on Linux centos RESET QUERY CACHE will clear out the query cache, but needs RELOAD privileges. RESET QUERY CACHE; or FLUSH QUERY CACHE does NOT clear out the query cache, it simply defrags it leaving the cached query results in place. FLUSH QUERY CACHE;      
    Tags: cache, clear, flush, memory, linux

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: