Linux Memory Management

Source: Internet
Author: User

The strategy of the Linux kernel is to maximize the use of memory Cache file system data, improve the IO speed, although the mechanism is that the process requires more memory, the page Cache will be automatically freed, but does not rule out the release of memory due to fragmentation does not meet the memory requirements of the process.

You can do this manually to free page Cache by command echo 3 >/proc/sys/vm/drop_caches, but sometimes you still find that the freed memory is not enough because Linux provides such a parameter min_free_kbytes, To determine the threshold at which the system begins to reclaim memory, the higher the value, the higher the free memory, such as echo 10240 >/proc/sys/vm/min_free_kbytes, which ensures that the free memory is 100M.


Modify/etc/sysctl.conf Add the following option and no memory continues to increase
Vm.dirty_ratio = 1
Vm.dirty_background_ratio=1
vm.dirty_writeback_centisecs=2
Vm.dirty_expire_centisecs=3
Vm.drop_caches=3
Vm.swappiness =100
vm.vfs_cache_pressure=163
vm.overcommit_memory=2
VM.LOWMEM_RESERVE_RATIO=32 32 8
Kern.maxvnodes=3

The above settings are rough, so that the role of the cache is basically unable to play. It is necessary to adjust the condition of the machine to find the best compromise.

/proc/sys/vm/dirty_ratio

This parameter controls the size of the file system write buffer for the filesystem, in percent, representing the percentage of system memory, indicating how much of the memory is used to write data to disk. Increased use of more system memory for disk write buffering can also greatly improve the write performance of the system. However, when you need a continuous, constant write situation, you should lower its value, generally starting on the default is 10. Set 1 Acceleration Program speed

/proc/sys/vm/dirty_background_ratio

This parameter controls the Pdflush process of the file system and when the disk is refreshed. The unit is a percentage that represents the percentage of system memory, meaning that when the write buffer is used to the amount of system memory, Pdflush begins writing data to the disk. Increased use of more system memory for disk write buffering can also greatly improve the write performance of the system. However, when you need a continuous, constant write situation, you should lower its value, generally starting on the default is 5

/proc/sys/vm/dirty_writeback_centisecs

This parameter controls the run interval of the kernel's dirty data refresh process Pdflush. The unit is 1/100 seconds. The default value is 500, which is 5 seconds. If your system is continuously writing to the action, then actually it is better to lower this value, so that the spike write operation can be flattened to multiple writes

/proc/sys/vm/dirty_expire_centisecs

this parameter declares that after the Linux kernel writes the data in the buffer is "old", the Pdflush process begins to consider writing to disk. The unit is 1/100 seconds. The default is 30000, which means that 30 seconds of data is old and will flush the disk. For specially overloaded writes, it is good to shrink the value appropriately, but it does not shrink too much, because too much narrowing can cause the IO to improve too quickly. The recommended setting is 1500, which is 15 seconds old. &NBSP
/proc/sys/vm/drop_caches
Releases the cache
/proc/sys/vm/page-cluster
that is already in use, which represents the number of pages written once to the swap area, 0 represents 1 pages, 1 means 2 pages, and 2 represents 4 pages.
/proc/sys/vm/swapiness
This file represents the degree to which the system is exchanging behavior, and the higher the value (0-100), the more likely the disk exchange will occur.
/proc/sys/vm/vfs_cache_pressure
This file indicates that the kernel recycles the propensity for directory and Inode cache memory




/etc/sysctl.conf
Vm.dirty_ratio = 1
vm.dirty_background_ratio=1
Vm.dirty_writeback_ Centisecs=1
vm.dirty_expire_centisecs=3
vm.drop_caches=3
vm.swapiness=100
vm.vfs_cache_pressure= 133

Vm.dirty_ratio = 5 #dft 20
Vm.dirty_background_ratio =5 #dft 10
vm.dirty_writeback_centisecs=100 #dft 5s
vm.dirty_expire_centisecs=300 #dft 30000 is 30s
Vm.drop_caches=3 #dft 0
vm.swappiness=100 #dft 60
vm.vfs_cache_pressure=133 #dft 100

vm.min_free_kbytes=204800

#200M Mem

Save Simple sysctl -w net.ipv4.route.flush=1


Linux Memory Management

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.