From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 58B1B481650 for ; Tue, 25 Aug 2026 13:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666086; cv=none; b=eHR7KxaegOK7GI/Z8RRbyi/79uVMHltuGpZsF7Bo1LX2sMmyeI/bAtH/R6SnRED250N7WZzu83jmAr4UuNdFLrwDiG1IBubWloH258HEGUi1x3fRkb90BrNX0BX6FOBpJ8OtJ7TyJRCHb2VBnF2aXMiyDVRNrncGf+rGrGJJeIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666086; c=relaxed/simple; bh=ELLnZ43cSDHaSLCaE7rpEkMPlJMSIrUdl9sOGKyrjJI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j3ot1dxoHm3BRAb5SMLvaIGK0a5PNRsaF+iMcVoNdk09K6NNjN1AQ2UNs9fJKVz/qqbPjZxjDdY28VgJS7W4aGMPDVGicnV3xf1gTugAEjS/p6ZXNrwQgU7Sl5MFmh70GAaR0hELakXIJYA/cEBdmfCXryBPwu5lW1MkE6xZ83Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nK2FC/DY; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nK2FC/DY" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-69f7fa1c548so11236a12.2 for ; Tue, 25 Aug 2026 06:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787666083; x=1788270883; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=hJUjDtXJ/jwDQ43yJqCCQ+BzF83DPTYawiSXPF0jph4=; b=nK2FC/DYxd5/gXmnT6hlbbsOJ4hTH6ADxQ1H3AtnzLBcmopeWqpfGyjmGaSNzN84qv YpjtJLXpePk8I5xCcJ1uuWG5fHTjhP4TrHSBbQq7dFTMbcjmQJEpLHvS2mh666wwpGQy KWuYb0y98E9pXzxG3PgveHZW9nn2kXxS88X+baRZaWf7J99++x3PgdpKXkcdFmUgs2qe Klr5ysjsDuPgmP/oW4x379WuvEr64q5ktd1PgcmzJRO5aVV1mPK2qZTtJ1YmHylGBI6h /YPvb4dieGVIUCzlHRr5fLjDChWE661UnKV9iwNxBWEagXLW2wcLIxU1MfqMlPjSIS8y yb1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787666083; x=1788270883; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hJUjDtXJ/jwDQ43yJqCCQ+BzF83DPTYawiSXPF0jph4=; b=BlzGARW8VCHLYYumXEQSDUyWGx6KT506e6UQwikUxQ89MXdb0aiCPBO2uN44+H2S9F jlaMertxshE3IRNTrXt3Im1ZO3JQ3MmybryY3MlfbajsLrXHPOJq1yEbNmUhBx1HG8eK ns0VrXAAACuvOaSgXSyrPdcBESgDZDeuaZm5XUAeSFrNd0XOBa547/ZjcbqQSobkx2nJ NaaAoe+Vg8+XtORBO76iSdLgqz6JiQh6ewax1j4xCpEiwZ1iWk3XO9d8hYiz40n0e90s emrkZiKhbm2xTicpVfMik42BeslEqeYoHSq5h9+xil4vYH3aeyOmduT5V1oyiVTHfFFQ 3ONQ== X-Forwarded-Encrypted: i=1; AHgh+RpbQkQfYJGfsvs5PiTo7rFA9K3MdwSOOWmALEbdyGpAhK787FfvmKiqz3byckU2nkDQXjVeQCy6LjbagB4=@vger.kernel.org X-Gm-Message-State: AFuF++lgiixNnuvRWGIQLX3ZEG4A/gnWpWyIzNX8pNtUy1KgENCSi2pf htZVv17Jtr5VQ66hsRi8e7F55tCQ78vq5m1z3TEjOqy2uagW/ZddJI67 X-Gm-Gg: AR+sD13LVSYtH8uHIFnykMctCJEtcQNqPUmP4lXul4hrixSk9Zs4MVRBgRSVt4iYWma djNIIgchWWoOCFkpsoIcRrJBPSTgugShK/zmRlh5u29NRsuwDPZgXD8+4Rt+GGnpSKdFkOmOEZQ alNIKqw2sVltpawwGHXOMpwYkiq2Zzcrnb4t+u+0wUZ1GcRjD83j0hsVodh4LlXTKanqYImqD62 RfnYGA8uqeIycfubJqh3x1dqzeASSvhBK8aIXM1Id8X/sAFoQXHiTJCi5Ht9a6fk29VZ3dfskdu Mtl0bid4oPSEqxecNXlC6Sm66gc8zOAdNP8/dYVdRfTYA06nizxx2gRFBh/CQU6FAnPpVpudmDl 5lZBGPolNHOsQQckOp09gFKh2cnsRi4+HzcziXB4t51xsjcuUirPWlPoqnPxiUmnrsmFtazDCiK VwXfttFgmtlA/CW+/BLDCaGBxuBUMelt7nECOfalK527gwPlPlS7kkZ3nHpXitPIt6gTyazRlKY hFXtLURMkWW7enWqWvJyhwVii2wIhM0M/NpbtJhigtKxiKz7joPtapVFuLEDmOwvTj98R2tPV6S 4fmx0JRhSk4= X-Received: by 2002:a17:906:478d:b0:c20:31d1:a89f with SMTP id a640c23a62f3a-c24921149camr2705228966b.24.1787666083234; Tue, 25 Aug 2026 06:54:43 -0700 (PDT) Received: from nickhuang (2001-b400-e2d1-934f-70e0-d480-12a2-0163.emome-ip6.hinet.net. [2001:b400:e2d1:934f:70e0:d480:12a2:163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c249606b5aasm1843939066b.4.2026.08.25.06.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 06:54:42 -0700 (PDT) Date: Tue, 25 Aug 2026 13:54:33 +0000 From: Nick Huang To: Krzysztof Kozlowski Cc: Shakeel Butt , Andrew Morton , Dave Chinner , Roman Gushchin , Muchun Song , Qi Zheng , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zenghui Yu , Nhat Pham Subject: Re: [PATCH] mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show() Message-ID: References: <20260610232048.62930-1-shakeel.butt@linux.dev> <041af2b5-9136-4027-b35a-72e5044c63ab@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <041af2b5-9136-4027-b35a-72e5044c63ab@kernel.org> On Tue, Aug 25, 2026 at 08:12:09AM +0200, Krzysztof Kozlowski wrote: > On 24/08/2026 15:42, Nick Huang wrote: > > On Wed, Jun 10, 2026 at 04:20:48PM -0700, Shakeel Butt wrote: > >> Reading the debugfs "count" file of a memcg-aware shrinker can sleep > >> inside an RCU read-side critical section: > >> > >> BUG: sleeping function called from invalid context at kernel/cgroup/rstat.c:421 > >> RCU nest depth: 1, expected: 0 > >> css_rstat_flush > >> mem_cgroup_flush_stats > >> zswap_shrinker_count > >> shrinker_debugfs_count_show > >> > >> shrinker_debugfs_count_show() invokes the ->count_objects() callback > >> under rcu_read_lock(). The zswap callback flushes memcg stats via > >> css_rstat_flush(), which may sleep, so it must not run under RCU. > >> > >> The RCU lock is not needed here. mem_cgroup_iter() takes RCU internally > >> and returns a memcg holding a css reference (dropped on the next > >> iteration or by mem_cgroup_iter_break()), so the memcg stays alive > >> without it. The shrinker is kept alive by the open debugfs file: > >> shrinker_free() removes the debugfs entries via > >> debugfs_remove_recursive(), which waits for in-flight readers to drain, > >> before call_rcu(..., shrinker_free_rcu_cb). The sibling "scan" handler > >> already invokes the sleeping ->scan_objects() callback with no RCU > >> section. > >> > >> Drop the rcu_read_lock()/rcu_read_unlock(). > >> > >> Fixes: 5035ebc644ae ("mm: shrinkers: introduce debugfs interface for memory shrinkers") > >> Reported-by: Zenghui Yu > >> Closes: https://lore.kernel.org/all/c052a064-cddb-494f-a0d8-f8a10b4b1c4d@linux.dev/ > >> Suggested-by: Nhat Pham > >> Signed-off-by: Shakeel Butt > >> --- > >> mm/shrinker_debug.c | 4 ---- > >> 1 file changed, 4 deletions(-) > >> > >> diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c > >> index affa64437302..cda4e86428c8 100644 > >> --- a/mm/shrinker_debug.c > >> +++ b/mm/shrinker_debug.c > >> @@ -57,8 +57,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) > >> if (!count_per_node) > >> return -ENOMEM; > >> > >> - rcu_read_lock(); > >> - > >> memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; > >> > >> memcg = mem_cgroup_iter(NULL, NULL, NULL); > >> @@ -88,8 +86,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) > >> } > >> } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); > >> > >> - rcu_read_unlock(); > >> - > >> kfree(count_per_node); > >> return ret; > >> } > >> -- > >> 2.53.0-Meta > >> > > Reviewed-by: Nick Huang > > Sorry, but what exactly did you review here? In the past you were > sending AI slop: > https://lore.kernel.org/all/aeNGbNyPxJssnkbO@lucifer/ > > Not even properly following the process. > https://lore.kernel.org/all/20260724143408.175870-1-sef1548@gmail.com/ > > https://lore.kernel.org/all/?q=f%3Asef1548%40gmail.com > > Why suddenly reviewing MM patches? > > Best regards, > Krzysztof Hi Krzysztof I saw this patch on the mailing list and was interested in the RCU issue, so I looked at the related code. I checked that removing the outer RCU read-side critical section doesn't break the memcg lifetime, since mem_cgroup_iter() returns the memcg with a CSS reference held. I should have explained what I checked instead of just adding a Reviewed-by. Thanks for pointing that out. Regards, Nick Huang