The SCHED_IDLE feature of cgroups

更新时间:
复制 MD 格式

When running mixed workloads—latency-sensitive services alongside background batch jobs—you need a way to deprioritize the batch cgroup so it consumes CPU only when no higher-priority peers need it. Alibaba Cloud Linux 3 provides the cpu.idle interface, the cgroup-level analog of the per-task SCHED_IDLE scheduling policy. Set cpu.idle to 1 on a cgroup to mark it as idle-priority: the cgroup competes for CPU only when no non-idle peers are runnable. This feature requires kernel version 5.10.134-16.al8 or later.

Interface file location

The cpu.idle interface file location depends on the cgroup version:

cgroup version Path
cgroup v1 /sys/fs/cgroup/cpu/$cg
cgroup v2 /sys/fs/cgroup/$cg

$cg is a placeholder for the cgroup name.

Enable or disable SCHED_IDLE for a cgroup

Interface Value Effect
cpu.idle 0 Disables the SCHED_IDLE scheduling policy for the cgroup.
1 Enables the SCHED_IDLE scheduling policy for the cgroup. The cgroup receives the minimum time slice weight and is no longer guaranteed a minimum runtime.

Limitations

Enabling SCHED_IDLE (setting cpu.idle to 1) has the following side effects due to incompatibilities between cgroup versions and the SCHED_IDLE policy:

cgroup version Limitation
cgroup v1 The cpu.shares interface cannot be overridden.
cgroup v2 The cpu.weight and cpu.weight.nice interfaces cannot be overridden.