Add lkml.

On 09/13, Tetsuo Handa wrote:
>
> This patch makes kthread_create() killable,

Probably makes sense...

> @@ -255,36 +266,59 @@ struct task_struct *kthread_create_on_node(int 
> (*threadfn)(void *data),
>                                          const char namefmt[],
>                                          ...)
>  {
> -     struct kthread_create_info create;
> -
> -     create.threadfn = threadfn;
> -     create.data = data;
> -     create.node = node;
> -     init_completion(&create.done);
> +     struct task_struct *task;
> +     struct kthread_create_info *create = kmalloc(sizeof(*create),
> +                                                  GFP_KERNEL);
> +
> +     if (!create)
> +             return ERR_PTR(-ENOMEM);
> +     create->threadfn = threadfn;
> +     create->data = data;
> +     create->node = node;
> +     create->owner = (void *) 1;
> +     init_completion(&create->done);
>  
>       spin_lock(&kthread_create_lock);
> -     list_add_tail(&create.list, &kthread_create_list);
> +     list_add_tail(&create->list, &kthread_create_list);
>       spin_unlock(&kthread_create_lock);
>  
>       wake_up_process(kthreadd_task);
> -     wait_for_completion(&create.done);
> -
> -     if (!IS_ERR(create.result)) {
> +     /*
> +      * Wait for completion in killable state, for I might be chosen by
> +      * the OOM killer while kthreadd is trying to allocate memory for
> +      * new kernel thread.
> +      */
> +     if (unlikely(wait_for_completion_killable(&create->done))) {
> +             /*
> +              * If I was SIGKILLed before kthreadd (or new kernel thread)
> +              * calls complete(), leave the cleanup of this structure to
> +              * that thread.
> +              */
> +             if (xchg(&create->owner, NULL))
> +                     return ERR_PTR(-ENOMEM);

I am wondering if this can be simplified...

At least you can move create->done from kthread_create_info to the
stack, and turn create->owner into the pointer to that completion.

Oleg.

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

Reply via email to