lkml.org 
[lkml]   [2013]   [Sep]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kthread: Make kthread_create() killable.
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.



\
 
 \ /
  Last update: 2013-09-14 18:21    [W:0.084 / U:0.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site