crun icon indicating copy to clipboard operation
crun copied to clipboard

change conversion from cgroup v1 to cgroup v2

Open giuseppe opened this issue 7 months ago • 0 comments
trafficstars

change the conversion formula from cgroup v1 to cgroup v2: https://github.com/systemd/systemd/blob/5da476ac7728b91ad3a49c1b126b3559b4fbeed8/src/core/cgroup.c#L1598-L1611

static uint64_t cgroup_cpu_shares_to_weight(uint64_t shares) {
        return CLAMP(shares * CGROUP_WEIGHT_DEFAULT / CGROUP_CPU_SHARES_DEFAULT,
                     CGROUP_WEIGHT_MIN, CGROUP_WEIGHT_MAX);
}

static uint64_t cgroup_cpu_weight_to_shares(uint64_t weight) {
        /* we don't support idle in cgroupv1 */
        if (weight == CGROUP_WEIGHT_IDLE)
                return CGROUP_CPU_SHARES_MIN;

        return CLAMP(weight * CGROUP_CPU_SHARES_DEFAULT / CGROUP_WEIGHT_DEFAULT,
                     CGROUP_CPU_SHARES_MIN, CGROUP_CPU_SHARES_MAX);
}

Reference: https://github.com/kubernetes/kubernetes/issues/131216

giuseppe avatar Apr 15 '25 19:04 giuseppe