From 639c98f5ad3b73358a41338b81f4af2fa7696f6e Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Sun, 10 Jul 2022 00:57:09 +0200 Subject: [PATCH] cgroup: add fallback to io.weight copy the same fallback runc has. If io.bfq.weight doesn't exist, then fallback to using io.weight with a conversion. Signed-off-by: Giuseppe Scrivano --- crun.1 | 6 ++++++ crun.1.md | 2 ++ src/libcrun/cgroup-resources.c | 30 +++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/crun.1 b/crun.1 index c9790165cf..a8bc0853d7 100644 --- a/crun.1 +++ b/crun.1 @@ -879,6 +879,12 @@ l l l l . \fB\fCOCI (x)\fR \fB\fCcgroup 2 value (y)\fR \fB\fCconversion\fR \fB\fCcomment\fR weight io.bfq.weight y = x weight_device io.bfq.weight y = x +weight io.weight (fallback) y = 1 + (x-10)*9999/990 T{ +convert linearly from [10-1000] to [1-10000] +T} +weight_device io.weight (fallback) y = 1 + (x-10)*9999/990 T{ +convert linearly from [10-1000] to [1-10000] +T} rbps io.max y=x wbps io.max y=x riops io.max y=x diff --git a/crun.1.md b/crun.1.md index e48cfd92e9..c4d2ca662e 100644 --- a/crun.1.md +++ b/crun.1.md @@ -676,6 +676,8 @@ they are converted when needed from the cgroup v1 configuration. |---|---|---|---| | weight | io.bfq.weight | y = x || | weight_device | io.bfq.weight | y = x || +| weight | io.weight (fallback) | y = 1 + (x-10)*9999/990 | convert linearly from [10-1000] to [1-10000] | +| weight_device | io.weight (fallback) | y = 1 + (x-10)*9999/990 | convert linearly from [10-1000] to [1-10000] | | rbps | io.max | y=x || | wbps | io.max | y=x || | riops | io.max |y=x || diff --git a/src/libcrun/cgroup-resources.c b/src/libcrun/cgroup-resources.c index eb5bb40a97..53c4f122fa 100644 --- a/src/libcrun/cgroup-resources.c +++ b/src/libcrun/cgroup-resources.c @@ -212,9 +212,33 @@ write_blkio_resources (int dirfd, bool cgroup2, runtime_spec_schema_config_linux uint32_t val = blkio->weight; len = sprintf (fmt_buf, "%" PRIu32, val); - ret = write_cgroup_file (dirfd, cgroup2 ? "io.bfq.weight" : "blkio.weight", fmt_buf, len, err); - if (UNLIKELY (ret < 0)) - return ret; + if (! cgroup2) + { + ret = write_cgroup_file (dirfd, "blkio.weight", fmt_buf, len, err); + if (UNLIKELY (ret < 0)) + return ret; + } + else + { + ret = write_cgroup_file (dirfd, "io.bfq.weight", fmt_buf, len, err); + if (UNLIKELY (ret < 0)) + { + if (crun_error_get_errno (err) == ENOENT) + { + crun_error_release (err); + + /* convert linearly from [10-1000] to [1-10000] */ + val = 1 + (val - 10) * 9999 / 990; + + len = sprintf (fmt_buf, "%" PRIu32, val); + + ret = write_cgroup_file (dirfd, "io.weight", fmt_buf, len, err); + } + + if (UNLIKELY (ret < 0)) + return ret; + } + } } if (blkio->leaf_weight) {