Skip to content

Commit

Permalink
driver/exec: set soft memory limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Mar 30, 2021
1 parent 750e665 commit 43549b4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/shared/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,21 +683,23 @@ func configureCgroups(cfg *lconfigs.Config, command *ExecCommand) error {
}

// Total amount of memory allowed to consume
var memoryLimit int64
if res := command.Resources.NomadResources.Memory; res.MemoryMaxMB > 0 {
memoryLimit = res.MemoryMaxMB * 1024 * 1024
} else if res.MemoryMB > 0 {
memoryLimit = res.MemoryMB * 1024 * 1024
res := command.Resources.NomadResources
memHard, memSoft := res.Memory.MemoryMaxMB, res.Memory.MemoryMB
if memHard <= 0 {
memHard = res.Memory.MemoryMB
memSoft = 0
}
if memoryLimit > 0 {
cfg.Cgroups.Resources.Memory = memoryLimit

if memHard > 0 {
cfg.Cgroups.Resources.Memory = memHard * 1024 * 1024
cfg.Cgroups.Resources.MemoryReservation = memSoft * 1024 * 1024

// Disable swap to avoid issues on the machine
var memSwappiness uint64
cfg.Cgroups.Resources.MemorySwappiness = &memSwappiness
}

cpuShares := command.Resources.NomadResources.Cpu.CpuShares
cpuShares := res.Cpu.CpuShares
if cpuShares < 2 {
return fmt.Errorf("resources.Cpu.CpuShares must be equal to or greater than 2: %v", cpuShares)
}
Expand Down

0 comments on commit 43549b4

Please sign in to comment.