Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cargo clippy warning in cgroups #291

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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