cgroup v1 to v2 Resource Converter
Moving a host or a container runtime from cgroup v1 to cgroup v2 changes the file that carries each limit: cpu.shares becomes cpu.weight, the quota and period pair becomes one cpu.max line, and memory.limit_in_bytes becomes memory.max. This page converts a value from one world to the other and shows exactly what to write. Everything runs locally.
Common cpu.shares values current and legacy mappings
| cpu.shares | weight (current) | weight (legacy) |
|---|
How the conversions work
cpu.shares → cpu.weight. Both knobs feed the same fair-scheduler weight, but the scales differ: v1 shares run from 2 to 262144 with a default of 1024, and v2 weight runs from 1 to 10000 with a default of 100. The mapping used by runc 1.3.2 and later and crun 1.23 and later is
cpu.weight = ⌈10^(L²/612 + 125L/612 − 7/34)⌉withL = log₂(cpu.shares). It is exact at the three anchors: 2 → 1, 1024 → 100 and 262144 → 10000, so a group at the v1 default keeps the v2 default priority.- The older KEP-2254 mapping is linear:
cpu.weight = 1 + ⌊(cpu.shares − 2) × 9999 / 262142⌋. It maps 1024 shares to only 39, well below the v2 default of 100, which is why it was replaced. - Weights are relative shares among runnable siblings, not a reservation or a cap. Sibling count, the cgroup hierarchy, sleeping patterns and
cpu.maxall change the CPU time a group actually receives.
cpu.cfs_quota_us + cpu.cfs_period_us → cpu.max. The v2 file folds the pair into one line, $MAX $PERIOD, in that order: the quota first, then the period. A quota of -1 means no limit and is written as max, so an unlimited group reads max 100000. The quota is CPU time in microseconds per period, aggregated across CPUs, so a quota twice the period allows two CPUs' worth of runtime.
memory.limit_in_bytes → memory.max. The number is the same byte count; only the file changes. The v1 sentinel -1 becomes the literal max. The combined memory-plus-swap limit has no single v2 counterpart: swap is limited separately through memory.swap.max.
Two smaller notes: pids.max keeps its name and range in v2, and a v1 cpu.rt_runtime_us bandwidth reservation has no per-cgroup v2 file. Check the value that the kernel actually reports before migrating: a runtime may already have translated its configuration.