From: Petr Mladek <pmladek@suse.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>, Tejun Heo <tj@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Josh Triplett <josh@joshtriplett.org>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jiri Kosina <jkosina@suse.cz>, Borislav Petkov <bp@suse.de>,
Michal Hocko <mhocko@suse.cz>,
linux-mm@kvack.org, Vlastimil Babka <vbabka@suse.cz>,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
Petr Mladek <pmladek@suse.com>
Subject: [PATCH v6 05/20] kthread: Add destroy_kthread_worker()
Date: Thu, 14 Apr 2016 17:14:24 +0200 [thread overview]
Message-ID: <1460646879-617-6-git-send-email-pmladek@suse.com> (raw)
In-Reply-To: <1460646879-617-1-git-send-email-pmladek@suse.com>
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 <pmladek@suse.com>
---
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-04-14 15:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-14 15:14 [PATCH v6 00/20] kthread: Use kthread worker API more widely Petr Mladek
2016-04-14 15:14 ` [PATCH v6 01/20] kthread/smpboot: Do not park in kthread_create_on_cpu() Petr Mladek
2016-04-14 15:14 ` [PATCH v6 02/20] kthread: Allow to call __kthread_create_on_node() with va_list args Petr Mladek
2016-04-14 15:14 ` [PATCH v6 03/20] kthread: Add create_kthread_worker*() Petr Mladek
2016-04-14 15:14 ` [PATCH v6 04/20] kthread: Add drain_kthread_worker() Petr Mladek
2016-04-14 15:14 ` Petr Mladek [this message]
2016-04-14 15:14 ` [PATCH v6 06/20] kthread: Detect when a kthread work is used by more workers Petr Mladek
2016-04-14 15:14 ` [PATCH v6 07/20] kthread: Initial support for delayed kthread work Petr Mladek
2016-04-14 15:14 ` [PATCH v6 08/20] kthread: Allow to cancel " Petr Mladek
2016-04-14 15:14 ` [PATCH v6 09/20] kthread: Allow to modify delayed " Petr Mladek
2016-04-14 15:14 ` [PATCH v6 10/20] kthread: Better support freezable kthread workers Petr Mladek
2016-04-14 15:14 ` [PATCH v6 11/20] mm/huge_page: Convert khugepaged() into kthread worker API Petr Mladek
2016-04-14 15:14 ` [PATCH v6 12/20] ring_buffer: Convert benchmark kthreads " Petr Mladek
2016-04-14 15:14 ` [PATCH v6 13/20] hung_task: Convert hungtaskd " Petr Mladek
2016-04-14 15:14 ` [PATCH v6 14/20] kmemleak: Convert kmemleak kthread " Petr Mladek
2016-04-14 15:14 ` [PATCH v6 15/20] ipmi: Convert kipmi " Petr Mladek
2016-04-14 15:14 ` [PATCH v6 16/20] IB/fmr_pool: Convert the cleanup thread " Petr Mladek
[not found] ` <1460646879-617-17-git-send-email-pmladek-IBi9RG/b67k@public.gmane.org>
2016-05-18 15:36 ` Doug Ledford
2016-04-14 15:14 ` [PATCH v6 17/20] memstick/r592: Better synchronize debug messages in r592_io kthread Petr Mladek
2016-04-14 15:14 ` [PATCH v6 18/20] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek
2016-04-14 15:14 ` [PATCH v6 19/20] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek
2016-04-14 15:14 ` [PATCH v6 20/20] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek
2016-08-25 8:33 ` Sebastian Andrzej Siewior
2016-08-25 11:37 ` Petr Mladek
2016-08-25 11:44 ` Sebastian Andrzej Siewior
2016-04-22 18:30 ` [PATCH v6 00/20] kthread: Use kthread worker API more widely Tejun Heo
2016-05-11 10:52 ` Petr Mladek
2016-05-25 20:42 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460646879-617-6-git-send-email-pmladek@suse.com \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=jkosina@suse.cz \
--cc=josh@joshtriplett.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).