reparent kernel threads to swapper
PATCH 3/3 reparent kernel threads to swapper
A lot of kernel threads parented to /sbin/init slow down do_wait() when a non-detached (user-space) process exits. Change reparent_kthread() to use init_task as a parent. Since init_task can't go away, we don't need to put the caller on init_task.children list.
NOTE: pstree doesn't show kernel threads with this patch.
kernel/exit.c renamed from kernel/exit.c~3_SWAPPER +4 -5
@@ -255,11 +255,11 @@ static int has_stopped_jobs(struct pid * }/** -* reparent_kthread - Reparent the calling kernel thread to the init task of the pid space that the thread belongs to. +* reparent_kthread - Reparent the calling kernel thread to swapper. * * If a kernel thread is launched as a result of a system call, or if -* it ever exits, it should generally reparent itself to init so that -* it is correctly cleaned up on exit. +* it ever exits, it should generally reparent itself so that it is +* correctly cleaned up on exit. * * The various task state such as scheduling policy and priority may have * been inherited from a user process, so we reset them to sane values here.
@@ -272,9 +272,8 @@ void reparent_kthread(void)ptrace_unlink (current);remove_parent (current); - current->parent = init_pid_ns.child_reaper; + current->parent = &init_task; current->real_parent = current->parent; -add_parent (current);/* make the task auto-reap */ current->exit_signal =-1 ;
Quoted 4 lines · Oleg Nesterov
A lot of kernel threads parented to
/sbin/initslow downdo_wait()when a non-detached (user-space) process exits. Changereparent_kthread()to useinit_taskas a parent. Sinceinit_taskcan't go away, we don't need to put the caller on init_task.children list.
Is there any downside of putting tasks on init_task.children?
If not it is probably a good idea to put processes there just for good measure.
Quoted 33 lines
NOTE: pstree doesn't show kernel threads with this patch.
Signed-off-by Oleg Nesterov <[email protected]>kernel/exit.c renamed from kernel/exit.c~3_SWAPPER +0
-1@@ -255,11 +255,11 @@ static int has_stopped_jobs(struct pid * }/** -* reparent_kthread - Reparent the calling kernel thread to the init task of the pid space that the thread belongs to.
+ *reparent_kthread- Reparent the calling kernel thread to swapper. *
* If a kernel thread is launched as a result of a system call, or if
- * it ever exits, it should generally reparent itself to init so that
- * it is correctly cleaned up on exit.
+ * it ever exits, it should generally reparent itself so that it is
+ * correctly cleaned up on exit.
*
* The various task state such as scheduling policy and priority may have
* been inherited from a user process, so we reset them to sane values here.kernel/exit.c renamed from kernel/exit.c~3_SWAPPER +1
-2@@ -272,9 +272,8 @@ void reparent_kthread(void)ptrace_unlink (current);remove_parent (current); - current->parent = init_pid_ns.child_reaper; + current->parent = &init_task; current->real_parent = current->parent; -add_parent (current);/* make the task auto-reap */ current->exit_signal =-1 ;