The patch titled kthreads: simplify the startup synchronization has been added to the -mm tree. Its filename is kthreads-simplify-the-startup-synchronization.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find out what to do about this The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/ ------------------------------------------------------ Subject: kthreads: simplify the startup synchronization From: Oleg Nesterov <oleg@xxxxxxxxxx> We use two completions two create the kernel thread, this is a bit ugly. kthread() wakes up create_kthread() via ->started, then create_kthread() wakes up the caller kthread_create() via ->done. But kthread() does not need to wait for kthread(), it can just return. Instead kthread() itself can wake up the caller of kthread_create(). Kill kthread_create_info->started, ->done is enough. This improves the scalability a bit and sijmplifies the code. The only problem if kernel_thread() fails, in that case create_kthread() must do complete(&create->done). Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxx> Cc: Pavel Emelyanov <xemul@xxxxxxxxxx> Cc: Rusty Russell <rusty@xxxxxxxxxxxxxxx> Cc: Vitaliy Gusev <vgusev@xxxxxxxxxx Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/kthread.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff -puN kernel/kthread.c~kthreads-simplify-the-startup-synchronization kernel/kthread.c --- a/kernel/kthread.c~kthreads-simplify-the-startup-synchronization +++ a/kernel/kthread.c @@ -31,7 +31,6 @@ struct kthread_create_info /* Information passed to kthread() from kthreadd. */ int (*threadfn)(void *data); void *data; - struct completion started; /* Result passed back to kthread_create() from kthreadd. */ struct task_struct *result; @@ -79,7 +78,7 @@ static int kthread(void *_create) /* OK, tell user we're spawned, wait for stop or wakeup */ __set_current_state(TASK_UNINTERRUPTIBLE); create->result = current; - complete(&create->started); + complete(&create->done); schedule(); if (!kthread_should_stop()) @@ -101,10 +100,8 @@ static void create_kthread(struct kthrea pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); if (pid < 0) { create->result = ERR_PTR(pid); - } else { - wait_for_completion(&create->started); + complete(&create->done); } - complete(&create->done); } /** @@ -135,7 +132,6 @@ struct task_struct *kthread_create(int ( create.threadfn = threadfn; create.data = data; - init_completion(&create.started); init_completion(&create.done); spin_lock(&kthread_create_lock); _ Patches currently in -mm which might be from oleg@xxxxxxxxxx are origin.patch wait-prevent-exclusive-waiter-starvation.patch linux-next.patch pipe_rdwr_fasync-fix-the-error-handling-to-prevent-the-leak-crash.patch get_mm_hiwater_xxx-trivial-s-define-inline.patch getrusage-fill-ru_maxrss-value.patch ptrace-kill-__ptrace_detach-fix-exit_state-check.patch ptrace-simplify-ptrace_exit-ignoring_children-path.patch ptrace-simplify-ptrace_exit-ignoring_children-pathpatch-fix.patch ptrace-reintroduce-__ptrace_detach-as-a-callee-of-ptrace_exit.patch ptrace-reintroduce-__ptrace_detach-as-a-callee-of-ptrace_exit-fix.patch ptrace-fix-possible-zombie-leak-on-ptrace_detach.patch reparent_thread-dont-call-kill_orphaned_pgrp-if-task_detached.patch reparent_thread-fix-the-is-it-traced-check.patch reparent_thread-fix-a-zombie-leak-if-sbin-init-ignores-sigchld.patch forget_original_parent-cleanup-ptrace-pathes.patch kthread-dont-looking-for-a-task-in-create_kthread-2.patch kthreads-move-sched-realeted-initialization-from-kthreadd-context.patch kthreads-simplify-the-startup-synchronization.patch kthreads-rework-kthread_stop.patch kthreads-simplify-migration_thread-exit-path.patch pids-document-task_pgrp-task_session-is-not-safe-without-tasklist-rcu.patch pids-document-task_pgrp-task_session-is-not-safe-without-tasklist-rcu-fix.patch pids-improve-get_task_pid-to-fix-the-unsafe-sys_wait4-task_pgrp.patch pids-refactor-vnr-nr_ns-helpers-to-make-them-safe.patch pids-kill-now-unused-signal_struct-__pgrp-__session-and-friends.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html