How to clear Linux memory cache, buffer and swap space

Source: Internet
Author: User
Tags app service

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.