This topic describes how to modify the parameter files in the /sys/class/bdi/<bdi>/ directory of Alibaba Cloud Linux 2 or 3 to fine-tune the dirty page thresholds and writeback control for a specific file system.
In the /sys/class/bdi/<bdi>/ directory, <bdi> represents the version of the corresponding device in the <major:minor> format. You can run the lsblk command to view the MAJ:MIN parameter value of a disk device.
Background information
In Linux, page cache is used to cache file system read and write operations (buffer I/Os). Data is first written to page cache and then to non-volatile storage through a writeback operation at a specific time. The page cache that has not yet been written back is referred to as dirty pages. To maintain an optimal level of dirty pages, the system periodically performs writeback operations or initiates writeback operations when the level of dirty pages reaches the upper limit.
QoS control
When the overall dirty page level of the system exceeds the free_run threshold (the dirty page level that triggers dirty page writeback), the speed of writing dirty pages to the cache is throttled to control the dirty page level of the system. The extent of throttling for each file system is determined by its writeback bandwidth quota, which in turn is determined by the percentage of the average writeback bandwidth of the file system over the total system writeback bandwidth in a past period of time. Devices with faster writeback speeds are allocated a larger writeback bandwidth quota, making it easier to get out of the throttled state when writing dirty pages. To better define the quality of service (QoS) of the above process, the minimum and maximum writeback bandwidth quotas are introduced.
Minimum writeback bandwidth quota
The minimum writeback bandwidth quota is the lowest writeback bandwidth quota that a file system can be allocated when the speed of writing dirty pages is throttled, which defines the minimum QoS guarantee. The following three interfaces can all be used to configure the minimum writeback bandwidth quota, but only one interface can take effect at a time:
min_ratio
Limits
Alibaba Cloud Linux 2.
Alibaba Cloud Linux 3.
Configure min_ratio
/sys/class/bdi/<bdi>/min_ratio specifies the percentage of the minimum writeback bandwidth quota of a file system over the total system writeback bandwidth in a past period of time. Default value: 0.
Query
min_ratioReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/min_ratioConfigure
min_ratioReplace
<bdi>with the version of the corresponding device in the<major:minor>format.Replace
<value>with a desired value.sudo sh -c 'echo <value> > /sys/class/bdi/<bdi>/min_ratio'For example, set the minimum writeback bandwidth quota of the
nvme0n1disk device to 20% of the total system writeback bandwidth in a past period of time.sudo sh -c 'echo 20 > /sys/class/bdi/259:0/min_ratio'
min_ratio_fine
Limits
Alibaba Cloud Linux 3 with kernel version 5.10.134-17 and later.
Configure min_ratio_fine
/sys/class/bdi/<bdi>/min_ratio_fine specifies the proportion of the minimum writeback bandwidth quota of a file system over the total system writeback bandwidth in a past period of time, in millionths. min_ratio_fine provides higher precision than min_ratio.
Query
min_ratio_fineReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/min_ratio_fineConfigure
min_ratio_fineReplace
<bdi>with the version of the corresponding device in the<major:minor>format.Replace
<value>with a desired value.sudo sh -c 'echo <value> > /sys/class/bdi/<bdi>/min_ratio_fine'For example, set the minimum writeback bandwidth quota of the
nvme0n1disk device to 20% of the total system writeback bandwidth in a past period of time.sudo sh -c 'echo 200000 > /sys/class/bdi/259:0/min_ratio_fine'
min_bytes
Limits
Alibaba Cloud Linux 3 with kernel version 5.10.134-17 and later.
Configure min_bytes
/sys/class/bdi/<bdi>/min_bytes specifies the minimum writeback bandwidth quota of a file system in bytes.
Query
min_bytesReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/min_bytesConfigure
min_bytesReplace
<bdi>with the version of the corresponding device in the<major:minor>format.Replace
<value>with a desired value.sudo sh -c 'echo <value> > /sys/class/bdi/<bdi>/min_bytes'For example, set the minimum writeback bandwidth quota of the
nvme0n1disk device to 67,108,864 bytes. 67,108,864 bytes is equal to 64 MB.sudo sh -c 'echo 67108864 > /sys/class/bdi/259:0/min_bytes'
Maximum writeback bandwidth quota
The maximum writeback bandwidth quota is the highest writeback bandwidth quota that a file system can be allocated when the speed of writing dirty pages is throttle. The maximum writeback bandwidth quota is primarily used for file systems whose bandwidths fluctuate due to network factors, such as Network File System (NFS) and Filesystem in Userspace (FUSE) file systems, to limit their writeback bandwidth quotas and prevent their impacts on other file systems. The following three interfaces can all be used to configure the maximum writeback bandwidth quota, but only one interface can take effect at a time:
max_ratio
Limits
Alibaba Cloud Linux 2.
Alibaba Cloud Linux 3.
Configure max_ratio
/sys/class/bdi/<bdi>/max_ratio specifies the percentage of the maximum writeback bandwidth quota of a file system over the total system writeback bandwidth in a past period of time. Default value: 100.
Query
max_ratioReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/max_ratioConfigure
max_ratioReplace
<bdi>with the version of the corresponding device in the<major:minor>format.Replace
<value>with a desired value.sudo sh -c 'echo <value> > /sys/class/bdi/<bdi>/max_ratio'For example, set the maximum writeback bandwidth quota of the
nvme0n1disk device to 60% of the total system writeback bandwidth in a past period of time.sudo sh -c 'echo 60 > /sys/class/bdi/259:0/max_ratio'
max_ratio_fine
Limits
Alibaba Cloud Linux 3 with kernel version 5.10.134-17 and later.
Configure max_ratio_fine
/sys/class/bdi/<bdi>/max_ratio_fine specifies the proportion of the maximum writeback bandwidth quota of a file system over the total system writeback bandwidth in a past period of time, in millionths. max_ratio_fine provides higher precision than max_ratio.
Query
max_ratio_fineReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/max_ratio_fineConfigure
max_ratio_fineReplace
<bdi>with the version of the corresponding device in the<major:minor>format.Replace
<value>with a desired value.sudo sh -c 'echo <value> > /sys/class/bdi/<bdi>/max_ratio_fine'For example, set the maximum writeback bandwidth quota of the
nvme0n1disk device to 60% of the total system writeback bandwidth in a past period of time.sudo sh -c 'echo 600000 > /sys/class/bdi/259:0/max_ratio_fine'
max_bytes
Limits
Alibaba Cloud Linux 3 with kernel version 5.10.134-17 and later.
Configure max_bytes
/sys/class/bdi/<bdi>/max_bytes specifies the maximum writeback bandwidth quota of a file system in bytes.
Query
max_bytesReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/max_bytesConfigure
max_bytesReplace
<bdi>with the version of the corresponding device in the<major:minor>format.Replace
<value>with a desired value.sudo sh -c 'echo <value> > /sys/class/bdi/<bdi>/max_bytes'For example, set the maximum writeback bandwidth quota of the
nvme0n1disk device to 67,108,864 bytes in a past period of time. 67,108,864 bytes is equal to 64 MB.sudo sh -c 'echo 67108864 > /sys/class/bdi/259:0/max_bytes'
Dirty page thresholds for file systems
When the overall dirty page level of the system exceeds the free_run threshold, the speed of writing dirty pages to the cache is throttled to control the dirty page level of the system.
To configure the upper limit of the dirty page level for a file system, you must enable the strict limit feature. After the feature is enabled, the dirty page threshold of the file system is the global free_run threshold multiplied by the quota ratio of the file system. The quota ratio of the file system is calculated based on the percentage of its average writeback bandwidth over the total system writeback bandwidth in a past period of time and corrected by using the min_ratio and max_ratio parameters.
After the strict limit feature is enabled for a file system, the speed of writing dirty pages to the cache of the file system is throttled as long as the dirty page level of the file system exceeds its own threshold.
Limits
Alibaba Cloud Linux 3 with kernel version 5.10.134-17 and later.
Configure strict_limit
The /sys/class/bdi/<bdi>/strict_limit parameter specifies whether the strict limit feature is enabled for the file system. A value of 1 indicates that the strict limit feature is enabled, and a value of 0 indicates that the strict limit feature is disabled. You can perform the following operations to query the strict_limit parameter and configure the parameter to enable or disable the strict limit feature.
Query
strict_limitReplace
<bdi>with the version of the corresponding device in the<major:minor>format.cat /sys/class/bdi/<bdi>/strict_limitEnable the
strict limitfeatureReplace
<bdi>with the version of the corresponding device in the<major:minor>format.sudo sh -c 'echo 1 > /sys/class/bdi/<bdi>/strict_limit'Disable the
strict limitfeatureReplace
<bdi>with the version of the corresponding device in the<major:minor>format.sudo sh -c 'echo 0 > /sys/class/bdi/<bdi>/strict_limit'