Compare commits

...

4 Commits

Author SHA1 Message Date
Lennart Poettering df957acc66
Merge pull request #13905 from poettering/cpuset-fixes
fixes to the cpuset cgroup logic
2019-11-01 23:44:36 +01:00
Lennart Poettering a897a7b837 cgroup: add missing OOM check, and shorten code a bit
cpu_set_to_range_string() can fail due to OOM. Handle that.

unit_write_settingf() exists, use it instead of formatting a string
beforehand.

cpu_set_add_all() can fail due to OOM. Let's avoid it if we don't have
to use it, just copy over the cpuset directly.
2019-11-01 10:22:03 +01:00
Lennart Poettering c259ac9aa2 cpuset: fix indentation and log about OOM we otherwise ignore 2019-11-01 10:21:53 +01:00
Lennart Poettering 85c3b27891 cgroup: add some basic OOM safety where it was missing 2019-11-01 10:21:35 +01:00
2 changed files with 13 additions and 13 deletions

View File

@ -360,9 +360,7 @@ static char *format_cgroup_memory_limit_comparison(char *buf, size_t l, Unit *u,
} }
void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
_cleanup_free_ char *disable_controllers_str = NULL; _cleanup_free_ char *disable_controllers_str = NULL, *cpuset_cpus = NULL, *cpuset_mems = NULL;
_cleanup_free_ char *cpuset_cpus = NULL;
_cleanup_free_ char *cpuset_mems = NULL;
CGroupIODeviceLimit *il; CGroupIODeviceLimit *il;
CGroupIODeviceWeight *iw; CGroupIODeviceWeight *iw;
CGroupIODeviceLatency *l; CGroupIODeviceLatency *l;
@ -437,8 +435,8 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, c->startup_cpu_shares, prefix, c->startup_cpu_shares,
prefix, format_timespan(q, sizeof(q), c->cpu_quota_per_sec_usec, 1), prefix, format_timespan(q, sizeof(q), c->cpu_quota_per_sec_usec, 1),
prefix, format_timespan(v, sizeof(v), c->cpu_quota_period_usec, 1), prefix, format_timespan(v, sizeof(v), c->cpu_quota_period_usec, 1),
prefix, cpuset_cpus, prefix, strempty(cpuset_cpus),
prefix, cpuset_mems, prefix, strempty(cpuset_mems),
prefix, c->io_weight, prefix, c->io_weight,
prefix, c->startup_io_weight, prefix, c->startup_io_weight,
prefix, c->blockio_weight, prefix, c->blockio_weight,
@ -974,8 +972,10 @@ static void cgroup_apply_unified_cpuset(Unit *u, const CPUSet *cpus, const char
_cleanup_free_ char *buf = NULL; _cleanup_free_ char *buf = NULL;
buf = cpu_set_to_range_string(cpus); buf = cpu_set_to_range_string(cpus);
if (!buf) if (!buf) {
return; log_oom();
return;
}
(void) set_attribute_and_warn(u, "cpuset", name, buf); (void) set_attribute_and_warn(u, "cpuset", name, buf);
} }

View File

@ -926,23 +926,23 @@ int bus_cgroup_set_property(
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *setstr = NULL; _cleanup_free_ char *setstr = NULL;
_cleanup_free_ char *data = NULL;
CPUSet *set; CPUSet *set;
setstr = cpu_set_to_range_string(&new_set); setstr = cpu_set_to_range_string(&new_set);
if (!setstr)
return -ENOMEM;
if (streq(name, "AllowedCPUs")) if (streq(name, "AllowedCPUs"))
set = &c->cpuset_cpus; set = &c->cpuset_cpus;
else else
set = &c->cpuset_mems; set = &c->cpuset_mems;
if (asprintf(&data, "%s=%s", name, setstr) < 0)
return -ENOMEM;
cpu_set_reset(set); cpu_set_reset(set);
cpu_set_add_all(set, &new_set); *set = new_set;
new_set = (CPUSet) {};
unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET); unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET);
unit_write_setting(u, flags, name, data); unit_write_settingf(u, flags, name, "%s=%s", name, setstr);
} }
return 1; return 1;