From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by kanga.kvack.org (Postfix) with ESMTP id EEEBE828DF for ; Thu, 14 Apr 2016 11:15:24 -0400 (EDT) Received: by mail-lf0-f72.google.com with SMTP id d19so48859880lfb.0 for ; Thu, 14 Apr 2016 08:15:24 -0700 (PDT) Received: from mx2.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id 131si35277030wmg.123.2016.04.14.08.15.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Apr 2016 08:15:23 -0700 (PDT) From: Petr Mladek Subject: [PATCH v6 05/20] kthread: Add destroy_kthread_worker() Date: Thu, 14 Apr 2016 17:14:24 +0200 Message-Id: <1460646879-617-6-git-send-email-pmladek@suse.com> In-Reply-To: <1460646879-617-1-git-send-email-pmladek@suse.com> References: <1460646879-617-1-git-send-email-pmladek@suse.com> Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Cc: Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek The current kthread worker users call flush() and stop() explicitly. This function drains the worker, stops it, and frees the kthread_worker struct in one call. It is supposed to be used together with create_kthread_worker*() that allocates struct kthread_worker. Also note that drain() correctly handles self-queuing works in compare with flush(). Signed-off-by: Petr Mladek --- include/linux/kthread.h | 2 ++ kernel/kthread.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 468011efa68d..a36604fa8aa2 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -136,4 +136,6 @@ bool queue_kthread_work(struct kthread_worker *worker, void flush_kthread_work(struct kthread_work *work); void flush_kthread_worker(struct kthread_worker *worker); +void destroy_kthread_worker(struct kthread_worker *worker); + #endif /* _LINUX_KTHREAD_H */ diff --git a/kernel/kthread.c b/kernel/kthread.c index 6051aa9d93c6..441651765f08 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -852,3 +852,24 @@ void drain_kthread_worker(struct kthread_worker *worker) spin_unlock_irq(&worker->lock); } EXPORT_SYMBOL(drain_kthread_worker); + +/** + * destroy_kthread_worker - destroy a kthread worker + * @worker: worker to be destroyed + * + * Drain and destroy @worker. It has the same conditions + * for use as drain_kthread_worker(), see above. + */ +void destroy_kthread_worker(struct kthread_worker *worker) +{ + struct task_struct *task; + + task = worker->task; + if (WARN_ON(!task)) + return; + + drain_kthread_worker(worker); + kthread_stop(task); + kfree(worker); +} +EXPORT_SYMBOL(destroy_kthread_worker); -- 1.8.5.6 -- 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: email@kvack.org