linux缓存回收

Linux MemFree与MemAvailable的区别

2、MemFree：空闲内存数

3、MemAvailable：可用内存数

How to Clear RAM Memory Cache, Buffer and Swap Space on Linux

How to Clear Cache in Linux?

1. Clear PageCache only.

2. Clear dentries and inodes.

3. Clear PageCache, dentries and inodes.

Explanation of above command.

sync will flush the file system buffer. Command Separated by “;” run sequentially. The shell wait for each command to terminate before executing the next command in the sequence. As mentioned in kernel documentation, writing to drop_cache will clean cache without killing any application/service, command echo is doing the job of writing to file.

If you have to clear the disk cache, the first command is safest in enterprise and production as “...echo 1 > ….” will clear the PageCache only. It is not recommended to use third option above “...echo 3 >” in production until you know what you are doing, as it will clear PageCache, dentries and inodes.

How to Clear Swap Space in Linux?

you want to clear Swap space, you may like to run the below command.

Also you may add above command to a cron script above, after understanding all the associated risk.

Now we will be combining both above commands into one single command to make a proper script to clear RAM Cache and Swap Space.