Skip to content

Commit

Permalink
rustjail: fix blkio conversion
Browse files Browse the repository at this point in the history
BFQ weight controller is using the same BFQ weight scheme (i.e 1->1000).
Therefore, there is no need to do the conversion.

More details here: opencontainers/runc#2786

Fixes: kata-containers#1440

Signed-off-by: Manabu Sugimoto <[email protected]>
  • Loading branch information
ManaSugi authored and bergwolf committed Feb 25, 2021
1 parent 7957b1b commit f866e55
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions src/agent/rustjail/src/cgroups/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,37 +320,23 @@ fn set_hugepages_resources(
}

fn set_block_io_resources(
cg: &cgroups::Cgroup,
_cg: &cgroups::Cgroup,
blkio: &LinuxBlockIO,
res: &mut cgroups::Resources,
) -> Result<()> {
info!(sl!(), "cgroup manager set block io");
res.blkio.update_values = true;

if cg.v2() {
res.blkio.weight = convert_blk_io_to_v2_value(blkio.weight);
res.blkio.leaf_weight = convert_blk_io_to_v2_value(blkio.leaf_weight);
} else {
res.blkio.weight = blkio.weight;
res.blkio.leaf_weight = blkio.leaf_weight;
}
res.blkio.weight = blkio.weight;
res.blkio.leaf_weight = blkio.leaf_weight;

let mut blk_device_resources = vec![];
for d in blkio.weight_device.iter() {
let (w, lw) = if cg.v2() {
(
convert_blk_io_to_v2_value(blkio.weight),
convert_blk_io_to_v2_value(blkio.leaf_weight),
)
} else {
(blkio.weight, blkio.leaf_weight)
};

let dr = BlkIoDeviceResource {
major: d.blk.major as u64,
minor: d.blk.minor as u64,
weight: w,
leaf_weight: lw,
weight: blkio.weight,
leaf_weight: blkio.leaf_weight,
};
blk_device_resources.push(dr);
}
Expand Down Expand Up @@ -1149,20 +1135,6 @@ fn convert_memory_swap_to_v2_value(memory_swap: i64, memory: i64) -> Result<i64>
Ok(memory_swap - memory)
}

// Since the OCI spec is designed for cgroup v1, in some cases
// there is need to convert from the cgroup v1 configuration to cgroup v2
// the formula for BlkIOWeight is y = (1 + (x - 10) * 9999 / 990)
// convert linearly from [10-1000] to [1-10000]
// https://github.com/opencontainers/runc/blob/a5847db387ae28c0ca4ebe4beee1a76900c86414/libcontainer/cgroups/utils.go#L382
fn convert_blk_io_to_v2_value(blk_io_weight: Option<u16>) -> Option<u16> {
let v = blk_io_weight.unwrap_or(0);
if v != 0 {
return None;
}

Some(1 + (v - 10) * 9999 / 990 as u16)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit f866e55

Please sign in to comment.