How To Clear Cache Memory In Linux

Posted on  by admin
GNU or Linux has amazing Memory Management system for efficient Memory Management but still if you think that any process is occupying your memory then Linux offers the process to clear the RAM cache. The process to do so is given in the following text.
1. Clear Cache in Linux : You can use any of these three options and can clear Cache in Linux without interrupting any other process or service.
i. Clear Only the PageCache :
Here “sync” will clear the file system buffer, “drop_cache” will clean cache without killing any other application or service and “...echo 1 > ….” will clear only the PageCache.
ii. Clear Dentries and Inodes :
Here “sync” will clear the file system buffer, “drop_cache” will clean cache without killing any other application or service and “...echo 2 > ….” will clear Dentries and Inodes.
iii. Clear PageCache, Inodes and Dentries:
Here “sync” will clear the file system buffer, “drop_cache” will clean cache without killing any other application or service and “...echo 2 > ….” will clear PageCache as well as Dentries and Inodes.
2. Clear Swap Space in Linux : To Clear Swap Space in Linux you should run the following command.
3. You can use the following command to make a Script to clear Both RAM Cache as well as Swap Space.
OR
4. You should also use “free -h” command before and after running the above script to check the 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.
  • The page cache is automatically enabled on Linux systems and will transparently make IO faster by storing recently used data in the cache. If you want to manually clear the cache that can be done easily by sending an echo command to the /proc filesystem indicating to the kernel to drop the cache and free the memory used for the cache.
Cache

How To Clear Cache In Memory

Try sync; echo 1 /proc/sys/vm/dropcaches. Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. As this is a non-destructive operation and dirty objects are not freeable, the user should run 'sync' first.