All Products
Search
Document Center

Alibaba Cloud Linux:Enable the CPU burst feature for cgroup v1

Last Updated:Nov 20, 2024

The CPU burst feature allows CPU-throttled containers to burst their CPU usage to achieve higher container performance and lower system latency. Alibaba Cloud Linux 2 starting with kernel version 4.19.91-22.al7 and Alibaba Cloud Linux 3 provide the CPU burst feature for cgroup v1. This topic describes how to enable the CPU burst feature for cgroup v1 and how to query CPU burst statistics.

Note

For information about the CPU burst feature, see Kill the Annoying CPU Throttling.

Enable the CPU burst feature

  1. To check whether the CPU burst feature is globally enabled for cgroup v1, run the following command:

    cat /proc/sys/kernel/sched_cfs_bw_burst_enabled

    Description about the command output:

    • If the CPU burst feature is globally enabled, 1 is returned.

      Note

      By default, the CPU burst feature is globally enabled for cgroup v1.

    • If the CPU burst feature is globally disabled, a value other than 1 is returned.

      To globally enable the CPU burst feature for cgroup v1, run the following command:

      sudo sh -c 'echo 1 > /proc/sys/kernel/sched_cfs_bw_burst_enabled'
  2. Enable the CPU burst feature for a specific child cgroup.

    Note

    By default, the CPU burst feature is disabled for all child cgroups of cgroup v1.

    1. To go to the path of a child cgroup and check whether the CFS bandwidth controller has taken effect, run the following commands:

      Replace <cgroup> with the directory of a child cgroup.

      cd /sys/fs/cgroup/cpu/<cgroup>/
      cat cpu.cfs_period_us
      cat cpu.cfs_quota_us

      If the CFS bandwidth controller has taken effect, a positive integer is returned for cat cpu.cfs_quota_us in the command output. In this case, you can enable the CPU burst feature to allow containers to utilize CPU resources beyond the specified limit.

    2. To view the default CPU burst settings, run the following command:

      cat cpu.cfs_burst_us

      If the CPU burst feature is disabled, a default value of 0 is returned in the command output.

    3. Configure cpu.cfs_burst_us to enable the CPU burst feature.

      You can set cpu.cfs_burst_us to a positive integer to enable the CPU burst feature and use this integer as the CPU burst limit. The following operations provide an example of how to enable the CPU burst feature:

      1. Configure the default cpu.cfs_quota_us and cpu.cfs_period_us files for the CFS bandwidth controller.

        cpu.cfs_period_us specifies the period during which CPU resources are utilized. cpu.cfs_quota_us specifies the maximum amount of CPU resources that each child cgroup can utilize during each period specified by cpu.cfs_period_us. Run the following commands to set cpu.cfs_period_us to 100 ms and cpu.cfs_quota_us to 400 ms to ensure that each child cgroup continues to obtain four CPU resources, which is calculated by using the following formula: cpu.cfs_quota_us/cpu.cfs_period_us.

        sudo sh -c 'echo 400000 > cpu.cfs_quota_us'
        sudo sh -c 'echo 100000 > cpu.cfs_period_us'
      2. Configure cpu.cfs_burst_us to enable the CPU burst feature.

        Run the following command to set cpu.cfs_burst_us to 600 ms to enable the CPU burst feature and allow each child cgroup to utilize up to six CPU resources above the CPU limit. This value is calculated by using the following formula: cpu.cfs_burst_us/cpu.cfs_period_us.

        sudo sh -c 'echo 600000 > cpu.cfs_burst_us'

Query CPU burst statistics

To go to the path of a child cgroup and view CPU burst statistics, run the following commands.

Replace <cgroup> with the directory of a child cgroup.

cd /sys/fs/cgroup/cpu/<cgroup>/
cat cpu.stat

Parameters in the command output:

  • nr_burst: the number of CPU bursts triggered by the child cgroup.

  • burst_time: the cumulative length of CPU burst time for the child cgroup.