Re: [PATCH v3 07/22] kthread: Detect when a kthread work is used by more workers
From: Tejun Heo <tj@kernel.org>
Date: 2015-11-24 14:49:49
Also in:
linux-mm, lkml
Hello, Petr. On Tue, Nov 24, 2015 at 11:06:50AM +0100, Petr Mladek wrote:
quoted
quoted
@@ -610,6 +625,12 @@ repeat: if (work) { __set_current_state(TASK_RUNNING); work->func(work); + + spin_lock_irq(&worker->lock); + /* Allow to queue the work into another worker */ + if (!kthread_work_pending(work)) + work->worker = NULL; + spin_unlock_irq(&worker->lock);Doesn't this mean that the work item can't be freed from its callback? That pattern tends to happen regularly.I am not sure if I understand your question. Do you mean switching work->func during the life time of the struct kthread_work? This should not be affected by the above code.
So, something like the following.
void my_work_fn(work)
{
struct my_struct *s = container_of(work, ...);
do something with s;
kfree(s);
}
and the queuer does
struct my_struct *s = kmalloc(sizeof(*s));
init s and s->work;
queue(&s->work);
expecting s to be freed on completion. IOW, you can't expect the work
item to remain accessible once the work function starts executing.
The above code allows to queue an _unused_ kthread_work into any kthread_worker. For example, it is needed for khugepaged, see http://marc.info/?l=linux-kernel&m=144785344924871&w=2 The work is static but the worker can be started/stopped (allocated/freed) repeatedly. It means that the work need to be usable with many workers. But it is associated only with one worker when being used.
It can just re-init work items when it restarts workers, right? Thanks. -- tejun -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>