• New Conversion from cgroup v1 CPU Shares to v2 CPU Weight I’m excited to announce the implementation of an improved conversion formula from cgroup v1 CPU shares to cgroup v2 CPU weight. • This enhancement addresses critical issues with CPU priority allocation for Kubernetes workloads when running on systems with cgroup v2. • Background Kubernetes was originally designed with cgroup v1 in mind, where CPU shares were defined simply by assigning the container’s CPU requests in millicpu form. • For example, a container requesting 1 CPU (1024m) would get (cpu.shares = 1024). • After a while, cgroup v1 started being replaced by its successor, cgroup v2. • In cgroup v2, the concept of CPU shares (which ranges from 2 to 262144, or from 2¹ to 2¹⁸) was replaced with CPU weight (which ranges from [1, 10000], or 10⁰ to 10⁴).

Article Summaries:

  • A new conversion formula has been released to map cgroup v1 CPU shares to cgroup v2 CPU weight, addressing shortcomings in Kubernetes’ earlier approach. The original linear mapping (cpu.weight = 1 + ((cpu.shares‑2) × 9999)/262142) produced low weights for typical workloads, reducing Kubernetes containers’ priority relative to non‑Kubernetes processes and limiting sub‑cgroup granularity. The updated quadratic formula now aligns key points-(2, 1), (1024, 100), and (262144, 10000)-providing a more accurate and granular translation of CPU requests from v1 to v2. This change improves priority handling and fine‑grained resource allocation for Kubernetes workloads on cgroup v2 systems.

Sources: