Return-Path: Received: from cantor2.suse.de ([195.135.220.15]:58232 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933468AbbFEPB6 (ORCPT ); Fri, 5 Jun 2015 11:01:58 -0400 From: Petr Mladek To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Cc: Richard Weinberger , Steven Rostedt , David Woodhouse , linux-mtd@lists.infradead.org, Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, Chris Mason , "Paul E. McKenney" , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , live-patching@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [RFC PATCH 07/18] kthread: Make iterant kthreads freezable by default Date: Fri, 5 Jun 2015 17:01:06 +0200 Message-Id: <1433516477-5153-8-git-send-email-pmladek@suse.cz> In-Reply-To: <1433516477-5153-1-git-send-email-pmladek@suse.cz> References: <1433516477-5153-1-git-send-email-pmladek@suse.cz> Sender: linux-nfs-owner@vger.kernel.org List-ID: Many kthreads already calls set_freezable() before they enter the main cycle. One of the reasons for creating iterant kthreads is to create a safe point for freezing and make even more kthreads properly freezable. Therefore it would make sense to set all iterant kthreads freezable by default. However some kthreads might be hard to make properly freezable. For example, if they do non-interruptible sleeps. They would need to explicitly clear PF_NOFREEZE flag in the init() call. But it should be avoided whenever possible. Signed-off-by: Petr Mladek --- kernel/kthread.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 185902d0e293..e34f67cb8ecf 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -412,13 +412,20 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data), * * This function defines the work flow of iterant kthreads. It calls * the given callbacks. Also it defines and implements a common - * check point for freezing and stopping. + * check point for freezing, stopping, and signal handling. + * + * IMPORTANT: Iterant kthreads are freezable by default. The functions + * defined in the given struct kthread_iterant still have to explicitly + * call try_to_freeze() after each interruptible sleep. They must avoid + * non-interruptible sleep if freezing is allowed. */ static int kthread_iterant_fn(void *kti_ptr) { struct kthread_iterant *kti = kti_ptr; void *data = kti->data; + set_freezable(); + if (kti->init) kti->init(data); -- 1.8.5.6