Skip to content

Commit

Permalink
simplify memory limit check
Browse files Browse the repository at this point in the history
If memory cgroup is mounted, memory limit is always supported,
no need to check if these files are exist.

Signed-off-by: Qiang Huang <[email protected]>
  • Loading branch information
hqhq committed Apr 24, 2015
1 parent 47e5acf commit 667b1e2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions pkg/sysinfo/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ func New(quiet bool) *SysInfo {
sysInfo := &SysInfo{}
if cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint("memory"); err != nil {
if !quiet {
logrus.Warnf("%v", err)
logrus.Warnf("Your kernel does not support cgroup memory limit: %v", err)
}
} else {
_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.limit_in_bytes"))
_, err2 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.soft_limit_in_bytes"))
sysInfo.MemoryLimit = err1 == nil && err2 == nil
if !sysInfo.MemoryLimit && !quiet {
logrus.Warn("Your kernel does not support cgroup memory limit.")
}
// If memory cgroup is mounted, MemoryLimit is always enabled.
sysInfo.MemoryLimit = true

_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes"))
sysInfo.SwapLimit = err == nil
_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes"))
sysInfo.SwapLimit = err1 == nil
if !sysInfo.SwapLimit && !quiet {
logrus.Warn("Your kernel does not support cgroup swap limit.")
logrus.Warn("Your kernel does not support swap memory limit.")
}
}

Expand Down

0 comments on commit 667b1e2

Please sign in to comment.