1
0
mirror of https://github.com/containers/youki synced 2024-11-23 17:32:15 +01:00

Merge pull request #291 from utam0k/fix/cargo-clippy-warn

fix cargo clippy warning in cgroups
This commit is contained in:
Furisto 2021-09-10 17:06:04 +02:00 committed by GitHub
commit 4878662516
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

@ -100,19 +100,22 @@ impl Memory {
// -1 means max // -1 means max
if swap == -1 || limit == -1 { if swap == -1 || limit == -1 {
Memory::set(path.join(CGROUP_MEMORY_SWAP), swap)?; Memory::set(path.join(CGROUP_MEMORY_SWAP), swap)?;
Memory::set(path.join(CGROUP_MEMORY_MAX), limit)?;
} else { } else {
if swap < limit { if swap < limit {
bail!("swap memory ({}) should be bigger than memory limit ({})", swap, limit); bail!(
"swap memory ({}) should be bigger than memory limit ({})",
swap,
limit
);
} }
// In cgroup v1 swap is memory+swap, but in cgroup v2 swap is // In cgroup v1 swap is memory+swap, but in cgroup v2 swap is
// a separate value, so the swap value in the runtime spec needs // a separate value, so the swap value in the runtime spec needs
// to be converted from the cgroup v1 value to the cgroup v2 value // to be converted from the cgroup v1 value to the cgroup v2 value
// by subtracting limit from swap // by subtracting limit from swap
Memory::set(path.join(CGROUP_MEMORY_SWAP), swap - limit)?; Memory::set(path.join(CGROUP_MEMORY_SWAP), swap - limit)?;
Memory::set(path.join(CGROUP_MEMORY_MAX), limit)?; }
} Memory::set(path.join(CGROUP_MEMORY_MAX), limit)?;
} }
None => { None => {
if limit == -1 { if limit == -1 {
@ -331,7 +334,7 @@ mod tests {
swap_content == swap.to_string() swap_content == swap.to_string()
} else { } else {
swap_content == (swap - linux_memory.limit.unwrap()).to_string() swap_content == (swap - linux_memory.limit.unwrap()).to_string()
} }
} else { } else {
false false
} }