Description
Like other operating systems, Linux has implemented a very efficient memory management mechanism, but any process that destroys the system's memory, then you have to clean it up, Linux provides a better way to flush \ Clear the RAM cache.
Note: It is not always necessary to clear the RAM cache, as we all know, the Linux lookup data is first looked up from the RAM cache, once the cache is emptied, all the data needs to be read from the disk, so only when needed to empty the cache, is the right choice.
How do I clear the Linux cache?
1. Clear Pagecache only:
# sync; Echo 1 >/proc/sys/vm/drop_caches
2. Clear Dentries and Inodes
# sync; Echo 2 >/proc/sys/vm/drop_caches
3. Clear Pagecache and Dentries and inodes at the same time
# sync; Echo 3 >/proc/sys/vm/drop_caches
An explanation of the above command:
Sync will refresh the system's buffer
According to the official kernel document description, the write value to Drop_caches will empty the cache without killing any app service.
Echo 1 is recommended in a production environment because it prioritizes the disk cache.
Effect Show:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/4E/wKiom1X5faHxHMfPAAG6dD4o1MQ646.jpg "title=" Qq20150916222927.jpg "alt=" Wkiom1x5fahxhmfpaag6dd4o1mq646.jpg "/>
Use shell scripts to automatically clear the RAM cache at night 2 o'clock
Vim clearcache.sh #!/bin/bashecho "Echo 1 >/proc/sys/vm/drop_caches"
# chmod 755 clearcache.sh# CRONTAB-E 0 3 * */path/to/clearcache.sh
How do I clear swap space?
Simple cleanup can use the following commands
# swapoff-a && swapon-a
Combined with the above script
Vim clearcache.sh #!/bin/bashecho "Echo 1 >/proc/sys/vm/drop_caches" && swapoff-a && swapon-a & & printf ' \n%s\n ' Ram-cache and Swap cleared '
This article is from the "Linux is belong to You" blog, make sure to keep this source http://jwh5566.blog.51cto.com/7394620/1695504
How to clear Linux memory cache, buffer and swap space