Skip to content

Commit 5d5f712

Browse files
intelfxbluca
authored andcommitted
core/exec-invoke: call setpriority() after sched_setattr()
The nice value is part of struct sched_attr, and consequently invoking sched_setattr() after setpriority() would clobber the nice value with the default (as we are not setting it in struct sched_attr). It would be best to combine both calls, but for now simply invoke setpriority() after sched_setattr() to make sure Nice= remains effective when used together with CPUSchedulingPolicy=. (cherry picked from commit 711a157) (cherry picked from commit b628d4d) (cherry picked from commit 4994f15) (cherry picked from commit c90ba5e) (cherry picked from commit 468144c)
1 parent f89c88c commit 5d5f712

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/core/execute.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4438,14 +4438,6 @@ static int exec_child(
44384438
}
44394439
}
44404440

4441-
if (context->nice_set) {
4442-
r = setpriority_closest(context->nice);
4443-
if (r < 0) {
4444-
*exit_status = EXIT_NICE;
4445-
return log_unit_error_errno(unit, r, "Failed to set up process scheduling priority (nice level): %m");
4446-
}
4447-
}
4448-
44494441
if (context->cpu_sched_set) {
44504442
struct sched_attr attr = {
44514443
.size = sizeof(attr),
@@ -4461,6 +4453,14 @@ static int exec_child(
44614453
}
44624454
}
44634455

4456+
if (context->nice_set) {
4457+
r = setpriority_closest(context->nice);
4458+
if (r < 0) {
4459+
*exit_status = EXIT_NICE;
4460+
return log_unit_error_errno(unit, r, "Failed to set up process scheduling priority (nice level): %m");
4461+
}
4462+
}
4463+
44644464
if (context->cpu_affinity_from_numa || context->cpu_set.set) {
44654465
_cleanup_(cpu_set_reset) CPUSet converted_cpu_set = {};
44664466
const CPUSet *cpu_set;

0 commit comments

Comments
 (0)