Skip to content

Commit 7ef6ece

Browse files
committed
Fix setting swaplimit=true without checking
Signed-off-by: Jakub Guzik <[email protected]>
1 parent a773178 commit 7ef6ece

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

pkg/sysinfo/cgroup2_linux.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
22

33
import (
44
"io/ioutil"
5+
"os"
56
"path"
67
"strings"
78

89
cgroupsV2 "github.com/containerd/cgroups/v2"
910
"github.com/containerd/containerd/sys"
11+
"github.com/opencontainers/runc/libcontainer/cgroups"
1012
"github.com/sirupsen/logrus"
1113
)
1214

@@ -66,6 +68,24 @@ func newV2(quiet bool, opts *opts) *SysInfo {
6668
return sysInfo
6769
}
6870

71+
func getSwapLimitV2() bool {
72+
groups, err := cgroups.ParseCgroupFile("/proc/self/cgroup")
73+
if err != nil {
74+
return false
75+
}
76+
77+
g := groups[""]
78+
if g == "" {
79+
return false
80+
}
81+
82+
cGroupPath := path.Join("/sys/fs/cgroup", g, "memory.swap.max")
83+
if _, err = os.Stat(cGroupPath); os.IsNotExist(err) {
84+
return false
85+
}
86+
return true
87+
}
88+
6989
func applyMemoryCgroupInfoV2(info *SysInfo, controllers map[string]struct{}, _ string) []string {
7090
var warnings []string
7191
if _, ok := controllers["memory"]; !ok {
@@ -74,7 +94,7 @@ func applyMemoryCgroupInfoV2(info *SysInfo, controllers map[string]struct{}, _ s
7494
}
7595

7696
info.MemoryLimit = true
77-
info.SwapLimit = true
97+
info.SwapLimit = getSwapLimitV2()
7898
info.MemoryReservation = true
7999
info.OomKillDisable = false
80100
info.MemorySwappiness = false

0 commit comments

Comments
 (0)