Skip to content

Commit

Permalink
Merge pull request #2837 from giuseppe/mem-fixes-cgroupv2
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankgb authored Mar 26, 2021
2 parents 291c215 + 7bd9ea7 commit 4765480
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions container/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package common
import (
"fmt"
"io/ioutil"
"math"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -50,25 +50,6 @@ func DebugInfo(watches map[string][]string) map[string][]string {
return out
}

// findFileInAncestorDir returns the path to the parent directory that contains the specified file.
// "" is returned if the lookup reaches the limit.
func findFileInAncestorDir(current, file, limit string) (string, error) {
for {
fpath := path.Join(current, file)
_, err := os.Stat(fpath)
if err == nil {
return current, nil
}
if !os.IsNotExist(err) {
return "", err
}
if current == limit {
return "", nil
}
current = filepath.Dir(current)
}
}

var bootTime = func() time.Time {
now := time.Now()
var sysinfo unix.Sysinfo_t
Expand Down Expand Up @@ -165,11 +146,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
spec.Memory.Reservation = readUInt64(memoryRoot, "memory.soft_limit_in_bytes")
}
} else {
memoryRoot, err := findFileInAncestorDir(memoryRoot, "memory.max", "/sys/fs/cgroup")
if err != nil {
return spec, err
}
if memoryRoot != "" {
if utils.FileExists(path.Join(memoryRoot, "memory.max")) {
spec.HasMemory = true
spec.Memory.Reservation = readUInt64(memoryRoot, "memory.high")
spec.Memory.Limit = readUInt64(memoryRoot, "memory.max")
Expand Down Expand Up @@ -226,7 +203,10 @@ func readString(dirpath string, file string) string {

func readUInt64(dirpath string, file string) uint64 {
out := readString(dirpath, file)
if out == "" || out == "max" {
if out == "max" {
return math.MaxUint64
}
if out == "" {
return 0
}

Expand Down

0 comments on commit 4765480

Please sign in to comment.