When setting a memory limit, also set a swap limit

Closes #940

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #946
Approved by: rhatdan
This commit is contained in:
Matthew Heon 2018-06-14 14:17:45 -04:00 committed by Atomic Bot
parent 8f1b7be275
commit 4b4de5dc21
1 changed files with 5 additions and 0 deletions

View File

@ -74,6 +74,11 @@ func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint
// RESOURCES - MEMORY
if config.Resources.Memory != 0 {
g.SetLinuxResourcesMemoryLimit(config.Resources.Memory)
// If a swap limit is not explicitly set, also set a swap limit
// Default to double the memory limit
if config.Resources.MemorySwap == 0 {
g.SetLinuxResourcesMemorySwap(2 * config.Resources.Memory)
}
}
if config.Resources.MemoryReservation != 0 {
g.SetLinuxResourcesMemoryReservation(config.Resources.MemoryReservation)