let runc disable swap in cgroup v2#2370
Merged
Merged
Conversation
1f6b8a5 to
b857d40
Compare
kolyshkin
reviewed
May 2, 2020
| } | ||
| if val := numToStr(swap); val != "" { | ||
| // When we set `swap`, we should let us set `memory.swap.max` to 0 | ||
| if swap == 0 && cgroup.Resources.MemorySwap > 0 { |
Contributor
There was a problem hiding this comment.
I would change the comment to something like
// memory and memorySwap set to the same value -- disable swap
Contributor
There was a problem hiding this comment.
and rewrite the whole block to avoid mentioning fscommon.WriteFile(dirPath, "memory.swap.max" twice.
For example
swapStr := numToStr(swap)
if swapStr == "" && swap == 0 && cgroup.Resources.MemorySwap > 0 {
// memory and memorySwap set to the same value -- disable swap
swapStr = "0"
}
if err := fscommon.WriteFile(dirPath, "memory.swap.max", swapStr); err != nil {
return err
}
kolyshkin
reviewed
May 2, 2020
| } | ||
| if swap > 0 { | ||
| // When we set `swap`, we should let us set `MemorySwapMax` to 0 | ||
| if (c.Resources.MemorySwap > 0 && swap >= 0) || swap == -1 { |
Contributor
There was a problem hiding this comment.
I would do
if (c.Resources.MemorySwap != 0) { // limit is set
 swap, err := cgroups.ConvertMemorySwapToCgroupV2Value(c.Resources.MemorySwap, c.Resources.Memory)
 if err != nil {
 return nil, err
 }
properties = append(properties,
 newProp("MemorySwapMax", uint64(swap)))
 }
}
Contributor
|
The commit should also include - return 0, errors.New("memory+swap limit should be > memory limit")
+ return 0, errors.New("memory+swap limit should be >= memory limit") |
Contributor
|
and if you can copy-paste the description from #2369 into the commit message, so it would be possible to find out what's going out by just reading git log, without going to github, that'd be great! |
In cgroup v2, when memory and memorySwap set to the same value which is greater than zero, runc should write zero in `memory.swap.max` to disable swap. Signed-off-by: lifubang <lifubang@acmcoder.com>
Contributor
Contributor
|
@AkihiroSuda @mrunalp PTAL |
Contributor
This was referenced May 10, 2020
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.
fix #2369
I think we should let cgroup fs/systemd driver can use 0 to disable memory swap in cgroup v2.
Signed-off-by: lifubang lifubang@acmcoder.com