From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Mladek Subject: [PATCH v4 00/22] kthread: Use kthread worker API more widely Date: Mon, 25 Jan 2016 16:44:49 +0100 Message-ID: <1453736711-6703-1-git-send-email-pmladek@suse.com> Return-path: Sender: owner-linux-mm@kvack.org 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 , Catalin Marinas , linux-watchdog@vger.kernel.org, Corey Minyard , openipmi-developer@lists.sourceforge.net, Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, Maxim Levitsky , Zhang Rui , Eduardo Valentin , Jacob Pan List-Id: linux-rdma@vger.kernel.org My intention is to make it easier to manipulate and maintain kthreads. Especially, I want to replace all the custom main cycles with a generic one. Also I want to make the kthreads sleep in a consistent state in a common place when there is no work. My first attempt was with a brand new API (iterant kthread), see http://thread.gmane.org/gmane.linux.kernel.api/11892 . But I was directed to improve the existing kthread worker API. This is the 3rd iteration of the new direction. 1st patch: add support to check if a timer callback is being called 2nd..12th patches: improve the existing kthread worker API 13th..18th, 20th, 22nd patches: convert several kthreads into the kthread worker API, namely: khugepaged, ring buffer benchmark, hung_task, kmemleak, ipmi, IB/fmr_pool, memstick/r592, intel_powerclamp 19th, 21st patches: do some preparation steps; they usually do some clean up that makes sense even without the conversion. Changes against v3: + allow to free struct kthread_work from its callback; do not touch the struct from the worker post-mortem; as a side effect, the structure must be reinitialized when the worker gets restarted; updated khugepaged, and kmemleak accordingly + call del_timer_sync() with worker->lock; instead, detect canceling in the timer callback and give up an attempt to get the lock there; do busy loop with spin_is_locked() to reduce cache bouncing + renamed ipmi+func() -> ipmi_kthread_worker_func() as suggested by Corey + added some collected Reviewed-by Changes against v2: + used worker->lock to synchronize the operations with the work instead of the PENDING bit as suggested by Tejun Heo; it simplified the implementation in several ways + added timer_active(); used it together with del_timer_sync() to cancel the work a less tricky way + removed the controversial conversion of the RCU kthreads + added several other examples: hung_task, kmemleak, ipmi, IB/fmr_pool, memstick/r592, intel_powerclamp + the helper fixes for the ring buffer benchmark has been improved as suggested by Steven; they already are in the Linus tree now + fixed a possible race between the check for existing khugepaged worker and queuing the work Changes against v1: + remove wrappers to manipulate the scheduling policy and priority + remove questionable wakeup_and_destroy_kthread_worker() variant + do not check for chained work when draining the queue + allocate struct kthread worker in create_kthread_work() and use more simple checks for running worker + add support for delayed kthread works and use them instead of waiting inside the works + rework the "unrelated" fixes for the ring buffer benchmark as discussed in the 1st RFC; also sent separately + convert also the consumer in the ring buffer benchmark I have tested this patch set against the stable Linus tree for 4.5-rc1. Comments against v3 can be found at http://thread.gmane.org/gmane.linux.kernel.mm/141493 Petr Mladek (22): timer: Allow to check when the timer callback has not finished yet kthread/smpboot: Do not park in kthread_create_on_cpu() kthread: Allow to call __kthread_create_on_node() with va_list args kthread: Add create_kthread_worker*() kthread: Add drain_kthread_worker() kthread: Add destroy_kthread_worker() kthread: Detect when a kthread work is used by more workers kthread: Initial support for delayed kthread work kthread: Allow to cancel kthread work kthread: Allow to modify delayed kthread work kthread: Better support freezable kthread workers kthread: Use try_lock_kthread_work() in flush_kthread_work() mm/huge_page: Convert khugepaged() into kthread worker API ring_buffer: Convert benchmark kthreads into kthread worker API hung_task: Convert hungtaskd into kthread worker API kmemleak: Convert kmemleak kthread into kthread worker API ipmi: Convert kipmi kthread into kthread worker API IB/fmr_pool: Convert the cleanup thread into kthread worker API memstick/r592: Better synchronize debug messages in r592_io kthread memstick/r592: convert r592_io kthread into kthread worker API thermal/intel_powerclamp: Remove duplicated code that starts the kthread thermal/intel_powerclamp: Convert the kthread to kthread worker API drivers/char/ipmi/ipmi_si_intf.c | 121 ++++--- drivers/infiniband/core/fmr_pool.c | 54 ++- drivers/memstick/host/r592.c | 61 ++-- drivers/memstick/host/r592.h | 5 +- drivers/thermal/intel_powerclamp.c | 302 +++++++++-------- include/linux/kthread.h | 56 ++++ include/linux/timer.h | 2 + kernel/hung_task.c | 41 ++- kernel/kthread.c | 619 +++++++++++++++++++++++++++++++---- kernel/smpboot.c | 5 + kernel/time/timer.c | 24 ++ kernel/trace/ring_buffer_benchmark.c | 133 ++++---- mm/huge_memory.c | 138 ++++---- mm/kmemleak.c | 87 +++-- 14 files changed, 1151 insertions(+), 497 deletions(-) CC: Catalin Marinas CC: linux-watchdog@vger.kernel.org CC: Corey Minyard CC: openipmi-developer@lists.sourceforge.net CC: Doug Ledford CC: Sean Hefty CC: Hal Rosenstock CC: linux-rdma@vger.kernel.org CC: Maxim Levitsky CC: Zhang Rui CC: Eduardo Valentin CC: Jacob Pan CC: linux-pm@vger.kernel.org -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757768AbcAYPrg (ORCPT ); Mon, 25 Jan 2016 10:47:36 -0500 Received: from mx2.suse.de ([195.135.220.15]:35909 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757734AbcAYPr2 (ORCPT ); Mon, 25 Jan 2016 10:47:28 -0500 From: Petr Mladek 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 , Catalin Marinas , linux-watchdog@vger.kernel.org, Corey Minyard , openipmi-developer@lists.sourceforge.net, Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, Maxim Levitsky , Zhang Rui , Eduardo Valentin , Jacob Pan , linux-pm@vger.kernel.org Subject: [PATCH v4 00/22] kthread: Use kthread worker API more widely Date: Mon, 25 Jan 2016 16:44:49 +0100 Message-Id: <1453736711-6703-1-git-send-email-pmladek@suse.com> X-Mailer: git-send-email 1.8.5.6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org My intention is to make it easier to manipulate and maintain kthreads. Especially, I want to replace all the custom main cycles with a generic one. Also I want to make the kthreads sleep in a consistent state in a common place when there is no work. My first attempt was with a brand new API (iterant kthread), see http://thread.gmane.org/gmane.linux.kernel.api/11892 . But I was directed to improve the existing kthread worker API. This is the 3rd iteration of the new direction. 1st patch: add support to check if a timer callback is being called 2nd..12th patches: improve the existing kthread worker API 13th..18th, 20th, 22nd patches: convert several kthreads into the kthread worker API, namely: khugepaged, ring buffer benchmark, hung_task, kmemleak, ipmi, IB/fmr_pool, memstick/r592, intel_powerclamp 19th, 21st patches: do some preparation steps; they usually do some clean up that makes sense even without the conversion. Changes against v3: + allow to free struct kthread_work from its callback; do not touch the struct from the worker post-mortem; as a side effect, the structure must be reinitialized when the worker gets restarted; updated khugepaged, and kmemleak accordingly + call del_timer_sync() with worker->lock; instead, detect canceling in the timer callback and give up an attempt to get the lock there; do busy loop with spin_is_locked() to reduce cache bouncing + renamed ipmi+func() -> ipmi_kthread_worker_func() as suggested by Corey + added some collected Reviewed-by Changes against v2: + used worker->lock to synchronize the operations with the work instead of the PENDING bit as suggested by Tejun Heo; it simplified the implementation in several ways + added timer_active(); used it together with del_timer_sync() to cancel the work a less tricky way + removed the controversial conversion of the RCU kthreads + added several other examples: hung_task, kmemleak, ipmi, IB/fmr_pool, memstick/r592, intel_powerclamp + the helper fixes for the ring buffer benchmark has been improved as suggested by Steven; they already are in the Linus tree now + fixed a possible race between the check for existing khugepaged worker and queuing the work Changes against v1: + remove wrappers to manipulate the scheduling policy and priority + remove questionable wakeup_and_destroy_kthread_worker() variant + do not check for chained work when draining the queue + allocate struct kthread worker in create_kthread_work() and use more simple checks for running worker + add support for delayed kthread works and use them instead of waiting inside the works + rework the "unrelated" fixes for the ring buffer benchmark as discussed in the 1st RFC; also sent separately + convert also the consumer in the ring buffer benchmark I have tested this patch set against the stable Linus tree for 4.5-rc1. Comments against v3 can be found at http://thread.gmane.org/gmane.linux.kernel.mm/141493 Petr Mladek (22): timer: Allow to check when the timer callback has not finished yet kthread/smpboot: Do not park in kthread_create_on_cpu() kthread: Allow to call __kthread_create_on_node() with va_list args kthread: Add create_kthread_worker*() kthread: Add drain_kthread_worker() kthread: Add destroy_kthread_worker() kthread: Detect when a kthread work is used by more workers kthread: Initial support for delayed kthread work kthread: Allow to cancel kthread work kthread: Allow to modify delayed kthread work kthread: Better support freezable kthread workers kthread: Use try_lock_kthread_work() in flush_kthread_work() mm/huge_page: Convert khugepaged() into kthread worker API ring_buffer: Convert benchmark kthreads into kthread worker API hung_task: Convert hungtaskd into kthread worker API kmemleak: Convert kmemleak kthread into kthread worker API ipmi: Convert kipmi kthread into kthread worker API IB/fmr_pool: Convert the cleanup thread into kthread worker API memstick/r592: Better synchronize debug messages in r592_io kthread memstick/r592: convert r592_io kthread into kthread worker API thermal/intel_powerclamp: Remove duplicated code that starts the kthread thermal/intel_powerclamp: Convert the kthread to kthread worker API drivers/char/ipmi/ipmi_si_intf.c | 121 ++++--- drivers/infiniband/core/fmr_pool.c | 54 ++- drivers/memstick/host/r592.c | 61 ++-- drivers/memstick/host/r592.h | 5 +- drivers/thermal/intel_powerclamp.c | 302 +++++++++-------- include/linux/kthread.h | 56 ++++ include/linux/timer.h | 2 + kernel/hung_task.c | 41 ++- kernel/kthread.c | 619 +++++++++++++++++++++++++++++++---- kernel/smpboot.c | 5 + kernel/time/timer.c | 24 ++ kernel/trace/ring_buffer_benchmark.c | 133 ++++---- mm/huge_memory.c | 138 ++++---- mm/kmemleak.c | 87 +++-- 14 files changed, 1151 insertions(+), 497 deletions(-) CC: Catalin Marinas CC: linux-watchdog@vger.kernel.org CC: Corey Minyard CC: openipmi-developer@lists.sourceforge.net CC: Doug Ledford CC: Sean Hefty CC: Hal Rosenstock CC: linux-rdma@vger.kernel.org CC: Maxim Levitsky CC: Zhang Rui CC: Eduardo Valentin CC: Jacob Pan CC: linux-pm@vger.kernel.org -- 1.8.5.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by kanga.kvack.org (Postfix) with ESMTP id 2A9376B0254 for ; Mon, 25 Jan 2016 10:47:28 -0500 (EST) Received: by mail-wm0-f43.google.com with SMTP id r129so69522748wmr.0 for ; Mon, 25 Jan 2016 07:47:28 -0800 (PST) Received: from mx2.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id az4si29165555wjb.100.2016.01.25.07.47.26 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Jan 2016 07:47:26 -0800 (PST) From: Petr Mladek Subject: [PATCH v4 00/22] kthread: Use kthread worker API more widely Date: Mon, 25 Jan 2016 16:44:49 +0100 Message-Id: <1453736711-6703-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 , Catalin Marinas , linux-watchdog@vger.kernel.org, Corey Minyard , openipmi-developer@lists.sourceforge.net, Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, Maxim Levitsky , Zhang Rui , Eduardo Valentin , Jacob Pan , linux-pm@vger.kernel.org My intention is to make it easier to manipulate and maintain kthreads. Especially, I want to replace all the custom main cycles with a generic one. Also I want to make the kthreads sleep in a consistent state in a common place when there is no work. My first attempt was with a brand new API (iterant kthread), see http://thread.gmane.org/gmane.linux.kernel.api/11892 . But I was directed to improve the existing kthread worker API. This is the 3rd iteration of the new direction. 1st patch: add support to check if a timer callback is being called 2nd..12th patches: improve the existing kthread worker API 13th..18th, 20th, 22nd patches: convert several kthreads into the kthread worker API, namely: khugepaged, ring buffer benchmark, hung_task, kmemleak, ipmi, IB/fmr_pool, memstick/r592, intel_powerclamp 19th, 21st patches: do some preparation steps; they usually do some clean up that makes sense even without the conversion. Changes against v3: + allow to free struct kthread_work from its callback; do not touch the struct from the worker post-mortem; as a side effect, the structure must be reinitialized when the worker gets restarted; updated khugepaged, and kmemleak accordingly + call del_timer_sync() with worker->lock; instead, detect canceling in the timer callback and give up an attempt to get the lock there; do busy loop with spin_is_locked() to reduce cache bouncing + renamed ipmi+func() -> ipmi_kthread_worker_func() as suggested by Corey + added some collected Reviewed-by Changes against v2: + used worker->lock to synchronize the operations with the work instead of the PENDING bit as suggested by Tejun Heo; it simplified the implementation in several ways + added timer_active(); used it together with del_timer_sync() to cancel the work a less tricky way + removed the controversial conversion of the RCU kthreads + added several other examples: hung_task, kmemleak, ipmi, IB/fmr_pool, memstick/r592, intel_powerclamp + the helper fixes for the ring buffer benchmark has been improved as suggested by Steven; they already are in the Linus tree now + fixed a possible race between the check for existing khugepaged worker and queuing the work Changes against v1: + remove wrappers to manipulate the scheduling policy and priority + remove questionable wakeup_and_destroy_kthread_worker() variant + do not check for chained work when draining the queue + allocate struct kthread worker in create_kthread_work() and use more simple checks for running worker + add support for delayed kthread works and use them instead of waiting inside the works + rework the "unrelated" fixes for the ring buffer benchmark as discussed in the 1st RFC; also sent separately + convert also the consumer in the ring buffer benchmark I have tested this patch set against the stable Linus tree for 4.5-rc1. Comments against v3 can be found at http://thread.gmane.org/gmane.linux.kernel.mm/141493 Petr Mladek (22): timer: Allow to check when the timer callback has not finished yet kthread/smpboot: Do not park in kthread_create_on_cpu() kthread: Allow to call __kthread_create_on_node() with va_list args kthread: Add create_kthread_worker*() kthread: Add drain_kthread_worker() kthread: Add destroy_kthread_worker() kthread: Detect when a kthread work is used by more workers kthread: Initial support for delayed kthread work kthread: Allow to cancel kthread work kthread: Allow to modify delayed kthread work kthread: Better support freezable kthread workers kthread: Use try_lock_kthread_work() in flush_kthread_work() mm/huge_page: Convert khugepaged() into kthread worker API ring_buffer: Convert benchmark kthreads into kthread worker API hung_task: Convert hungtaskd into kthread worker API kmemleak: Convert kmemleak kthread into kthread worker API ipmi: Convert kipmi kthread into kthread worker API IB/fmr_pool: Convert the cleanup thread into kthread worker API memstick/r592: Better synchronize debug messages in r592_io kthread memstick/r592: convert r592_io kthread into kthread worker API thermal/intel_powerclamp: Remove duplicated code that starts the kthread thermal/intel_powerclamp: Convert the kthread to kthread worker API drivers/char/ipmi/ipmi_si_intf.c | 121 ++++--- drivers/infiniband/core/fmr_pool.c | 54 ++- drivers/memstick/host/r592.c | 61 ++-- drivers/memstick/host/r592.h | 5 +- drivers/thermal/intel_powerclamp.c | 302 +++++++++-------- include/linux/kthread.h | 56 ++++ include/linux/timer.h | 2 + kernel/hung_task.c | 41 ++- kernel/kthread.c | 619 +++++++++++++++++++++++++++++++---- kernel/smpboot.c | 5 + kernel/time/timer.c | 24 ++ kernel/trace/ring_buffer_benchmark.c | 133 ++++---- mm/huge_memory.c | 138 ++++---- mm/kmemleak.c | 87 +++-- 14 files changed, 1151 insertions(+), 497 deletions(-) CC: Catalin Marinas CC: linux-watchdog@vger.kernel.org CC: Corey Minyard CC: openipmi-developer@lists.sourceforge.net CC: Doug Ledford CC: Sean Hefty CC: Hal Rosenstock CC: linux-rdma@vger.kernel.org CC: Maxim Levitsky CC: Zhang Rui CC: Eduardo Valentin CC: Jacob Pan CC: linux-pm@vger.kernel.org -- 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