Course contentsShow
← Linux
Lesson 1553 of 1,81913. Containerization Primitives and NamespacesFree lesson

Analyzing Kernel Scheduler Priorities

Observe how cgroup priorities map to the CFS (Completely Fair Scheduler) entity logic.

In this lesson, you will learn how cgroup CPU shares are translated into weight values within the Completely Fair Scheduler (CFS) to determine task priority.

From Cgroups to CFS Weights

When you manage container performance, you often interact with cpu.shares in the cgroup v1 hierarchy (or cpu.weight in cgroup v2). However, the CFS doesn't natively "understand" a cgroup share value; it operates on the concept of se.load.weight.

The scheduler maintains a mapping between the abstract cgroup priority and the internal sched_entity structure. When a process inside a container is scheduled, the kernel scales the cgroup’s weight against the total weight of all runnable entities in the same runqueue. This value determines the process's vruntime (virtual runtime) progression rate. A higher weight means the vruntime increments more slowly, keeping the task "fairly" behind others for a longer period of its timeslice.

Examining the Mapping

You can observe how these priorities manifest in the kernel’s internal logic by inspecting the sched_entity struct via drgn or by analyzing the procfs interface. Each CFS task maintains a load.weight. To see the default mapping, the kernel uses a table where a nice value of 0 is equivalent to a weight of 1024.

If you set a cgroup share to 512, the CFS adjusts the load.weight of the group’s scheduling entities proportionally. You can visualize this relationship by examining the sched file for a specific PID:

# Observe the CFS priority settings for a specific process
cat /proc/[pid]/sched | grep -E "se.load.weight|se.vruntime"

The se.load.weight value you see here is the result of the kernel’s calculation, merging the cgroup's constraint with the task's individual nice value. When the scheduler decides which task to run next, it picks the task with the smallest vruntime—the value that represents the "cost" of the time the process has already consumed, adjusted by its weight. By increasing a container's shares, you are essentially increasing its weight, which slows the accumulation of its vruntime relative to other containers on the same CPU.

Key Takeaway: Cgroup priorities act as multipliers for the CFS load.weight, which dictates how slowly a task’s vruntime grows, ultimately granting it more time on the CPU.