-
Notifications
You must be signed in to change notification settings - Fork 31
v2: set memory.oom.group => OOMPolicy in systemd #41
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
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 |
|---|---|---|
|
|
@@ -20,7 +20,8 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| cpuIdleSupportedVersion = 252 | ||
| cpuIdleSupportedVersion = 252 | ||
| oomPolicySupportedVersion = 253 | ||
| ) | ||
|
|
||
| type UnifiedManager struct { | ||
|
|
@@ -183,13 +184,8 @@ func unifiedResToSystemdProps(cm *dbusConnManager, res map[string]string) (props | |
| newProp("TasksMax", num)) | ||
|
|
||
| case "memory.oom.group": | ||
| // Setting this to 1 is roughly equivalent to OOMPolicy=kill | ||
| // (as per systemd.service(5) and | ||
| // https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html), | ||
| // but it's not clear what to do if it is unset or set | ||
| // to 0 in runc update, as there are two other possible | ||
| // values for OOMPolicy (continue/stop). | ||
| fallthrough | ||
| // This was set before the unit started, so no need to | ||
|
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. Dumb question, do we know this to actually be true? i.e. we've made it so we also process I guess I don't have a better answer for these sort of "must be done on unit creation" type settings unless we can warn iff we know the systemd prop isn't aligned already.
Member
Author
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.
Oh, I suppose what we should do is query the existing value, and warn/error if they mismatch? because you're right: if someone does a |
||
| // warn about it here. | ||
|
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 wonder if the warning should be louder (maybe just more explicitly stating systemd might override this on a daemon-reload) for other uses that hit it since systemd will stomp on it as you highlight, or is that only for a subset of things that systemd has a knob for? I realize that's a bit out of scope for this PR, but sort of a tricky thing for folks to debug down to.
Member
Author
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 |
||
|
|
||
| default: | ||
| // Ignore the unknown resource here -- will still be | ||
|
|
@@ -338,6 +334,29 @@ func (m *UnifiedManager) Apply(pid int) error { | |
|
|
||
| properties = append(properties, c.SystemdProps...) | ||
|
|
||
| // OOMPolicy must be set at unit creation time, systemd does not allow | ||
| // changing it on a running scope for some reason despite the kernel allowing so | ||
| // so we do this here in Apply() instead of Set() | ||
| if c.Resources != nil { | ||
| if v, ok := c.Resources.Unified["memory.oom.group"]; ok { | ||
| if systemdVersion(m.dbus) >= oomPolicySupportedVersion { | ||
| value, err := strconv.ParseUint(v, 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("unified resource %q value conversion error: %w", "memory.oom.group", err) | ||
| } | ||
|
|
||
| switch value { | ||
| case 0: | ||
| properties = append(properties, newProp("OOMPolicy", "continue")) | ||
| case 1: | ||
| properties = append(properties, newProp("OOMPolicy", "kill")) | ||
| default: | ||
| logrus.Debugf("don't know how to convert memory.oom.group=%d; skipping (will still be applied to cgroupfs)", value) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if err := startUnit(m.dbus, unitName, properties, pid == -1); err != nil { | ||
| return fmt.Errorf("unable to start unit %q (properties %+v): %w", unitName, properties, err) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.