All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: chenguanyou <chenguanyou9338@gmail.com>, linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, keescook@chromium.org,
	mhocko@suse.com, lukas.bulwahn@gmail.com, gpiccoli@canonical.com,
	chenguanyou <chenguanyou@xiaomi.com>
Subject: Re: [PATCH] hungtask: add filter kthread/check comm
Date: Wed, 19 May 2021 13:28:55 +0200	[thread overview]
Message-ID: <e573a737-0195-aec0-032e-4a7bdb8553f7@suse.cz> (raw)
In-Reply-To: <20210518111616.26695-1-chenguanyou@xiaomi.com>

On 5/18/21 1:16 PM, chenguanyou wrote:

The description is missing.

> Signed-off-by: chenguanyou <chenguanyou@xiaomi.com>
> ---
>  include/linux/sched/sysctl.h |  4 ++++
>  kernel/hung_task.c           | 17 +++++++++++++++++
>  kernel/sysctl.c              | 15 +++++++++++++++
>  lib/Kconfig.debug            | 23 +++++++++++++++++++++++
>  4 files changed, 59 insertions(+)
> 
> diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
> index 3c31ba88aca5..e8a9a28215bf 100644
> --- a/include/linux/sched/sysctl.h
> +++ b/include/linux/sched/sysctl.h
> @@ -14,11 +14,15 @@ extern unsigned int sysctl_hung_task_all_cpu_backtrace;
>  #define sysctl_hung_task_all_cpu_backtrace 0
>  #endif /* CONFIG_SMP */
>  
> +#define TASK_COMM_LEN 16
> +
>  extern int	     sysctl_hung_task_check_count;
>  extern unsigned int  sysctl_hung_task_panic;
>  extern unsigned long sysctl_hung_task_timeout_secs;
>  extern unsigned long sysctl_hung_task_check_interval_secs;
>  extern int sysctl_hung_task_warnings;
> +extern unsigned int sysctl_hung_task_filter_kthread;
> +extern char sysctl_hung_task_check_comm[TASK_COMM_LEN];
>  int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
>  		void *buffer, size_t *lenp, loff_t *ppos);
>  #else
> diff --git a/kernel/hung_task.c b/kernel/hung_task.c
> index 396ebaebea3f..e018563d4882 100644
> --- a/kernel/hung_task.c
> +++ b/kernel/hung_task.c
> @@ -23,6 +23,7 @@
>  #include <linux/sched/sysctl.h>
>  
>  #include <trace/events/sched.h>
> +#include <linux/string.h>
>  
>  /*
>   * The number of tasks checked:
> @@ -48,6 +49,16 @@ unsigned long __read_mostly sysctl_hung_task_timeout_secs = CONFIG_DEFAULT_HUNG_
>   */
>  unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
>  
> +/*
> + * Non zero means no checking kthread
> + */
> +unsigned int __read_mostly sysctl_hung_task_filter_kthread = CONFIG_DEFAULT_HUNG_TASK_FILTER_KTHREAD;
> +
> +/*
> + * Only one
> + */
> +char __read_mostly sysctl_hung_task_check_comm[TASK_COMM_LEN] = CONFIG_DEFAULT_HUNG_TASK_CHECK_COMM;
> +
>  int __read_mostly sysctl_hung_task_warnings = 10;
>  
>  static int __read_mostly did_panic;
> @@ -88,6 +99,12 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
>  {
>  	unsigned long switch_count = t->nvcsw + t->nivcsw;
>  
> +	if (unlikely(strlen(sysctl_hung_task_check_comm) && !strstr(t->comm, sysctl_hung_task_check_comm)))
> +		return;
> +
> +	if (unlikely(sysctl_hung_task_filter_kthread && t->flags & PF_KTHREAD))
> +		return;
> +
>  	/*
>  	 * Ensure the task is not frozen.
>  	 * Also, skip vfork and any other user process that freezer should skip.
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 62fbd09b5dc1..157c47a8430a 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2519,6 +2519,21 @@ static struct ctl_table kern_table[] = {
>  		.proc_handler	= proc_dointvec_minmax,
>  		.extra1		= &neg_one,
>  	},
> +	{
> +		.procname	= "hung_task_filter_kthread",
> +		.data		= &sysctl_hung_task_filter_kthread,
> +		.maxlen		= sizeof(int),
> +		.mode		= 0644,
> +		.extra1		= SYSCTL_ZERO,
> +		.extra2		= SYSCTL_ONE,
> +	},
> +	{
> +		.procname	= "hung_task_check_comm",
> +		.data		= &sysctl_hung_task_check_comm,
> +		.maxlen		= TASK_COMM_LEN,
> +		.mode		= 0644,
> +		.proc_handler	= proc_dostring,
> +	},
>  #endif
>  #ifdef CONFIG_RT_MUTEXES
>  	{
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 2c7f46b366f1..59cfa9e230ee 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1101,6 +1101,29 @@ config DEFAULT_HUNG_TASK_TIMEOUT
>  	  A timeout of 0 disables the check.  The default is two minutes.
>  	  Keeping the default should be fine in most cases.
>  
> +config DEFAULT_HUNG_TASK_FILTER_KTHREAD
> +	bool "Default filter kthread for hung task"
> +	depends on DETECT_HUNG_TASK
> +	default 0
> +	help
> +	  This option controls filter kthread used to determine when
> +	  a kernel task has become "state=TASK_UNINTERRUPTIBLE" and should be skip.
> +
> +	  It can be adjusted at runtime via the kernel.hung_task_filter_kthread
> +	  sysctl or by writing a value to
> +	  /proc/sys/kernel/hung_task_filter_kthread.
> +
> +	  A filter of 1 disables the check
> +
> +config DEFAULT_HUNG_TASK_CHECK_COMM
> +	string "Default check only one comm"
> +	depends on DETECT_HUNG_TASK
> +	default ""
> +	help
> +	  It can be adjusted at runtime via the kernel.hung_task_check_comm
> +	  sysctl or by writing a value to
> +	  /proc/sys/kernel/hung_task_check_comm.
> +
>  config BOOTPARAM_HUNG_TASK_PANIC
>  	bool "Panic (Reboot) On Hung Tasks"
>  	depends on DETECT_HUNG_TASK
> 


  reply	other threads:[~2021-05-19 11:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 11:16 [PATCH] hungtask: add filter kthread/check comm chenguanyou
2021-05-19 11:28 ` Vlastimil Babka [this message]
2021-05-19 12:13 chenguanyou
2021-05-19 13:06 ` Michal Hocko
2021-05-19 17:53 ` Randy Dunlap
     [not found]   ` <CAHS3RMVYbHTzD6JnOmE331qSbcnvuYnBe0jraNuuLc0Z2NnStg@mail.gmail.com>
2021-05-21  8:31     ` Michal Hocko
2021-05-21 13:25 chenguanyou
2021-05-21 16:37 ` Randy Dunlap
2021-05-21 13:25 chenguanyou
2021-05-22 21:51 ` Andrew Morton
     [not found]   ` <CAHS3RMWjuB98TzvcYyQ0qtNYOxDeM7W1YmyqDYs=H-cn-VsVdw@mail.gmail.com>
2021-05-25  7:26     ` Michal Hocko

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=e573a737-0195-aec0-032e-4a7bdb8553f7@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=chenguanyou9338@gmail.com \
    --cc=chenguanyou@xiaomi.com \
    --cc=gpiccoli@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=mhocko@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.