Manually release memory in CentOS

Source: Internet
Author: User

Manually release memory in CentOS

For a Web server at the backend of the online cluster, we have observed that the + buffers/cache value (actual usage of Linux memory) is always around 5365, even if the Nginx + FastCGI program is stopped, considering that this machine is often using rsync + inotify, there will certainly be frequent file access. In Linux, files are frequently accessed in Linux, which occupies physical memory. When the program ends, it will not automatically release the occupied memory, but will always exist as a Cache. In fact, after the kernel finishes a program, it will release the memory, but the kernel does not immediately collect this part into free, but exists in cached or buffer, improves the system's io efficiency. The cache and buffered memory are dynamically configured and managed by the kernel. If the system's free size is insufficient, the system will automatically release the cache buffer memory for the Program (so if you see a lot of used, it is not necessary to manually release the memory, my previous articles and books actually show how we can observe the actual memory usage of the Linux system ).

Procedure:

1. query the current memory usage and cache release parameters.

Free-m

The command result is shown in:

TotalusedfreesharedbufferscachedMem: 109886792419601681001-/+ buffers/cache: 56225365 Swap: 429504295

The command for viewing the release cache parameters is as follows:

Cat/proc/sys/vm/drop_caches

0

0 is the default value, indicating not to release.

2. Use the sync command to write dirty data in the system cache area to the disk, including modified I-node, delayed block I/O, and read/write ing files. The command is as follows:

Sync

3. The configuration file/proc/sys/vm/drop_caches records the cache release parameters. The command is as follows:

Echo3>/proc/sys/vm/drop_caches

4. Do not restart the machine to make the configuration change take effect. The command is as follows:

Sysctl-p

After the above operations are performed, the value of + buffers/cache has increased from 5365 to about 9000, and the value returns to normal. However, I think the Linux memory management method is actually excellent, in many cases, you do not need to manually release the memory.

This article from the "fuqin liquor" blog, please be sure to keep this source http://yuhongchun.blog.51cto.com/1604432/1430026

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.