Skip to content

Commit 468144c

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)
1 parent 5159b7a commit 468144c

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
@@ -4578,14 +4578,6 @@ static int exec_child(
45784578
}
45794579
}
45804580

4581-
if (context->nice_set) {
4582-
r = setpriority_closest(context->nice);
4583-
if (r < 0) {
4584-
*exit_status = EXIT_NICE;
4585-
return log_unit_error_errno(unit, r, "Failed to set up process scheduling priority (nice level): %m");
4586-
}
4587-
}
4588-
45894581
if (context->cpu_sched_set) {
45904582
struct sched_attr attr = {
45914583
.size = sizeof(attr),
@@ -4601,6 +4593,14 @@ static int exec_child(
46014593
}
46024594
}
46034595

4596+
if (context->nice_set) {
4597+
r = setpriority_closest(context->nice);
4598+
if (r < 0) {
4599+
*exit_status = EXIT_NICE;
4600+
return log_unit_error_errno(unit, r, "Failed to set up process scheduling priority (nice level): %m");
4601+
}
4602+
}
4603+
46044604
if (context->cpu_affinity_from_numa || context->cpu_set.set) {
46054605
_cleanup_(cpu_set_reset) CPUSet converted_cpu_set = {};
46064606
const CPUSet *cpu_set;

0 commit comments

Comments
 (0)