All Products
Search
Document Center

Alibaba Cloud Linux:Fine-tune the system dirty page thresholds and writeback control

Last Updated:Mar 27, 2025

This topic describes how to modify the parameter files in the /proc/sys/vm/ directory of Alibaba Cloud Linux 2 or 3 to fine-tune the system dirty page thresholds and writeback control.

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.

Supported operating systems

  • Alibaba Cloud Linux 2

  • Alibaba Cloud Linux 3

Dirty page thresholds

Description

Different thresholds apply when the level of dirty pages fall into one of the ranges illustrated below:

```
   (background writeback)
         free run            | soft throttle | hard throttle
-------------+---------------+---------------+------------>
             ^               ^               ^          dirty pages
dirty_background_thresh   free_run      dirty_thresh
```
  • Free run

    When the level of dirty pages in the system is lower than the free run threshold (free run = (dirty_background_thresh + dirty_thresh)/2)), the speed of writing dirty pages to the cache is not throttled. In this case, the system periodically executes the background writeback task (kupdate) to control the level of dirty pages.

  • Soft throttle

    When the level of dirty pages in the system exceeds the free run threshold, the speed of writing dirty pages to the cache is throttled to curb the accumulation of new dirty pages and control the level of dirty pages. The soft-throttle range is separated by the dirty_thresh parameter from the hard-throttle range.

    Soft throttling occurs when the level of dirty pages exceeds the free run threshold but remains below the dirty_thresh threshold. In this case, the speed of writing dirty pages to the cache is throttled only if the number of dirty pages being written by a file system exceeds the dirty page quota for the file system. The dirty page quota for each file system is calculated by taking the average writeback bandwidth of the file system as a percentage of the total writeback bandwidth in the system over a certain period of time and multiplying the percentage by the threshold defined by the thresh parameter.

  • Hard throttle

    Hard throttling occurs when the level of dirty pages in the system exceeds the threshold defined by the dirty_thresh parameter. In this case, the speed of writing data to the significantly restricted.

Configure dirty page thresholds

The level of dirty pages in the system is jointly controlled by the thresholds defined by the thresh and dirty_background_thresh parameters.

dirty_background_thresh

You can use the /proc/sys/vm/dirty_background_bytes or /proc/sys/vm/dirty_background_ratio parameter to configure a value for the dirty_background_thresh parameter as a threshold.

  • /proc/sys/vm/dirty_background_bytes: specifies the value of the dirty_background_thresh parameter in bytes.

  • /proc/sys/vm/dirty_background_ratio: specifies a percentage of the total available memory in the system as the value of the dirty_background_thresh parameter.

Note

Only one of the /proc/sys/vm/dirty_background_bytes and /proc/sys/vm/dirty_background_ratio parameters takes effect at a time, with the other set to 0. When you use sysctl to set one of the preceding parameters, the other parameter is automatically set to 0. The default value of the dirty_background_thresh parameter is 10% of the total available memory in the system.

  • Use the dirty_background_bytes parameter to specify a threshold.

    • Query the dirty_background_bytes parameter.

      sysctl -n vm.dirty_background_bytes
    • Set the dirty_background_bytes parameter.

      Replace <value> with a desired value. Unit: bytes.

      sudo sysctl -w vm.dirty_background_bytes=<value>
  • Use the dirty_background_ratio parameter to specify a percentage of the total available memory in the system as a threshold.

    • Query the dirty_background_ratio parameter.

      sysctl -n vm.dirty_background_ratio
    • Set the dirty_background_ratio parameter.

      Replace <percent> with a desired value. Unit: percentage (%). Example: 20.

      sudo sysctl -w vm.dirty_background_ratio=<percent>

dirty_thresh

You can use the /proc/sys/vm/dirty_bytes or /proc/sys/vm/dirty_ratio parameter to configure a value for the thresh parameter as a threshold.

  • /proc/sys/vm/dirty_bytes: specifies the value of the thresh parameter in bytes.

  • /proc/sys/vm/dirty_ratio: specifies a percentage of the total available memory in the system as the value of thresh parameter.

Note

Only one of the /proc/sys/vm/dirty_bytes and /proc/sys/vm/dirty_ratio parameters takes effect at a time, with the other set to 0. When you use sysctl to set one of the preceding parameters, the other parameter is automatically set to 0. The default value of the thresh parameter is 20% of the total available memory in the system.

  • Use the /proc/sys/vm/dirty_bytes parameter to specify a threshold.

    • Query the dirty_bytes parameter.

      sysctl -n vm.dirty_bytes
    • Set the dirty_bytes parameter.

      Replace <value> with a desired value. Unit: bytes.

      sudo sysctl -w vm.dirty_bytes=<value>
  • Use the /proc/sys/vm/dirty_ratio parameter to specify a percentage of the total available memory in the system as a threshold.

    • Query the dirty_ratio parameter.

      sysctl -n vm.dirty_ratio
    • Set dirty_ratio parameter.

      Replace <percent> with a desired value. Unit: percentage (%). Example: 20.

      sudo sysctl -w vm.dirty_ratio=<percent>

Periodic writeback in the background

When the level of dirty pages in the system is lower than the free run threshold (free run = (dirty_background_thresh + dirty_thresh)/2)), the speed of writing dirty pages to the cache is not throttled. In this case, the system periodically executes the background writeback task (kupdate) to control the level of dirty pages.

dirty_writeback_centisecs

The /proc/sys/vm/dirty_writeback_centisecs parameter specifies the interval at which the periodic writeback task is executed. Unit: centiseconds. A value of 0 indicates that the periodic writeback task is disabled. Default value: 500, which indicates that the periodic writeback task is executed at an interval of 5 seconds.

  • Query the dirty_writeback_centisecs parameter.

    sysctl -n vm.dirty_writeback_centisecs
  • Set the dirty_writeback_centisecs parameter.

    Replace <value> with a desired value.

    sudo sysctl -w vm.dirty_writeback_centisecs=<value>

dirty_expire_centisecs

The periodic writeback task selectively performs writeback operations and targets only timed-out dirty pages. If dirty pages are still available in a file a specific period of time after the first dirty page is written to the file, the file is deemed to have timed out. The periodic writeback task performs writeback on these timed-out dirty pages.

The /proc/sys/vm/dirty_writeback_centisecs parameter specifies the timeout period. Unit: centiseconds. Default value: 3,000, which is equal to 30 seconds.

  • Query the dirty_expire_centisecs parameter.

    sysctl -n vm.dirty_expire_centisecs
  • Set the dirty_expire_centisecs parameter.

    sudo sysctl -w vm.dirty_expire_centisecs=<value>