Free command-linux memory cached release

Source: Internet
Author: User
Tags rsync

In the work often encounter Linux memory is very large, but the cached accounted for most of the memory space, causing Linux to start the swap situation.

This is the case:

Total Memory 128g,cached occupies 108G, causing the system to use swap memory, resulting in degraded performance and slower speed

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/07/9E/wKiom1nMkDHSeihvAAAYMFPk230424.png "title=" ec73~ [$L (Go3gye6yn76kyq.png "alt=" Wkiom1nmkdhseihvaaaymfpk230424.png "/>

The role of buffer,cached:

cached is mainly responsible for the use of cache files, log files too large to cause the cached area memory to occupy the memory.
Buffer and cache in free: (They are all memory-intensive):
Buffer: Memory as buffer cache, which is the read and write buffer of the block device
Cache: As the page cache memory, the file system cache
If the cache has a large value, it indicates that the cache has a high number of files.

In order to improve disk access efficiency, Linux has done some careful design, in addition to the Dentry cache (for VFS, speed up the file path name to Inode conversion), but also adopted two main cache mode: Buffer cache and Page cache. The former is for the disk block read and write, the latter for the file inode read and write. These caches effectively shorten the time for I/O system calls (such as read,write,getdents).


How to solve the problem that causes the machine to become slow?
The main culprit is that the memory has been cached, the basic free
So we should think about how to release the cached memory.
Restarting the machine is sure to work, but we must not be able to do that.

There are three ways to release the system (the default is 0, and you need to change the value back to 0 after release ):
To free Pagecache:echo 1 >/proc/sys/vm/drop_caches
To free dentries and Inodes:echo 2 >/proc/sys/vm/drop_caches
To free Pagecache, dentries and Inodes:echo 3 >/proc/sys/vm/drop_caches

Common methods are: Echo 1 >/proc/sys/vm/drop_caches

execute the above command to free up about 40G of cached space

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/A6/50/wKioL1nMk_myh8MHAAAYp4hcr1o225.png "title=" 5%) Tjrku]$[m_$9l9zdhz20.png "alt=" Wkiol1nmk_myh8mhaaayp4hcr1o225.png "/>

Friends who often use rsync to transmit large amounts of data may have encountered a similar situation: The beginning is the transfer of a large number of files in the past, to the later transfer of data is not big, but is very slow, to the edge of the server will find in the Terminal Input command is not slow, but look at memory usage, found that free memory is very low, Almost 0, I think it could be that the memory is cached.

Why should we release cached memory? Because when we use rsync to transfer large amounts of data, the Linux system caches some of the file's information in memory, which can reduce the disk IO time consumption of frequently used files, and when we pass through a batch of files, we have to transfer another batch of files in the past, is completely different files or the contents of the file has changed, the in-memory cache file is not what we need, we need to clear the cache, freeing up memory to transfer the next batch of files to use, this time we need to see more memory is Free State.

On this premise, it is necessary for us to manually empty the cache, freeing up more available memory to

Note: Before emptying the cache, we need to execute the sync command on the Linux system to write the contents of the cache that are not written to disk.

In addition to releasing cached memory, you also need to set the value of vm.swappiness to use physical memory to a large extent

To view the value of the vm.swappiness parameter:

#sysctl-Q vm.swappiness

Temporarily set the value of Vm.swappiness (takes effect after reboot)

#sysctl vm.swappiness=10

Permanently set vm.swappiness:

echo "vm.swappiness = ten" >>/etc/sysctl.conf

This article is from the "burning Years of Passion" blog, please be sure to keep this source http://liuzhengwei521.blog.51cto.com/4855442/1969413

Free command-linux memory cached release

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.