Skip to content

Commit

Permalink
cgroupv2: set MemorySwapMax= for systemd
Browse files Browse the repository at this point in the history
While at it, if a memory is unlimited, set swap to unlimited, too,
to be in line with the cgroupv1 runc behavior. For background,
see commit 18ebc51 (Reset Swap when memory is set to unlimited,
Oct 19 2016).

NB: systemd does not have MemorySwapMax for cgroupv1.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Apr 2, 2020
1 parent e3e26ca commit fe9d4c2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libcontainer/cgroups/systemd/unified_hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ func (m *UnifiedManager) Apply(pid int) error {
if c.Resources.Memory != 0 {
properties = append(properties,
newProp("MemoryMax", uint64(c.Resources.Memory)))
// If memory is unlimited, set mem+swap to unlimited, too
if c.Resources.Memory == -1 {
c.Resources.MemorySwap = -1
}
}

if c.Resources.MemorySwap != 0 {
properties = append(properties,
newProp("MemorySwapMax", uint64(c.Resources.MemorySwap)))
}

if c.Resources.CpuWeight != 0 {
Expand Down

0 comments on commit fe9d4c2

Please sign in to comment.