[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250925223310.66e769299f7d07491578151d@kernel.org>
Date: Thu, 25 Sep 2025 22:33:10 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Julian Sun <sunjunchao@...edance.com>
Cc: cgroups@...r.kernel.org, linux-kernel@...r.kernel.org,
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: Re: [PATCH v2 1/2] hung_task: Introduce touch_hung_task_detector().
On Wed, 24 Sep 2025 11:40:59 +0800
Julian Sun <sunjunchao@...edance.com> wrote:
> 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.
>
Looks good to me.
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@...nel.org>
Thanks,
> 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
>
--
Masami Hiramatsu (Google) <mhiramat@...nel.org>
Powered by blists - more mailing lists