mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix setting swaplimit=true without checking
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
(cherry picked from commit 7ef6ece774
)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
parent
b0f5bc36fe
commit
a57fc0eb15
1 changed files with 21 additions and 1 deletions
|
@ -2,11 +2,13 @@ package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
cgroupsV2 "github.com/containerd/cgroups/v2"
|
cgroupsV2 "github.com/containerd/cgroups/v2"
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,6 +68,24 @@ func newV2(quiet bool, opts *opts) *SysInfo {
|
||||||
return sysInfo
|
return sysInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSwapLimitV2() bool {
|
||||||
|
groups, err := cgroups.ParseCgroupFile("/proc/self/cgroup")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
g := groups[""]
|
||||||
|
if g == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
cGroupPath := path.Join("/sys/fs/cgroup", g, "memory.swap.max")
|
||||||
|
if _, err = os.Stat(cGroupPath); os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func applyMemoryCgroupInfoV2(info *SysInfo, controllers map[string]struct{}, _ string) []string {
|
func applyMemoryCgroupInfoV2(info *SysInfo, controllers map[string]struct{}, _ string) []string {
|
||||||
var warnings []string
|
var warnings []string
|
||||||
if _, ok := controllers["memory"]; !ok {
|
if _, ok := controllers["memory"]; !ok {
|
||||||
|
@ -74,7 +94,7 @@ func applyMemoryCgroupInfoV2(info *SysInfo, controllers map[string]struct{}, _ s
|
||||||
}
|
}
|
||||||
|
|
||||||
info.MemoryLimit = true
|
info.MemoryLimit = true
|
||||||
info.SwapLimit = true
|
info.SwapLimit = getSwapLimitV2()
|
||||||
info.MemoryReservation = true
|
info.MemoryReservation = true
|
||||||
info.OomKillDisable = false
|
info.OomKillDisable = false
|
||||||
info.MemorySwappiness = false
|
info.MemorySwappiness = false
|
||||||
|
|
Loading…
Reference in a new issue