mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Robin Holt <holt@sgi.com>, Chris Snook <csnook@redhat.com>,
	Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org
Subject: Re: init's children list is long and slows reaping children.
Date: Sun, 8 Apr 2007 19:46:18 +0400	[thread overview]
Message-ID: <20070408154618.GA84@tv-sign.ru> (raw)
In-Reply-To: <m11wiv4s4k.fsf@ebiederm.dsl.xmission.com>

On 04/07, Eric W. Biederman wrote:
>
> Oleg Nesterov <oleg@tv-sign.ru> writes:
>
> > On 04/06, Oleg Nesterov wrote:
> >>
> >> @@ -275,10 +275,7 @@ static void reparent_to_init(void)
> >>  	remove_parent(current);
> >>  	current->parent = child_reaper(current);
> >>  	current->real_parent = child_reaper(current);
> >> -	add_parent(current);
> >> -
> >> -	/* Set the exit signal to SIGCHLD so we signal init on exit */
> >> -	current->exit_signal = SIGCHLD;
> >> +	current->exit_signal = -1;
> >>
> >>  	if (!has_rt_policy(current) && (task_nice(current) < 0))
> >>  		set_user_nice(current, 0);
> >>
> >> is enough. init is still our parent (make ps happy), but it can't see us,
> >> we are not on ->children list.
> >
> > OK, this doesn't work. A multi-threaded init may do execve().
>
> Good catch.  daemonize must die!

Well, this is not the problem of daemonize(), but I agree, daemonize() should
die with the changes you proposed.

> > So, we can re-parent a kernel thread to swapper. In that case it doesn't matter
> > if we put task on ->children list or not.
>
> Yes.  We can.
>
> > User-visible change. Acceptable?
>
> We would have user visible changes when we changed to ktrhead_create anyway,
> and it's none of user space's business so certainly.

OK, I'll try to do "just for review" patch. I'm afraid pstree will be confused.

> >> Off course, we also need to add preparent_to_init() to kthread() and
> >> (say) stopmachine(). Or we can create kernel_thread_detached() and
> >> modify callers to use it.
> >
> > It would be very nice to introduce CLONE_KERNEL_THREAD instead, then
>
> If we are going to do something to copy_process and the like let's take
> this one step farther.  Let's pass in the value of the task to copy.

Yes! I thought about that too. but see below,

> Then we can add a wrapper around copy_process to build kernel_thread
> something like:
>
> struct task_struct *__kernel_thread(int (*fn)(void *), void * arg,
> 				    unsigned long flags)
> {
> 	struct task_struct *task;
> 	struct pt_regs regs, *reg;
>
>         reg = kernel_thread_regs(&regs, fn, arg);
> 	task = copy_process(&init_task, flags, 0, reg, 0, NULL, NULL, NULL, 0);
> 	if (!IS_ERR(task))
> 		wake_up_new_task(task, flags);
>
> 	return task;
> }

First, we still need some additional flag/parameter to set ->exit_state = -1.
Let's use CLONE_KERNEL_THREAD for discussion.

Now. Can we do copy_process(an_arbitrary_task) ? If yes, we need additional
locking in copy_process(). Just think about ->signal,->parent access. Nasty,
and probably not so useful.

If we can only use "current" or init_task, CLONE_KERNEL_THREAD is enough.
Just now it only

	- sets ->exit_state = -1

	- sets ->parent = &init_task

(note that the second change could be omitted, we can use CLONE_PARENT
 if we know that all users of CLONE_KERNEL_THREAD are kernel threads).

> After that daemonize just becomes:
>
> void daemonize(const char *name, ...)
> {
> 	va_list args;
>
> 	va_start(args, name);
> 	vsnprintf(current->comm, sizeof(current->comm), name, args);
> 	va_end(args);
> }
>
> And kthread_create becomes:
>
> struct task_struct *kthread_create(int (*threadfn)(void *data),
> 				   void *data,
> 				   const char namefmt[],
> 				   ...)
> {
> 	struct kthread_create_info create;
> 	struct task_struct *task;
>
> 	create.threadfn = threadfn;
> 	create.data = data;
>
> 	/* We want our own signal handler (we take no signals by default). */
>         task = __kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
> 	if (!IS_ERR(task)) {
> 		va_list args;
> 		va_start(args, namefmt);
> 		vsnprintf(task->comm, sizeof(task->comm),  namefmt, args);
> 		va_end(args);
> 	}
>         return task;
> }

Yes, nice. This is not complete, we still have to wait for completion,
because kthread_create() promises that a new thread has no CPU on
return (so we can use kthread_bind() for example), but nice anyway.

> If we are willing to go that far.  I think it is worth it to touch the
> architecture specific code.  As that removes an unnecessary wait
> queue, and ensures that kernel threads always start with a consistent
> state.  So it is a performance, scalability and simplicity boost.

Yes.

But note that CLONE_KERNEL_THREAD allows us to achieve the same step by
step. For example, we can extend the meaning of CLONE_KERNEL_THREAD to
use init_task.mm in copy_mm(), then copy_fs(), etc.

Eric, I am far from sure I am right though. Probably it is better to do
one big change as you suggested.

However, I like the idea of for-in-kernel-only CLONE_ flags. For example,
we can kill the ugly "pid" parameter of copy_process() and use CLONE_IDLE
instead.

Also, we can't use __kernel_thread() you propose if we want do_wait(),
using CLONE_ flags a bit more flexible.

BTW. I think your idea of kernel_thread_regs() is very nice in any case. Is
it enough (and possible) to implement an architecture neutral kernel_thread?

Oleg.


  reply	other threads:[~2007-04-08 15:46 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-06  8:42 Oleg Nesterov
2007-04-06  9:10 ` Eric W. Biederman
2007-04-06  9:44   ` Oleg Nesterov
2007-04-06 15:45     ` Eric W. Biederman
2007-04-06 15:47       ` Oleg Nesterov
2007-04-06 17:16         ` Linus Torvalds
2007-04-06 17:27           ` Ingo Molnar
2007-04-06 17:31             ` Ingo Molnar
2007-04-06 17:34           ` Eric W. Biederman
2007-04-06 19:06             ` H. Peter Anvin
2007-04-06 19:15               ` Eric W. Biederman
2007-04-06 19:21                 ` H. Peter Anvin
2007-04-06 21:04                 ` Jeremy Fitzhardinge
2007-04-06 21:07                   ` H. Peter Anvin
2007-04-06 19:36           ` Oleg Nesterov
2007-04-06 19:43             ` Ingo Molnar
2007-04-06 20:01               ` Oleg Nesterov
2007-04-06 20:21                 ` Ingo Molnar
2007-04-06 19:47             ` Oleg Nesterov
2007-04-06 19:59               ` Eric W. Biederman
2007-04-07 20:31             ` Oleg Nesterov
2007-04-08  0:38               ` Eric W. Biederman
2007-04-08 15:46                 ` Oleg Nesterov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-04-05 19:51 Robin Holt
2007-04-05 20:57 ` Linus Torvalds
2007-04-06  0:51   ` Chris Snook
2007-04-06  1:03     ` Chris Snook
2007-04-06  1:29     ` Linus Torvalds
2007-04-06  2:15       ` Eric W. Biederman
2007-04-06 10:43         ` Robin Holt
2007-04-06 15:38           ` Eric W. Biederman
2007-04-06 16:31             ` Oleg Nesterov
2007-04-06 17:32               ` Ingo Molnar
2007-04-06 17:39                 ` Roland Dreier
2007-04-06 18:04                   ` Eric W. Biederman
2007-04-06 18:30                 ` Eric W. Biederman
2007-04-10 13:48                   ` Ingo Molnar
2007-04-10 13:38                     ` Oleg Nesterov
2007-04-10 15:00                       ` Eric W. Biederman
2007-04-10 14:51                     ` Eric W. Biederman
2007-04-10 15:06                       ` Ingo Molnar
2007-04-10 15:22                         ` Eric W. Biederman
2007-04-10 15:53                           ` Ingo Molnar
2007-04-10 16:17                             ` Eric W. Biederman
2007-04-10 16:44                       ` Oleg Nesterov
2007-04-11 19:55                         ` Bill Davidsen
2007-04-11 20:17                           ` Eric W. Biederman
2007-04-11 21:24                             ` Bill Davidsen
2007-04-11 20:19                           ` Oleg Nesterov
2007-04-06 18:02               ` Eric W. Biederman
2007-04-06 18:21               ` Davide Libenzi
2007-04-06 18:56                 ` Eric W. Biederman
2007-04-06 19:16                   ` Davide Libenzi
2007-04-06 19:19                     ` Ingo Molnar
2007-04-06 21:29                       ` Davide Libenzi
2007-04-06 21:51                         ` Linus Torvalds
2007-04-06 22:31                           ` Davide Libenzi
2007-04-06 22:46                             ` Linus Torvalds
2007-04-06 22:59                               ` Davide Libenzi
2007-04-09  8:28                           ` Ingo Molnar
2007-04-09 18:09                             ` Bill Davidsen
2007-04-09 19:28                               ` Kyle Moffett
2007-04-09 19:51                                 ` Linus Torvalds
2007-04-09 20:03                                   ` Davide Libenzi
2007-04-10 15:12                                     ` Bill Davidsen
2007-04-10 19:17                                       ` Davide Libenzi
2007-04-09 20:00                                 ` Eric W. Biederman
2007-04-06 16:41             ` Robin Holt
2007-04-09 17:37         ` Chris Snook
2007-04-06 18:05       ` Christoph Hellwig
2007-04-06 19:39         ` Eric W. Biederman
2007-04-06 22:38 ` Jeff Garzik
2007-04-06 22:51   ` Linus Torvalds
2007-04-06 23:37     ` Jeff Garzik
2007-04-11  7:28       ` Nick Piggin
2007-04-10  0:23   ` Andrew Morton
2007-04-10  0:48     ` Eric W. Biederman
2007-04-10  1:15       ` Andrew Morton
2007-04-10  6:53       ` Jeff Garzik
2007-04-10  9:42       ` Robin Holt
2007-04-10  1:59     ` Dave Jones
2007-04-10  2:30       ` Andrew Morton
2007-04-10  2:46         ` Linus Torvalds
2007-04-10  7:07           ` Jeff Garzik
2007-04-10 22:20             ` Ingo Oeser
2007-04-10  5:07         ` Alexey Dobriyan
2007-04-10  5:21           ` Dave Jones
2007-04-10  6:09         ` Torsten Kaiser
2007-04-10  7:08           ` Jeff Garzik
2007-04-10  7:05         ` Jeff Garzik
2007-04-10  7:37           ` Andrew Morton
2007-04-10  8:33             ` Jeff Garzik
2007-04-10  8:41               ` Andrew Morton
2007-04-10  8:48                 ` Jeff Garzik
2007-04-10 22:35                   ` Ingo Oeser
2007-04-10 16:35           ` Matt Mackall
2007-04-10  7:44         ` Russell King
2007-04-10  8:16           ` Jeff Garzik
2007-04-10  8:59           ` Ingo Molnar
2007-04-10  9:33             ` Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070408154618.GA84@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=csnook@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=holt@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome