-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix read "max" value for cgroup v2 #2837
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,9 +17,9 @@ package common | |||||
import ( | ||||||
"fmt" | ||||||
"io/ioutil" | ||||||
"math" | ||||||
"os" | ||||||
"path" | ||||||
"path/filepath" | ||||||
"strconv" | ||||||
"strings" | ||||||
"time" | ||||||
|
@@ -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 | ||||||
|
@@ -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") | ||||||
|
@@ -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" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have you decided to change behaviour for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course, my bad! |
||||||
return math.MaxUint64 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: The max value for cgroup v1 is 9223372036854771712 (max signed integer rounded to nearest page, at least on x86). So to be correct it should be something like this I guess:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with changing it, but would it be a problem with cgroup v1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember where this value is used, but I just thought it was nice with the same value for both cgroup v2. If you try to write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: This is used for more than the memory limits, and my above comments only apply to those. Hmm |
||||||
} | ||||||
if out == "" { | ||||||
return 0 | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍