Skip to content

Commit

Permalink
Merge pull request #291 from utam0k/fix/cargo-clippy-warn
Browse files Browse the repository at this point in the history
fix cargo clippy warning in cgroups
  • Loading branch information
Furisto committed Sep 10, 2021
2 parents 7c0c4a7 + f349cdb commit 4878662
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cgroups/src/v2/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@ impl Memory {
// -1 means max
if swap == -1 || limit == -1 {
Memory::set(path.join(CGROUP_MEMORY_SWAP), swap)?;
Memory::set(path.join(CGROUP_MEMORY_MAX), limit)?;
} else {
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
// 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
// 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
// by subtracting limit from swap
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 => {
if limit == -1 {
Expand Down Expand Up @@ -331,7 +334,7 @@ mod tests {
swap_content == swap.to_string()
} else {
swap_content == (swap - linux_memory.limit.unwrap()).to_string()
}
}
} else {
false
}
Expand Down

0 comments on commit 4878662

Please sign in to comment.