Ubuntu Ram Cache Clear



You can write to /proc/sys/vm/drop_caches file to instruct kernel to drop clean caches, as well as reclaimable slab objects like dentries and inodes. Once dropped, their memory becomes free.

To clear ram cache, you may call the script whenever required. Setting a cron to clear RAM cache everyday 2 hours. root@linuxhelp # crontab -e Append the following line, save and exit to execute it at 2 hours daily. 0 2. /path/to/script.sh To clear automatically the RAM cache on production server. The article provides information on how to clear cache / buffer memory on a Linux server and set a cron job to clear cache memory at regular intervals using cron service. The steps also work on various Linux flavors like RHEL, CentOs, Fedora, Ubuntu.

This is not recommended to clear memory cache on Linux systems, but it is safe. But clearing cache may cause performance issue with system. Since it discards cached objects from memory, it may cost a significant amount of I/O and CPU to recreate the dropped objects.

This tutorial will help you to clear memory cache on Linux/Unix system via command line.

How to Clear Cache in Linux System

Ubuntu ram cache clear command

There are three options available to clear cache in Linux system memory. Use one of below as per your requirements.

  • Clear PageCache, dentries and inodes in cache memory
  • Clear dentries and inodes only in cache memory
  • Clear pagecache only in cache memory
Cache

Here the sync command is used to increase the number of objects freed by the drop cache. Using this a user can claim more memory by clearing more dirty objects on the system.

How to Schedule Clear Memory Cache

Ubuntu ram cache clear windows 10

If you have to clear buffer cache regularly, use the cronjob do it. Schedule the following in system crontab to automatically flush cache memory on a regular interval.

Sophos xg 650. Open a terminal and execute ‘crontab -e’ command to edit crontab:

Append below entry to the file:

Ubuntu

The above cron will execute on every hour and flushes the memory cache on your system.

How to find Cache Memory in Linux

Use free command to find out cache memory uses by Linux system. Output of free command is like below

Ubuntu

Ubuntu Ram Cache Clear Windows 10

Output:

Clear Ram Cache Ubuntu 20.04

Here the last column is showing cached memory (12953 MB) on Linux system. The -m option is used to show output MB’s.

Free