[PATCH v2 2/2] memcg: Don't trigger hung task warnings when memcg is releasing resources.

From: Julian Sun

Date: Tue Sep 23 2025 - 23:42:22 EST


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 <sunjunchao@xxxxxxxxxxxxx>
---

I didn’t 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 <linux/seq_buf.h>
#include <linux/sched/isolation.h>
#include <linux/kmemleak.h>
+#include <linux/nmi.h>
#include "internal.h"
#include <net/sock.h>
#include <net/ip.h>
@@ -3912,8 +3913,15 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
int __maybe_unused i;

#ifdef CONFIG_CGROUP_WRITEBACK
- for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++)
+ for (i = 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);
--
2.39.5