Fix some cases of swap setting#2426
Merged
Merged
Conversation
Contributor
Author
|
@lifubang @cyphar @AkihiroSuda PTAL |
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>
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>
Contributor
Author
Contributor
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_bytesto -1 ifmemory.memsw.limit_in_bytesisnot 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.