Skip to content

Commit 4765480

Browse files
authored
Merge pull request #2837 from giuseppe/mem-fixes-cgroupv2
2 parents 291c215 + 7bd9ea7 commit 4765480

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

container/common/helpers.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ package common
1717
import (
1818
"fmt"
1919
"io/ioutil"
20+
"math"
2021
"os"
2122
"path"
22-
"path/filepath"
2323
"strconv"
2424
"strings"
2525
"time"
@@ -50,25 +50,6 @@ func DebugInfo(watches map[string][]string) map[string][]string {
5050
return out
5151
}
5252

53-
// findFileInAncestorDir returns the path to the parent directory that contains the specified file.
54-
// "" is returned if the lookup reaches the limit.
55-
func findFileInAncestorDir(current, file, limit string) (string, error) {
56-
for {
57-
fpath := path.Join(current, file)
58-
_, err := os.Stat(fpath)
59-
if err == nil {
60-
return current, nil
61-
}
62-
if !os.IsNotExist(err) {
63-
return "", err
64-
}
65-
if current == limit {
66-
return "", nil
67-
}
68-
current = filepath.Dir(current)
69-
}
70-
}
71-
7253
var bootTime = func() time.Time {
7354
now := time.Now()
7455
var sysinfo unix.Sysinfo_t
@@ -165,11 +146,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
165146
spec.Memory.Reservation = readUInt64(memoryRoot, "memory.soft_limit_in_bytes")
166147
}
167148
} else {
168-
memoryRoot, err := findFileInAncestorDir(memoryRoot, "memory.max", "/sys/fs/cgroup")
169-
if err != nil {
170-
return spec, err
171-
}
172-
if memoryRoot != "" {
149+
if utils.FileExists(path.Join(memoryRoot, "memory.max")) {
173150
spec.HasMemory = true
174151
spec.Memory.Reservation = readUInt64(memoryRoot, "memory.high")
175152
spec.Memory.Limit = readUInt64(memoryRoot, "memory.max")
@@ -226,7 +203,10 @@ func readString(dirpath string, file string) string {
226203

227204
func readUInt64(dirpath string, file string) uint64 {
228205
out := readString(dirpath, file)
229-
if out == "" || out == "max" {
206+
if out == "max" {
207+
return math.MaxUint64
208+
}
209+
if out == "" {
230210
return 0
231211
}
232212

0 commit comments

Comments
 (0)