Linux is designed in such a way that it looks into disk cache before looking onto the disk. If it finds the resource in the cache, then the request doesn’t reach the disk. If we clean the cache, the disk cache will be less useful as the OS will look for the resource on the disk.
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.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.
/+ buffers/cache: 771 7056 Swap: 49. You will find difference between used and cache memory before and after clearing cache. In case of heavy memory consumption, you will set cron job to clear memory in hourly basis OR as per your convenience. Basically with enough RAM for your standard method of operation, neither swap activity (if any) nor cache should really affect the operation of the OS in any significant way. On some Linux systems I did tend to use the sync command when logging out to make sure the system flushed the buffers and that I had a clean logout.
This tutorial will help you to clear memory cache on Linux/Unix system via command line.
How to Clear Cache in Linux System
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
Clear Cache Ram Linux Server
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
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.
Open a terminal and execute ‘crontab -e’ command to edit crontab:
Append below entry to the file:
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
Output:
Clear Cache Ram Linux Windows 7
Here the last column is showing cached memory (12953 MB) on Linux system. The -m option is used to show output MB’s.