Force processes to non-realtime before mm_exit
PATCH 1/1 Force processes to non-realtime before mm_exit
Without this, a realtime process which has called mlockall exiting causes large latencies for other realtime processes at the same or lower priorities. This seems like a fairly common use case too, because realtime processes generally want their memory locked into RAM.
--- kernel/exit.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/exit.c +6 -0
@@ -730,6 +730,12 @@ void do_exit(long code) tsk->exit_code = code;taskstats_exit (tsk, group_dead); +if (tsk->policy ==SCHED_FIFO || tsk->policy ==SCHED_RR ) { +struct sched_param param = { .sched_priority =0 }; + +sched_setscheduler_nocheck (current,SCHED_NORMAL , ¶m); + } +exit_mm (tsk);if (group_dead)
Signature · 1 line
2.1.4
Quoted 4 lines · Brian Silverman
Without this, a realtime process which has called mlockall exiting causes large latencies for other realtime processes at the same or lower priorities. This seems like a fairly common use case too, because realtime processes generally want their memory locked into RAM.
Could this cause a subtle priority inversion for a process waiting on this process to die? I'm thinking that if this is a critical process, it crashes, and the system is very busy with other RT processes, it could take a long time before the process gets restarted when it is expected to happen quickly.
I don't have another solution for you, and beyond speeding up the memory reclamation process (which may not be possible or easy) I'm not sure there is. I'm just pointing out a possible side effect.
-corey
Quoted 22 lines
Signed-off-by Brian Silverman <[email protected]>--- kernel/exit.c | 6 ++++++ 1 file changed, 6 insertions(+)kernel/exit.c +6
-0@@ -730,6 +730,12 @@ void do_exit(long code) tsk->exit_code = code;taskstats_exit (tsk, group_dead); +if (tsk->policy ==SCHED_FIFO || tsk->policy ==SCHED_RR ) { +struct sched_param param = { .sched_priority =0 }; + +sched_setscheduler_nocheck (current,SCHED_NORMAL , ¶m); + } +exit_mm (tsk);if (group_dead)
Peter Zijlstra
maintainerQuoted 4 lines · Brian Silverman
Without this, a realtime process which has called mlockall exiting causes large latencies for other realtime processes at the same or lower priorities. This seems like a fairly common use case too, because realtime processes generally want their memory locked into RAM.
So I'm not too sure.. SCHED_FIFO/RR are a complete trainwreck and provide absolutely no isolation from badly behaving tasks what so ever, so I'm not too inclined to protect them from exit either, its just one more way in which they can cause pain.
But aside from the, the patch has issues..
Review void do_exit(long code) · line 739
Quoted 12 lines
+++
b/kernel/exit.c(quoted diff) +6
-0@@ -730,6 +730,12 @@ void do_exit(long code) tsk->exit_code = code; taskstats_exit(tsk, group_dead); + if (tsk->policy == SCHED_FIFO || tsk->policy == SCHED_RR) { + struct sched_param param = { .sched_priority = 0 }; + + sched_setscheduler_nocheck(current, SCHED_NORMAL, ¶m); + } + exit_mm(tsk);
That only does half a job. You forget about SCHED_DEADLINE and negative nice tasks.
Something like the below perhaps... But yeah, unconvinced.
kernel/exit.c +7 -0
@@ -812,6 +812,13 @@ void do_exit(long code) tsk->exit_code = code;taskstats_exit (tsk, group_dead); +/* +* Drop all scheduler priority before exit_mm() as that +* can involve a lot of work and we don't want a dying +* task to interfere with healthy/running tasks. +*/ +sched_normalize_task (tsk); +exit_mm (tsk);if (group_dead)
kernel/sched/core.c +19 -15
@@ -7585,14 +7585,29 @@ void ___might_sleep(const char *file, int line, int preempt_offset)EXPORT_SYMBOL (___might_sleep);#endif -#ifdef CONFIG_MAGIC_SYSRQ -void normalize_rt_tasks (void ) +void sched_normalize_task (struct task_struct *p) { -struct task_struct *g, *p;struct sched_attr attr = { .sched_policy =SCHED_NORMAL , }; +if (!dl_task (p) && !rt_task (p)) { +/* +* Renice negative nice level tasks. +*/ +if (task_nice (p) <0 ) +set_user_nice (p,0 ); +return ; + } + +__sched_setscheduler (p, &attr, false, false); +} + +#ifdef CONFIG_MAGIC_SYSRQ +void normalize_rt_tasks (void ) +{ +struct task_struct *g, *p; +read_lock (&tasklist_lock);for_each_process_thread (g, p) {/*
@@ -7608,21 +7623,10 @@ void normalize_rt_tasks(void) p->se.statistics.block_start =0 ;#endif -if (!dl_task (p) && !rt_task (p)) { -/* -* Renice negative nice level userspace -* tasks back to 0: -*/ -if (task_nice (p) <0 ) -set_user_nice (p,0 ); -continue ; - } - - __sched_setscheduler(p, &attr, false, false); + sched_normalize_task(p); }read_unlock (&tasklist_lock); } -#endif /* CONFIG_MAGIC_SYSRQ */ #if defined(CONFIG_IA64 ) || defined(CONFIG_KGDB_KDB )
Quoted 29 lines · Peter Zijlstra
Quoted 4 lines · Brian Silverman
Without this, a realtime process which has called mlockall exiting causes large latencies for other realtime processes at the same or lower priorities. This seems like a fairly common use case too, because realtime processes generally want their memory locked into RAM.
So I'm not too sure.. SCHED_FIFO/RR are a complete trainwreck and provide absolutely no isolation from badly behaving tasks what so ever, so I'm not too inclined to protect them from exit either, its just one more way in which they can cause pain.
But aside from the, the patch has issues..
kernel/exit.c void do_exit(long code) · line 739
Quoted 12 lines
+++
b/kernel/exit.ckernel/exit.c +6
-0@@ -730,6 +730,12 @@ void do_exit(long code) tsk->exit_code = code;taskstats_exit (tsk, group_dead); +if (tsk->policy ==SCHED_FIFO || tsk->policy ==SCHED_RR ) { +struct sched_param param = { .sched_priority =0 }; + +sched_setscheduler_nocheck (current,SCHED_NORMAL , ¶m); + } +exit_mm (tsk);That only does half a job. You forget about
SCHED_DEADLINEand negative nice tasks.
Quoted 1 line
Something like the below perhaps... But yeah, unconvinced.
I agree that FIFO/RR can cause pain, but running exit_mm() with RT priority or consuming DL time is silly.
FWIW: Acked-by-me