From nobody Thu Oct 2 02:15:15 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8DC12367D2 for ; Wed, 24 Sep 2025 03:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758685271; cv=none; b=QjnojFy1yKEU596C4WGEWAxGGccyd4ZFQHoKi5luCNH8PCv3vAAet8hKAleVN9eG5VxXxRqpuYxKRW0DXZChsCLL/kCNpJCkPMB3G9clIPtADeKkSSHi9PfRXsylbhX55K+KO5CtD/RtwZ232aDxWhF5tGov7gcPCfD963PHJqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758685271; c=relaxed/simple; bh=spqI6rzBALnpSMNsrDVeCcve/oeu3eO31tW3HIY0PFY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VCpP8/5502YTfIz8HjSo/dQ//Efsj6l3YiICrSO4cRkXFv+bVvdY02TiCm8i8Bwy8xim5wO8a+l0Axg0K9rGPS/6dSXoRoldSjJ8uyP7KN7/ArPO39vml+JUv1fshWNCaPDaWDBZBDzpad0SSysFNxyMDxea5J+FzK+ELN8xGOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=MHtIr+he; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="MHtIr+he" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-267facf9b58so46320555ad.2 for ; Tue, 23 Sep 2025 20:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1758685269; x=1759290069; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CHQ+DdEo33vc4KCDGuMUNzkfwefcdJo6mPASmdDLS5Q=; b=MHtIr+he5Duynx5X1HvjwOokS1IiiunLkGznIbqK3hfMULQsThQDbFodYmm0osKe05 kyN0+UHk/6t6a5g8udpExpraPYl3wSQ+jXLGvv/7njZfTgp7u6jVPpeVdHhJjicsAuam pOM0BafW8Lntvo/ZuX7EOKOLQiC7B6BMFpmoCtauaEOeuvfb41csG0211e6gRWh2QRKn 1B8lxpLYqqkVonRPXRnrr6L1o0T/NollK3YBGgeS4kcKvB47bV+6/Xe2RefAx5JlYg5M +dRXd727aSPhSqADHSA8a6D8lGfbep/dOoGCk3lAC7Vu7beNnbDZr7hNtsXydgnY/ljh 6yfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758685269; x=1759290069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CHQ+DdEo33vc4KCDGuMUNzkfwefcdJo6mPASmdDLS5Q=; b=E9J6XD5DIQRxT3pM1OPDMUWJmOs/Ge/1ijpH3grXb9h6CaVWXr2A0b/lS0i0R3ufyU MJDR05uUW/nuPMIhbPASCOFq7bolc+/cjFNWzlGuAGVe7B4KGEnK1QTAmd74gfaKJNnP 4mQHwvWaPHWHuVs07tosZSV7WCvyGVZ3y341ZfBd96hj3DS/xtgCVaPoPuIGTA094CkX PM/3YY3X5NwEvkGqoFtMqYuRaUD7Sk7v+rBtYeBosHkFOmt6dO3d1ejGBUSwaDQqDp7/ b9ysjzcL0Rp9J6nAlViBg0g0tVU+NthdMVtLilDxyyvofcIdgzfKcon8pMSUG/q/ghC8 yq5g== X-Forwarded-Encrypted: i=1; AJvYcCVKmxoTnHnfjhIA9HlIMiSwYqYllpUlX1WmnQZ9sbAnjddP9LHru3Paom0RpvOzVKwvfHwuirNpYlPqF44=@vger.kernel.org X-Gm-Message-State: AOJu0YxGoJZse7xoU85QvSV75KlP2ubqZQ4aynyH1qxoJZ0D8SUR78pu LK7JomxmAB3f4LIrIK5dTJcBwXaYtbBs505mQTTWDSRVcifPhutGC18p9R32S37EdO4= X-Gm-Gg: ASbGncvVGH5BUCFAB9yX/O6+pPslsvqAl4N0MoQZ7lVoADCzf7vuTaQdor2m85IzSTG V5V2ofWVNH6DfrONghtbnr4mhNPTl5USNNiD/Iyw4eAZ6phPuD4mG8OLz7V86sy21sexmv5U7Qn h1Mlp7qeOsesfwBQpmskgassCHw0UUn9VGNBvv+xQgv57UVVJBPOvYFtUmY3vJMLN+vErISGTJz rCVCLpI4kJdvnBogGP6h3JfHe3MyXOer7uqv3DJGU9FINvwqRDSLfcywk6vbAoTFYnTLnp95HuL ii+A53Thwsb7CkzbETbZAdpz1JIfOxszhlg4wqq/+54UOJS1b7eSDG7gwT3r6WiQ7/FZ9ZPXh03 ytnV3H6NNYE91YSoGU+ujnEFEo1PdqVY7 X-Google-Smtp-Source: AGHT+IE01vH1dOq4gN0RxZiU2IARw6GpSu64vihveNRXf2jRo5uHOkH57XR3v8v0OkH3XlAZ1ejViQ== X-Received: by 2002:a17:902:e84f:b0:26a:589b:cf11 with SMTP id d9443c01a7336-27cc678387amr68942965ad.43.1758685269114; Tue, 23 Sep 2025 20:41:09 -0700 (PDT) Received: from localhost ([106.38.226.14]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-269802df76dsm172166575ad.74.2025.09.23.20.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Sep 2025 20:41:08 -0700 (PDT) From: Julian Sun To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Cc: 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: [PATCH v2 1/2] hung_task: Introduce touch_hung_task_detector(). Date: Wed, 24 Sep 2025 11:40:59 +0800 Message-Id: <20250924034100.3701520-2-sunjunchao@bytedance.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250924034100.3701520-1-sunjunchao@bytedance.com> References: <20250924034100.3701520-1-sunjunchao@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Suggested-by: Andrew Morton Suggested-by: Lance Yang Reviewed-by: Masami Hiramatsu (Google) --- 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) = { } =20 #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 =20 /* 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_stru= ct *task) } #endif =20 +void touch_hung_task_detector(struct task_struct *t) +{ + t->last_switch_count =3D ULONG_MAX; +} + static void check_hung_task(struct task_struct *t, unsigned long timeout) { unsigned long switch_count =3D t->nvcsw + t->nivcsw; @@ -203,6 +208,10 @@ static void check_hung_task(struct task_struct *t, uns= igned long timeout) if (unlikely(!switch_count)) return; =20 + /* The task doesn't want to trigger the hung task warning. */ + if (unlikely(t->last_switch_count =3D=3D ULONG_MAX)) + return; + if (switch_count !=3D t->last_switch_count) { t->last_switch_count =3D switch_count; t->last_switch_time =3D 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 =3D=3D ULONG_MAX)) { + t->last_switch_count =3D t->nvcsw + t->nivcsw; + t->last_switch_time =3D jiffies; + } } unlock: rcu_read_unlock(); --=20 2.39.5 From nobody Thu Oct 2 02:15:15 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9512A21C9F4 for ; Wed, 24 Sep 2025 03:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758685344; cv=none; b=EtxXlevpS8glJHbeM7sTq/gpGJhswBnT/F4bU4tY5DBXxNYEoYBcTFmm21KgDUCXnTl/FK+Y55QmUJKFmuEBwXVGdPQdS7bvfR5e0ZfkR1xEER45nHI2A6oKPIF2bPXazAhd9HzBAjtg3Tj4QcCuESwLomcxaWtxS45D0Y3gp9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758685344; c=relaxed/simple; bh=JfIAWDuN1kKed0FYgT3jkRN7qq4iKlUIG9GpMZNLTHA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Xvn9lpg0Vr+X25Ulc5q8JD02S9fsK/f0Q9wY3F3wr6HipWXjdBQvXebBaOmEchI9pLUNqUoOJNIkE5NLLaHo1Wm1haiwAFcFsQMmAHZMPsH3+VcMZ5MjlzmPFF9SwP4S/U4kQmk9sOlhjrUtTr5cJHCm9NUMqxswtlFwvxLRhmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=SBXGZ2/z; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="SBXGZ2/z" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-25669596955so56564175ad.0 for ; Tue, 23 Sep 2025 20:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1758685342; x=1759290142; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EsJTV5DUFz04JQKhysbzOjs1PoDN4ekmuz2g31Q2mg8=; b=SBXGZ2/z/hWy7nePgRqH8oxZEzeaEJs9yMavjspCzkBvWRyR9xlObEeOz4k+Cje6Ok W3k8l/oWd8mvxJThE6O7vUR9pY1CKONA2L3J7KRiQ0IWZUiTDpwrfiiJBKttHZ0MAJ9f RbRuq3zG8/Lwlot5q+qZIueQsWDJRnHzeQ1K7KeJGCE/TgKDV/UDm3n5lM/k/leUaz6t GKqewGmKapr7WeqT3C4oA+MINB/DMV5Xuqg5sss7Z/vTyMPxxbPJjPjUPJOR5kvGbIo8 ZK0fUuqHhYFQ5timiDiS91iJVs6l4SeaMRnxIi43+snVC8dbKGvanPDBxXJZWM1OSdaG g0XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758685342; x=1759290142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EsJTV5DUFz04JQKhysbzOjs1PoDN4ekmuz2g31Q2mg8=; b=cqYfe53FuOwGmrtYSDAZz6dQry46LbVm7SVoUmVJHS2JwdS8h3zo7QMZ8IZD4l14Fs rNsVSJNyV30mNKHljvw20cYmpbQ43EC7A+e5dfxR8Gra5caJlEM7TdPVqV/amXHdZ48Z S7nFVlHHpvaiWHuiEJ5qZb2qErBBSOLrb/Yr745a8RF/y/TE979tGYSAfXUg4U40xUle kLY8r59XdhASVyUnJp2gq5AwepmGHC+RPGr14/VoFonIHowKmsdfdjU3zEcgW0fQzQSF ofYr/PhMhxpQs61DlfDdP3jNS81kut/FAweL+d5f6f7vSctYBNPspMdTDxVQtcjWIP6/ Q2wA== X-Forwarded-Encrypted: i=1; AJvYcCX9G+mVEzVGMuTspwarUKs10WoCSl+hJXucyzu5gloXnaPtil6ThpJlM6eyMaG+W7tDEXBmLbG/joMD1Es=@vger.kernel.org X-Gm-Message-State: AOJu0YwYbw3GIDdLIUAbQEENxVkqLtPRh5nS5ojyMn754am9iLpgpFQB xLnXRT7X6CMO4mxqhN+bh03QTwTES0JtyBO4QGGyrZ152rxbCfGCVpOvYk3ABGWsRdE= X-Gm-Gg: ASbGncu1I3c2Jab8xpYMcWQr1dRX3+kzGaFIjdfwSYZnW6zkLA1kmACxnhL4K4Y/3Kr 9Yc+oXYVb+NY0Zgpgzhp8J+dW7nX2VfQ7smvXoey6QGuz8kh15B0fsH8YTCZBZRY6tZTh9Gwh6t 112KmFDmZd1Pzh0I7cTd3l9zmb8gUKQsp74eI2O5emp0Ojpeoy+3MWtixph3RKW6GOhOCnaLLfu lZarmCT5FdQD/qNr8OMu54FQdEcjCFvTKwYhifY+v2Sau3QJgWNUGmZNblA/cdJCGjQDn69rpRI vcVpK3sDpbTzH5y94GwTVaSuQ5Wu0zCZG+Y5zeMBuvrSrzyS0SXKIOMTZz2EsKFn6PzU0CWcJR3 YIJJOIkvyUH8K69OXR86WH/aBeNrKLanYag== X-Google-Smtp-Source: AGHT+IGrcT5Ka2xMEBu3sbqKbDUXPNl6amxvjYaBM1CXrmwchGIMFPPAdgNK41sSgXmtBkVzwz8xzA== X-Received: by 2002:a17:903:8c6:b0:269:82a5:fa19 with SMTP id d9443c01a7336-27cc61bed26mr61207375ad.45.1758685341761; Tue, 23 Sep 2025 20:42:21 -0700 (PDT) Received: from localhost ([106.38.226.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2752328629fsm88067475ad.106.2025.09.23.20.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Sep 2025 20:42:21 -0700 (PDT) From: Julian Sun To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Cc: 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: [PATCH v2 2/2] memcg: Don't trigger hung task warnings when memcg is releasing resources. Date: Wed, 24 Sep 2025 11:41:00 +0800 Message-Id: <20250924034100.3701520-3-sunjunchao@bytedance.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250924034100.3701520-1-sunjunchao@bytedance.com> References: <20250924034100.3701520-1-sunjunchao@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hung task warning in mem_cgroup_css_free() is undesirable and unnecessary since the behavior of waiting for a long time is expected. Use touch_hung_task_detector() to eliminate the possible hung task warning. Signed-off-by: Julian Sun --- I didn=E2=80=99t add a fixes tag because there is no actual bug in the original code, and this patch is more of an improvement-type one. mm/memcontrol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 8dd7fbed5a94..fc73a56372a4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -63,6 +63,7 @@ #include #include #include +#include #include "internal.h" #include #include @@ -3912,8 +3913,15 @@ static void mem_cgroup_css_free(struct cgroup_subsys= _state *css) int __maybe_unused i; =20 #ifdef CONFIG_CGROUP_WRITEBACK - for (i =3D 0; i < MEMCG_CGWB_FRN_CNT; i++) + for (i =3D 0; i < MEMCG_CGWB_FRN_CNT; i++) { + /* + * We don't want the hung task detector to report warnings + * here since there's nothing wrong if the writeback work + * lasts for a long time. + */ + touch_hung_task_detector(current); wb_wait_for_completion(&memcg->cgwb_frn[i].done); + } #endif if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket) static_branch_dec(&memcg_sockets_enabled_key); --=20 2.39.5