From: chenguanyou <chenguanyou9338@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, keescook@chromium.org,
mhocko@suse.com, lukas.bulwahn@gmail.com, vbabka@suse.cz,
gpiccoli@canonical.com, chenguanyou <chenguanyou@xiaomi.com>
Subject: [PATCH v2] hungtask: add filter kthread
Date: Thu, 5 Aug 2021 21:47:47 +0800 [thread overview]
Message-ID: <20210805134747.29621-1-chenguanyou@xiaomi.com> (raw)
Some kernel threads are always in D state, when we enable hung_task,
it will misjudge, we should skip these to narrow the scope.
exp mediatek:
root 435 435 2 0 0 mtk_lpm_monitor_thread 0 D LPM-0
root 436 436 2 0 0 mtk_lpm_monitor_thread 0 D LPM-1
root 437 437 2 0 0 mtk_lpm_monitor_thread 0 D LPM-2
root 438 438 2 0 0 mtk_lpm_monitor_thread 0 D LPM-3
root 439 439 2 0 0 mtk_lpm_monitor_thread 0 D LPM-4
root 440 440 2 0 0 mtk_lpm_monitor_thread 0 D LPM-5
root 441 441 2 0 0 mtk_lpm_monitor_thread 0 D LPM-6
root 442 442 2 0 0 mtk_lpm_monitor_thread 0 D LPM-7
Signed-off-by: chenguanyou <chenguanyou@xiaomi.com>
---
Documentation/admin-guide/sysctl/kernel.rst | 10 ++++++++++
include/linux/sched/sysctl.h | 1 +
kernel/hung_task.c | 8 ++++++++
kernel/sysctl.c | 9 +++++++++
lib/Kconfig.debug | 15 +++++++++++++++
5 files changed, 43 insertions(+)
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index 68b21395a743..3c7c74b26d95 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -405,6 +405,16 @@ This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
-1: report an infinite number of warnings.
+hung_task_filter_kthread
+========================
+
+We should skip kthread when a hung task is detected.
+This file shows up if ``CONFIG_DEFAULT_HUNG_TASK_FILTER_KTHREAD`` is enabled.
+
+= =========================================================
+0 Not skip detect kthread.
+1 Skip detect kthread.
+= =========================================================
hyperv_record_panic_msg
=======================
diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
index db2c0f34aaaf..2b8b01b57559 100644
--- a/include/linux/sched/sysctl.h
+++ b/include/linux/sched/sysctl.h
@@ -19,6 +19,7 @@ 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;
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..74ad75c2dde8 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -48,6 +48,11 @@ 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;
+
int __read_mostly sysctl_hung_task_warnings = 10;
static int __read_mostly did_panic;
@@ -88,6 +93,9 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
{
unsigned long switch_count = t->nvcsw + t->nivcsw;
+ 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 d4a78e08f6d8..62067b9db486 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2513,6 +2513,15 @@ 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,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE,
+ },
#endif
#ifdef CONFIG_RT_MUTEXES
{
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 678c13967580..d7063f955987 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1110,6 +1110,21 @@ 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
+ int "Default filter kthread for hung task"
+ depends on DETECT_HUNG_TASK
+ range 0 1
+ default 0
+ help
+ This option controls filter kthread uses to determine when
+ a kernel task has become "state=TASK_UNINTERRUPTIBLE" and should be skipped.
+
+ 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 BOOTPARAM_HUNG_TASK_PANIC
bool "Panic (Reboot) On Hung Tasks"
depends on DETECT_HUNG_TASK
--
2.17.1
next reply other threads:[~2021-08-05 13:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-05 13:47 chenguanyou [this message]
2021-08-05 14:11 ` Michal Hocko
2021-08-05 14:47 ` chenguanyou
2021-08-05 23:43 ` [PATCH " Andrew Morton
2021-08-07 13:16 ` chenguanyou
2021-08-09 9:17 ` [PATCH " Michal Hocko
2021-08-09 11:52 ` chenguanyou
2021-08-09 11:57 ` [PATCH " Michal Hocko
2021-08-09 12:24 ` chenguanyou
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=20210805134747.29621-1-chenguanyou@xiaomi.com \
--to=chenguanyou9338@gmail.com \
--cc=akpm@linux-foundation.org \
--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 \
--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
all inboxes | Powered by JetHome®