Skip to content

Fix some cases of swap setting#2426

Merged
AkihiroSuda merged 2 commits into
opencontainers:masterfrom
kolyshkin:mem-swap-unlim
May 26, 2020
Merged

Fix some cases of swap setting#2426
AkihiroSuda merged 2 commits into
opencontainers:masterfrom
kolyshkin:mem-swap-unlim

Conversation

@kolyshkin
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin commented May 20, 2020

This fixes two nuances in memory+swap update handling, and finally enables cgroupv2 swap checks in tests/integration/update.bats.

cgroupv1: don't ignore MemorySwap if Memory==-1

Commit 18ebc51b3cc3 "Reset Swap when memory is set to unlimited (-1)"
(see PR #1127) added handling of the case when a user updates the container
limits to set memory to unlimited (-1) but do not set any other limits.
Apparently, in this case, if swap limit was previously set, kernel fails
to set memory.limit_in_bytes to -1 if memory.memsw.limit_in_bytes is
not set to -1.

What the above commit fails to handle correctly is the request when
Memory is set to -1 and MemorySwap is set to some specific limit N
(where N > 0). In this case, the value of N is silently discarded
and MemorySwap is set to -1 instead.

This is wrong thing to do, as the limit set, even if incorrectly,
should not be ignored.

Fix this by only assigning MemorySwap == -1 in case it was not
explicitly set.

cgroupv2: set mem+swap to max if mem set to max

... and mem+swap is not explicitly set otherwise.

This ensures compatibility with cgroupv1 controller which interprets
things this way. Previous attempts to fix this: #2285, #2405.

With this fixed, we can finally enable swap tests for cgroupv2.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

@lifubang @cyphar @AkihiroSuda PTAL

@kolyshkin
Copy link
Copy Markdown
Contributor Author

rebased

Commit 18ebc51b3cc3 "Reset Swap when memory is set to unlimited (-1)"
added handling of the case when a user updates the container limits
to set memory to unlimited (-1) but do not set any other limits.
Apparently, in this case, if swap limit was previously set, kernel fails
to set memory.limit_in_bytes to -1 if memory.memsw.limit_in_bytes is
not set to -1.

What the above commit fails to handle correctly is the request when
Memory is set to -1 and MemorySwap is set to some specific limit N
(where N > 0). In this case, the value of N is silently discarded
and MemorySwap is set to -1 instead.

This is wrong thing to do, as the limit set, even if incorrectly,
should not be ignored.

Fix this by only assigning MemorySwap == -1 in case it was not
explicitly set.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Copy Markdown
Contributor Author

ah, got a typo while rebasing... fixed now

... and mem+swap is not explicitly set otherwise.

This ensures compatibility with cgroupv1 controller which interprets
things this way.

With this fixed, we can finally enable swap tests for cgroupv2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Copy Markdown
Contributor Author

kolyshkin commented May 23, 2020

@AkihiroSuda @mrunalp @lifubang PTAL

@mrunalp
Copy link
Copy Markdown
Contributor

mrunalp commented May 25, 2020

LGTM

Approved with PullApprove

@AkihiroSuda
Copy link
Copy Markdown
Member

AkihiroSuda commented May 26, 2020

LGTM

Approved with PullApprove

@AkihiroSuda AkihiroSuda merged commit 1f737ee into opencontainers:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants