Re: [PATCH 4/4] reparent/untrace: do nothing if no childs/tracees

From: Oleg Nesterov
Date: Wed Feb 11 2009 - 16:17:39 EST


On 02/11, Oleg Nesterov wrote:
>
> However, forget_original_parent() has another problem. We can race with
> another thread which has already picked us for reparenting before we set
> PF_EXITING, so this patch also checks thread_group_empty().
>
> It is possible to be more clever, we can take tasklist for reading, or
> ensure that ->thread_group.prev is not PF_EXITING, but this is nasty.
> Perhaps even this optimization is too ugly.

Or, perhaps we can do:

static void forget_original_parent(struct task_struct *father)
{
struct task_struct *p, *n, *reaper;
LIST_HEAD(dead_childs);

if (list_empty(&father->children))
return;

write_lock_irq(&tasklist_lock);
again:
reaper = find_new_reaper(father);

list_for_each_entry_safe(p, n, &father->children, sibling) {
p->real_parent = reaper;
if (p->parent == father) {
BUG_ON(p->ptrace);
p->parent = p->real_parent;
}
reparent_thread(father, p, &dead_childs);
}

smp_mb(); /* do_exit() does mb() after exit_signals() */
if (unlikely(reaper->flags & PF_EXITING)) {
father = reaper;
goto again;
}
write_unlock_irq(&tasklist_lock);

BUG_ON(!list_empty(&father->children));

list_for_each_entry_safe(p, n, &dead_childs, sibling) {
list_del_init(&p->sibling);
release_task(p);
}
}

but this needs a fat comment at least. I am not sure this worth the trouble.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/