Pdflush process details

Source: Internet
Author: User

Pdflush process description 1. Introduction due to the cache function of page cache, write operations are actually delayed. When the page cache data is updated compared with the data stored in the background, the data is called dirty data. Dirty pages accumulated in the memory must eventually be written back to the disk. In either of the following situations, dirty pages are written back to the disk: 1. When the idle memory falls below a specific threshold, the kernel must write the dirty pages back to the disk to release the memory. 2. When the residence time of dirty pages in the memory exceeds a specific threshold, the kernel must write the dirty pages that have timed out back to the disk to ensure that the dirty pages do not reside in the memory indefinitely. The above two jobs have different purposes. In fact, in the old kernel, this is done by two independent kernel threads. However, in the 2.6 kernel, a group of kernel threads-pdflush background write-back routines-run two types of work in a unified manner. Let's take a look at how these two goals are implemented. First, when the idle memory in the system falls below a specific threshold, the pdflush thread refresh the dirty pages back to the disk. The background write-back routine aims to release dirty pages to regain memory when the available physical memory is too low. The specified memory threshold value can be set using the dirty_background_ratio parameter. When the idle memory is lower than the dirty _ background_ratio threshold, the kernel calls the wakeup_bdflush () function to wake up a pdflush thread, and then the pdflush thread further calls the function background_writeout () to write dirty pages back to Disks. The function background _ writeout () requires a long integer parameter, which specifies the number of pages to write back. The background_writeout () function continuously writes data until the following two conditions are met: 1. A specified page with the minimum number of records has been written to the disk. 2. The number of idle memory has rebounded, exceeding the dirty_background_ratio threshold. The above conditions ensure that the pdflush operation can reduce the pressure of insufficient memory in the system. The write-back operation will not stop until the two conditions are met, unless pdflush writes back all the dirty pages, and no remaining dirty pages can be written back. To meet the second goal, the pdflush background routine will be periodically wakened (irrelevant to whether the idle memory is too low) and written out dirty pages that have been resident in the memory for too long, make sure that there are no dirty pages in the memory for a long time. When a system crashes, the memory will be in disorder, and dirty pages in the memory that have not been written back to the disk will be lost, so it is very important to periodically synchronize write-back. When the system starts, the kernel initializes a timer so that it can periodically wake up the pdflush thread and then run the function wb_kupdate (). This function writes back all dirty pages with a residence time of more than dirty_expire_centisecs seconds. Then the timer will be initialized to dirty_expire _ centisecs again and then wake up the pdflush thread. All in all, the pdflush thread is awakened cyclically and dirty pages that have exceeded a specific period are written back to the disk. Ii. Related Control Parameters in proc the system administrator can set write-back parameters in/proc/sys/vm or set them through sysctl system calls. The/proc/sys/vm/dirty_ratio parameter controls the file system write buffer size of a process in the file system. The unit is the percentage, indicating the percentage of system memory, indicates the amount of system memory used by the write buffer in a process. When there is another disk write operation, data is written to the disk. By increasing the size, you can use more system memory for disk write buffering and greatly improve the system write performance. However, when you need continuous and constant writing, you should reduce the value. The default value is 40. /Proc/sys/vm/dirty_background_ratio this parameter controls the pdflush process of the file system and when to refresh the disk. The Unit is the percentage, which indicates the percentage of the total memory of the system. This means that when the dirty data on the disk is buffered to the system memory, pdflush begins to refresh the dirty data to the disk. Increasing the memory size of multiple systems will be used for disk write buffering, which can also greatly improve the write performance of the system. However, when you need continuous and constant writing, you should reduce the value. The default value is 10. /Proc/sys/vm/dirty_writeback_centisecsPdflush: how often the background process is awakened and dirty data is written to the hard disk. Unit: 1/100 seconds. The default value is 500, that is, 5 seconds. If your system writes data continuously, it is better to reduce the value. In this way, you can split the peak write operation into multiple write operations. The setting method is as follows: echo 200>/proc/sys/vm/dirty_writeback_centisecs/proc/sys/vm/dirty_expire_centisecs. After the parameter declares that the dirty data in the Linux Kernel write buffer is too old, the pdflush process begins to consider writing data to the disk. Unit: 1/100 seconds. The default value is 30000, that is, if the data of 30 seconds is old, the disk will be refreshed. For write operations with special overloading, it is also good to narrow down this value, but it cannot be reduced too much, because too much will lead to IO increase too quickly. We recommend that you set it to 1500, that is, 15 seconds is counted as old. Echo 1500>/proc/sys/vm/dirty_expire_centisecs

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.