From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Julian Sun <sunjunchao@bytedance.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, lance.yang@linux.dev,
mhiramat@kernel.org, yangyicong@hisilicon.com, will@kernel.org,
dianders@chromium.org, mingo@kernel.org, lihuafei1@huawei.com,
hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev,
shakeel.butt@linux.dev, muchun.song@linux.dev, tj@kernel.org,
peterz@infradead.org
Subject: Re: [PATCH v2 1/2] hung_task: Introduce touch_hung_task_detector().
Date: Thu, 25 Sep 2025 22:33:10 +0900 [thread overview]
Message-ID: <20250925223310.66e769299f7d07491578151d@kernel.org> (raw)
In-Reply-To: <20250924034100.3701520-2-sunjunchao@bytedance.com>
On Wed, 24 Sep 2025 11:40:59 +0800
Julian Sun <sunjunchao@bytedance.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@kernel.org>
Thanks,
> Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Suggested-by: Lance Yang <lance.yang@linux.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@kernel.org>
next prev parent reply other threads:[~2025-09-25 13:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 3:40 [PATCH v2 0/2] Suppress undesirable hung task warnings Julian Sun
2025-09-24 3:40 ` [PATCH v2 1/2] hung_task: Introduce touch_hung_task_detector() Julian Sun
2025-09-25 13:33 ` Masami Hiramatsu [this message]
2025-09-24 3:41 ` [PATCH v2 2/2] memcg: Don't trigger hung task warnings when memcg is releasing resources Julian Sun
2025-09-24 6:32 ` Peter Zijlstra
2025-09-24 7:50 ` [External] " Julian Sun
2025-09-24 8:28 ` Peter Zijlstra
2025-09-24 10:36 ` Julian Sun
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=20250925223310.66e769299f7d07491578151d@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=hannes@cmpxchg.org \
--cc=lance.yang@linux.dev \
--cc=lihuafei1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@kernel.org \
--cc=mingo@kernel.org \
--cc=muchun.song@linux.dev \
--cc=peterz@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=sunjunchao@bytedance.com \
--cc=tj@kernel.org \
--cc=will@kernel.org \
--cc=yangyicong@hisilicon.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 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®