How do I change the OS file cache flush policy?

Environmental description

The following is for the linux operating system and is valid for testing on centos/RHEL 6 and centos/RHEL 7.

Related parameters

The following two parameters are mainly related to the file system write cache strategy. Other related references can be Googled by yourself:

/proc/sys/vm/dirty_ratio

The size of the file system write buffer, the unit is percentage, which means the percentage of system memory, which means that when the write buffer uses the system memory, it starts to write data to the disk. Increasing it will use more system memory for disk write buffering, and can also greatly improve system write performance. However, when continuous, constant writing is required, its value should be lowered.

/proc/sys/vm/dirty_background_ratio

Controls when the pdflush process flushes the disk. The unit is a percentage, indicating the percentage of system memory, which means that when the write buffer uses how much system memory, pdflush starts to write data to the disk. Increasing it will use more system memory for disk write buffering, and can also greatly improve system write performance. However, when continuous, constant writing is required, the value should be lowered.

Comparison description

vm.dirty_background_ratio: This parameter specifies that when the number of dirty pages cached by the file system reaches the percentage of system memory (such as 5%), background write-back processes such as pdflush/flush/kdmflush will be triggered to run, and certain cached dirty pages will be asynchronously swipe into external memory;

vm.dirty_ratio: And this parameter specifies when the number of dirty pages cached by the file system reaches the percentage of system memory (such as 10%), the system has to start processing dirty pages in the cache (because the number of dirty pages is already large at this time, In order to avoid data loss, a certain dirty page needs to be flushed into external memory); during this process, many application processes may be blocked because the system turns to process file IO.

Normally, the condition of vm.dirty_background_ratio is reached first, and then the flush process is triggered to perform an asynchronous write-back operation. However, during this process, the application process can still perform the write operation. If the amount written by multiple application processes is greater than the amount flushed by the flush process It will naturally reach the threshold set by the parameter vm.dirty_ratio, and the operating system will switch to the process of synchronously processing dirty pages, blocking the application process.

That is, the normal vm.dirty_background_ratio < vm.dirty_ratio only makes sense.

In a system that often has a large number of write operations, the values ​​of these two parameters should be lowered respectively to speed up the frequency of data flushing, so as to avoid the related process being in the D state due to the synchronous processing of file IO by the system.

Parameter modification method

Temporary effective method (invalid after restart):

echo 5 >/proc/sys/vm/dirty_background_ratio
echo 10 >/proc/sys/vm/dirty_ratio

or

sysctl -w vm.dirty_background_ratio=5
sysctl -w vm.dirty_ratio=10

Permanent method:

echo "vm.dirty_background_ratio = 5" >> /etc/sysctl.conf
echo "vm.dirty_ratio = 10" >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf

Reference:
http://blog.sina.com.cn/s/blog_448574810101k1va.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325637309&siteId=291194637