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.
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 :
Code:
# sync; echo 1 > /proc/sys/vm/drop_caches
ii. Clear Dentries and Inodes :
Code:
# sync; echo 2 > /proc/sys/vm/drop_caches
iii. Clear PageCache, Inodes and Dentries:
Code:
# sync; echo 3 > /proc/sys/vm/drop_caches
2. Clear Swap Space in Linux : To Clear Swap Space in Linux you should run the following command.
Code:
# swapoff -a && swapon –a
Code:
# echo 3 > /proc/sys/vm/drop_caches && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'
Code:
$ su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root