Skip to content

Commit

Permalink
cgroup: add fallback to io.weight
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
giuseppe committed Jul 9, 2022
1 parent ba3cb60 commit 639c98f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions crun.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crun.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
30 changes: 27 additions & 3 deletions src/libcrun/cgroup-resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 639c98f

Please sign in to comment.