-
Notifications
You must be signed in to change notification settings - Fork 2.2k
define MemoryUnlimited const for users #1422
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,14 +104,12 @@ func setKernelMemory(path string, kernelMemoryLimit uint64) error { | |
| } | ||
|
|
||
| func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error { | ||
| ulimited := -1 | ||
|
|
||
| // If the memory update is set to uint64(-1) we should also | ||
| // set swap to uint64(-1), it means unlimited memory. | ||
| if cgroup.Resources.Memory == uint64(ulimited) { | ||
| // If the memory update is set to MemoryUnlimited we should also | ||
| // set swap to MemoryUnlimited. | ||
| if cgroup.Resources.Memory == configs.MemoryUnlimited { | ||
| // Only set swap if it's enbled in kernel | ||
| if cgroups.PathExists(filepath.Join(path, cgroupMemorySwapLimit)) { | ||
| cgroup.Resources.MemorySwap = uint64(ulimited) | ||
| cgroup.Resources.MemorySwap = uint64(configs.MemoryUnlimited) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -126,7 +124,7 @@ func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error { | |
| // When update memory limit, we should adapt the write sequence | ||
| // for memory and swap memory, so it won't fail because the new | ||
| // value and the old value don't fit kernel's validation. | ||
| if cgroup.Resources.MemorySwap == uint64(ulimited) || memoryUsage.Limit < cgroup.Resources.MemorySwap { | ||
| if cgroup.Resources.MemorySwap == uint64(configs.MemoryUnlimited) || memoryUsage.Limit < cgroup.Resources.MemorySwap { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as the above, casting is not necessary. |
||
| if err := writeFile(path, cgroupMemorySwapLimit, strconv.FormatUint(cgroup.Resources.MemorySwap, 10)); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ | |
|
|
||
| package configs | ||
|
|
||
| import ( | ||
| "math" | ||
| ) | ||
|
|
||
| type FreezerState string | ||
|
|
||
| const ( | ||
|
|
@@ -33,6 +37,8 @@ type Cgroup struct { | |
| *Resources | ||
| } | ||
|
|
||
| const MemoryUnlimited = math.MaxUint64 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the value that is actually used by the kernel, which is 9223372036854771712. Some older kernels will set any value larger than this to 0, and then crash, eg RHEL 7.2.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this value may well be totally incorrect on 32 bit machines, not sure what happens there. |
||
|
|
||
| type Resources struct { | ||
| // If this is true allow access to any kind of device within the container. If false, allow access only to devices explicitly listed in the allowed_devices list. | ||
| // Deprecated | ||
|
|
@@ -50,7 +56,7 @@ type Resources struct { | |
| // Memory reservation or soft_limit (in bytes) | ||
| MemoryReservation uint64 `json:"memory_reservation"` | ||
|
|
||
| // Total memory usage (memory + swap); set `-1` to enable unlimited swap | ||
| // Total memory usage (memory + swap); set MemoryUnlimited to enable unlimited swap | ||
| MemorySwap uint64 `json:"memory_swap"` | ||
|
|
||
| // Kernel memory limit (in bytes) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you dont need to cast this to uint64 anymore