Android / Linux disk write caching / wait time parameter modification

When the Linux file system when performing a write operation, the data will not be immediately written to disk, but write to the cache, waiting for a certain percentage of occupied memory or over a certain time before the bulk of these cached data written to disk, thus reducing the IO operations, improve performance and disk life. If the data is not enough time to write to the disk hardware power-down occurs, the data will be lost. Applications can call sync content is written to disk in real time to avoid losing. Troubleshoot problems may lose sync command is executed before the power failure, see if I can reproduce, If you can not reproduce, indicating that the cache is not written to disk results in a timely manner.

We can adjust some parameters of the system to improve this problem, but the need for a balanced IO performance and data security.

1. /proc/sys/vm/dirty_ratio

This parameter controls the file system's file system write buffer size, the unit is the percentage, expressed as a percentage of system memory, showing how much to use when writing the buffer memory when the system starts to write data to disk. The increased use more system memory for disk write buffer, can greatly improve write performance of the system. However, when you need continuous, constant writes occasions, its value should be lowered

 

2. /proc/sys/vm/dirty_background_ratio

pdflush this process parameter control of the file system, and when the flush to disk. The unit is the percentage, expressed as a percentage of system memory, meaning that when the write buffer using system memory to how much time, pdflush began to write data to disk. The increased use more system memory for disk write buffer, can greatly improve write performance of the system. However, when you need continuous, constant writes occasions, its value should be lowered

 

3. /proc/sys/vm/dirty_writeback_centisecs 

This parameter controls the running kernel dirty data refresh interval pdflush the process. The unit is 1/100 seconds. The default value is 500, it is 5 seconds. If your system is continuously writing operation, then in fact or lower this value is better, so you can write the spikes flattened into multiple write operations

 

4. /proc/sys/vm/dirty_expire_centisecs

After this parameter declarations inside the Linux kernel buffer write data more "old" the, pdflush process began to consider written to disk. The unit is 1/100 seconds. The default is 3000, which is 30 seconds even if the data is old, will refresh the disk. For particularly heavy load of a write operation, this value is appropriately reduced is good, but it can not be reduced too much, because too much can lead to reduced too quickly improve IO
 

Disk cache data stored in the maximum time, if not finish this time, will be reported abnormal stop writing, so the cached data will continue to accumulate, leading to memory ringing off the hook.

echo 0 > /proc/sys/kernel/hung_task_timeout_secs

Lower the percentage, so that the buffer is written to disk as soon as possible, so that the buffer will not accumulate large amounts of data began to be written to disk

echo 5 > /proc/sys/vm/dirty_background_ratio

echo 10 > /proc/sys/vm/dirty_ratio

 

Android modify these parameters default:

system/core/rootdir/init.rc    

570     # Tweak background writeout
571     write /proc/sys/vm/dirty_expire_centisecs 200
572     write /proc/sys/vm/dirty_background_ratio  5

On the other hand you can modify mount mount options, using sync sync mode, the file is written directly to disk, but would slow down

reference:

linux disk cache parameters _b779789251 the blog -CSDN blog https://blog.csdn.net/b779789251/article/details/94559911

linux adjust the cache are written to disk, reducing the possibility of disk ringing off the hook - scripts small Wazi - blog Park https://www.cnblogs.com/shengulong/p/9265145.html

Depth analysis disk cache mechanism under Linux with SSD's write amplification problem _LINUX_ operating system _ script Home https://www.jb51.net/LINUXjishu/405114.html

https://blog.csdn.net/chuanzhilong/article/details/76020517

[Actual] cluster NFS network file sharing service 2-mount mount (parameters, optimization) - async sync dirsync other parameters to explain

https://www.cnblogs.com/zoe233/p/12018875.html

Published 44 original articles · won praise 31 · views 60000 +

Guess you like

Origin blog.csdn.net/u013463707/article/details/103902976