On Sun, Mar 15, 2015 at 08:55:06PM +0100, Oleg Nesterov wrote:
On 03/15, Josh Triplett wrote:
quoted
On Sun, Mar 15, 2015 at 03:52:23PM +0100, Oleg Nesterov wrote:
quoted
On 03/15, Josh Triplett wrote:
quoted
Add a CLONE_AUTOREAP flag to request this behavior unconditionally,
Yes, CLONE_AUTOREAP is much better. And I agree (mostly) with that
we should rely on do_notify_parent().
Howver the patch still doesn't look right. First of all, ->autoreap
should be per-process, not per-thread.
Ah, you're thinking of the case where the parent process launches a
...
Not really, although we probably need more sanity checks.
It should be per-process simply because this "autoreap" affects the whole
process. And the sub-threads are already "autoreap". And these 2 autoreap's
semantics differ, we should not confuse them.
Will the approach I suggested, of having clones with CLONE_THREAD
inherit the autoreap value rather than setting it from CLONE_AUTOREAP,
implement the semantics you're looking for?
Also, are you suggesting that CLONE_AUTOREAP with CLONE_THREAD should
produce -EINVAL, or just that it should be ignored?
quoted
(As an aside, what *is* the use case for CLONE_PARENT without
CLONE_THREAD?)
To me CLONE_PARENT is another historical mistake and the source of misc
problems ;)
I kinda figured. :)
quoted
quoted
And there are ptrace/mt issues,
it seems. Just for example, we should avoid EXIT_TRACE if autoreap in
wait_task_zombie() even if we are going to re-notify parent.
I don't see how EXIT_TRACE can happen in wait_task_zombie if autoreap is
set. wait_task_zombie does a cmpxchg with exit_state and doesn't
proceed unless exit_state was EXIT_ZOMBIE, and I don't see how we can
ever reach the EXIT_ZOMBIE state if autoreap.
Because you again forgot about ptrace ;)
Josh. Let me try to summarise this later when I have time. Again, I am
not sure, perhaps this is even simpler than I currently think. And let
me apologize in advance, most probably I will be busy tomorrow.
I look forward to your later review and feedback.
- Josh Triplett
Josh,
I am really sorry for delay.
On 03/15, Josh Triplett wrote:
On Sun, Mar 15, 2015 at 08:55:06PM +0100, Oleg Nesterov wrote:
>
quoted
It should be per-process simply because this "autoreap" affects the whole
process. And the sub-threads are already "autoreap". And these 2 autoreap's
semantics differ, we should not confuse them.
Will the approach I suggested, of having clones with CLONE_THREAD
inherit the autoreap value rather than setting it from CLONE_AUTOREAP,
implement the semantics you're looking for?
Not sure I understand... CLONE_THREAD should not inherit the autoreap.
A sub-thread is always autoreapable.
Also, are you suggesting that CLONE_AUTOREAP with CLONE_THREAD should
produce -EINVAL, or just that it should be ignored?
Yes, I think CLONE_AUTOREAP | CLONE_THREAD should return -EINVAL. But
this all is minor...
The main problem is how/when we should check this "autoreap" without
making this code even more ugly.
I still think we need a preparation patch. I tried to make it today but
failed. Will try again on weekend...
Note that we can't solely rely on do_notify_parent() which (with your patch)
correctly checks !ptrace && autoreap.
Just for example. Please look at __ptrace_detach(). Note that if we add
CLONE_AUTOREAP this needs a fix in any case. The tracee can be "autoreap"
but zombie, because "autoreap" should be ignored until the tracer detaches.
But the "same_thread_group" should not call do_notify_parent() again. So
this needs another check.
And let me quote our discussion from the previous email:
> > EXCEPT: do we really want SIGCHLD from the exiting child? I think we
> > do not. I won't really argue though, but this should be discussed and
> > documented. IIUC, with your patch it is still sent.
>
> I think we do, yes. The caller of clone can already specify what signal
> they want, including no signal at all. If they specify a signal
> (SIGCHLD or otherwise) along with CLONE_AUTOREAP, we can send that
> signal.
OK. Agreed.
Yes, I agree...
But the changes in __ptrace_detach() depend on whether we need to send a signal
or not. Either way the changle is simple, but looks ugly. It would be nice to
cleanup this somehow.
Also. I forgot that the kernel always resets ->exit_signal to SIGCHLD on exec
or reparenting. Reparenting is probably fine. But what about exec? Should it
keep ->exit_signal == 0 if "autoreap" ? I think it should not, to avoid the
strange special case.
quoted
quoted
quoted
And there are ptrace/mt issues,
it seems. Just for example, we should avoid EXIT_TRACE if autoreap in
wait_task_zombie() even if we are going to re-notify parent.
I don't see how EXIT_TRACE can happen in wait_task_zombie if autoreap is
set. wait_task_zombie does a cmpxchg with exit_state and doesn't
proceed unless exit_state was EXIT_ZOMBIE, and I don't see how we can
ever reach the EXIT_ZOMBIE state if autoreap.
Because you again forgot about ptrace ;)
And this too asks for preparation before CLONE_AUTOREAP...
So I'll try to think about this all again on weekend. I'll try very much
to not disappear again ;)
Oleg.
On Friday 20 March 2015 19:14:04 Oleg Nesterov wrote:
Also. I forgot that the kernel always resets ->exit_signal to SIGCHLD on
exec or reparenting. Reparenting is probably fine. But what about exec?
Should it keep ->exit_signal == 0 if "autoreap" ? I think it should not, to
avoid the strange special case.
Not delivering any signal was the objective of this patch series, so yes
exit_signal == 0 should survive an exec and even re-exec.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
On 03/20, Thiago Macieira wrote:
On Friday 20 March 2015 19:14:04 Oleg Nesterov wrote:
quoted
Also. I forgot that the kernel always resets ->exit_signal to SIGCHLD on
exec or reparenting. Reparenting is probably fine. But what about exec?
Should it keep ->exit_signal == 0 if "autoreap" ? I think it should not, to
avoid the strange special case.
Not delivering any signal was the objective of this patch series, so yes
exit_signal == 0 should survive an exec and even re-exec.
OK, but then perhaps we should never send SIGCHLD (on exit) if "autoreap",
to make the logic simple.
And copy_process() should probably do
if ((clone_flags & CSIGNAL) && (clone_flags && CLONE_AUTOREAP))
return -EINVAL;
so that we still can change this behaviour later.
Oleg.
On Fri, Mar 20, 2015 at 08:09:14PM +0100, Oleg Nesterov wrote:
On 03/20, Thiago Macieira wrote:
quoted
On Friday 20 March 2015 19:14:04 Oleg Nesterov wrote:
quoted
Also. I forgot that the kernel always resets ->exit_signal to SIGCHLD on
exec or reparenting. Reparenting is probably fine. But what about exec?
Should it keep ->exit_signal == 0 if "autoreap" ? I think it should not, to
avoid the strange special case.
Not delivering any signal was the objective of this patch series, so yes
exit_signal == 0 should survive an exec and even re-exec.
OK, but then perhaps we should never send SIGCHLD (on exit) if "autoreap",
to make the logic simple.
And copy_process() should probably do
if ((clone_flags & CSIGNAL) && (clone_flags && CLONE_AUTOREAP))
return -EINVAL;
so that we still can change this behaviour later.
I'm fine with that, as it would handle the particular use case we care
about.
However, the reset-signal-on-reparent thing might still make sense,
particularly for the ptrace-reparent case (less so for the
reparent-to-child-reaper case).
- Josh Triplett