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

runc update: fix updating swap for cgroup v2 #4357

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Jul 22, 2024

This allows to do

runc update $ID --memory=-1 --memory-swap=$VAL

for cgroup v2, i.e. set memory to unlimited and swap to a specific value.

This was not possible because ConvertMemorySwapToCgroupV2Value rejected memory=-1 ("unlimited"). In a hindsight, it was a mistake, because if memory limit is unlimited, we should treat memory+swap limit as just swap limit.

While at it, improve some comments in the code, and revise the unit test.

Fixes: c86be8a ("cgroupv2: fix setting MemorySwap") aka #2288

@kolyshkin kolyshkin marked this pull request as ready for review July 22, 2024 20:22
Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly LGTM. Left some comments, mainly about tests.

On a quick look, it seems crun does the same: https://github.com/containers/crun/blob/main/src/libcrun/cgroup-resources.c#L711

libcontainer/cgroups/utils.go Outdated Show resolved Hide resolved
libcontainer/cgroups/utils_test.go Show resolved Hide resolved
Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

I slightly prefer the version with two ifs, but this is clear anyways, it is a nit.

@kolyshkin kolyshkin force-pushed the update-swap-v2 branch 2 times, most recently from e1acf39 to 707ee6d Compare September 12, 2024 22:39
@kolyshkin
Copy link
Contributor Author

For ease of review, I've split this into two commits.

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin thanks for splitting in 2 commits, it makes it really straight-forward to review :)

@kolyshkin kolyshkin added the backport/1.2-todo A PR in main branch which needs to be backported to release-1.2 label Oct 23, 2024
Improve readability of ConvertMemorySwapToCgroupV2Value by switching
from a bunch of if statements to a switch, and adding a comment
describing each case.

No functional change.

Signed-off-by: Kir Kolyshkin <[email protected]>
This allows to do

	runc update $ID --memory=-1 --memory-swap=$VAL

for cgroup v2, i.e. set memory to unlimited and swap to a specific
value.

This was not possible because ConvertMemorySwapToCgroupV2Value rejected
memory=-1 ("unlimited"). In a hindsight, it was a mistake, because if
memory limit is unlimited, we should treat memory+swap limit as just swap
limit.

Revise the unit test; add description to each case.

Fixes: c86be8a ("cgroupv2: fix setting MemorySwap")
Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin
Copy link
Contributor Author

@AkihiroSuda @lifubang this is a fix that did not made its way into v1.2.0. I would still like to merge it and then open a backport to release-1.2 branch.

@kolyshkin kolyshkin added this to the 1.2.1 milestone Oct 29, 2024
@rata rata mentioned this pull request Nov 1, 2024
@AkihiroSuda AkihiroSuda merged commit 519a3f1 into opencontainers:main Nov 1, 2024
42 checks passed
@AkihiroSuda AkihiroSuda added backport/1.2-done A PR in main branch which has been backported to release-1.2 and removed backport/1.2-todo A PR in main branch which needs to be backported to release-1.2 labels Nov 1, 2024
@kolyshkin kolyshkin removed this from the 1.2.1 milestone Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.2-done A PR in main branch which has been backported to release-1.2 kind/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants