[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250924034100.3701520-2-sunjunchao@bytedance.com>
Date: Wed, 24 Sep 2025 11:40:59 +0800
From: Julian Sun <sunjunchao@...edance.com>
To: cgroups@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: akpm@...ux-foundation.org,
lance.yang@...ux.dev,
mhiramat@...nel.org,
yangyicong@...ilicon.com,
will@...nel.org,
dianders@...omium.org,
mingo@...nel.org,
lihuafei1@...wei.com,
hannes@...xchg.org,
mhocko@...nel.org,
roman.gushchin@...ux.dev,
shakeel.butt@...ux.dev,
muchun.song@...ux.dev,
tj@...nel.org,
peterz@...radead.org
Subject: [PATCH v2 1/2] hung_task: Introduce touch_hung_task_detector().
In the kernel, long waits can trigger hung task warnings. However, some
warnings are undesirable and unnecessary - for example, a hung task
warning triggered when a background kworker waits for writeback
completion during resource cleanup(like the context of
mem_cgroup_css_free()). This kworker does not affect any user behavior
and there is no erroneous behavior at the kernel code level, yet it
triggers an annoying hung task warning.
To eliminate such warnings, this patch introduces
touch_hung_task_detector() to allow some tasks ignored by hung task
detector.
Signed-off-by: Julian Sun <sunjunchao@...edance.com>
Suggested-by: Andrew Morton <akpm@...ux-foundation.org>
Suggested-by: Lance Yang <lance.yang@...ux.dev>
---
include/linux/nmi.h | 2 ++
kernel/hung_task.c | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/include/linux/nmi.h b/include/linux/nmi.h
index cf3c6ab408aa..61fc2ad234de 100644
--- a/include/linux/nmi.h
+++ b/include/linux/nmi.h
@@ -59,8 +59,10 @@ static inline void touch_all_softlockup_watchdogs(void) { }
#ifdef CONFIG_DETECT_HUNG_TASK
void reset_hung_task_detector(void);
+void touch_hung_task_detector(struct task_struct *t);
#else
static inline void reset_hung_task_detector(void) { }
+static inline void touch_hung_task_detector(struct task_struct *t) { }
#endif
/*
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index 8708a1205f82..6409d3d4bd36 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -184,6 +184,11 @@ static inline void debug_show_blocker(struct task_struct *task)
}
#endif
+void touch_hung_task_detector(struct task_struct *t)
+{
+ t->last_switch_count = ULONG_MAX;
+}
+
static void check_hung_task(struct task_struct *t, unsigned long timeout)
{
unsigned long switch_count = t->nvcsw + t->nivcsw;
@@ -203,6 +208,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
if (unlikely(!switch_count))
return;
+ /* The task doesn't want to trigger the hung task warning. */
+ if (unlikely(t->last_switch_count == ULONG_MAX))
+ return;
+
if (switch_count != t->last_switch_count) {
t->last_switch_count = switch_count;
t->last_switch_time = jiffies;
@@ -317,6 +326,10 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
!(state & TASK_WAKEKILL) &&
!(state & TASK_NOLOAD))
check_hung_task(t, timeout);
+ else if (unlikely(t->last_switch_count == ULONG_MAX)) {
+ t->last_switch_count = t->nvcsw + t->nivcsw;
+ t->last_switch_time = jiffies;
+ }
}
unlock:
rcu_read_unlock();
--
2.39.5
Powered by blists - more mailing lists