Re: [PATCH] fs: push nr_cached_objects memcg gating into individual filesystems
From: Qi Zheng
Date: Tue Jul 14 2026 - 06:58:29 EST
On 7/14/26 6:14 PM, Usama Arif wrote:
Commit 0baad6f9b997 ("fs/super: skip non-memcg-aware nr_cached_objects
in memcg slab shrink") added a check in fs/super.c that skips the
->nr_cached_objects() hook whenever the shrinker is invoked for a
non-root memcg, because none of the current implementations (btrfs,
xfs, shmem huge) honour sc->memcg.
That policy is really a filesystem-owned property: fs/super.c should
not encode the assumption that these hooks are never memcg-aware,
since a future implementation might legitimately filter by sc->memcg.
Move the check into btrfs_nr_cached_objects(), xfs_fs_nr_cached_objects()
and shmem_unused_huge_count() so each filesystem can lift the
restriction independently once its underlying counters/scans become
memcg-aware, without needing a coordinated change to fs/super.c.
Behaviour is unchanged: calls into these hooks from shrink_slab_memcg()
still early-return 0 for non-root memcg contexts, keeping the shrinker
bit clearable in each memcg's bitmap; the global (kswapd or root
direct reclaim) path still drives them as before.
Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
---
fs/btrfs/super.c | 11 +++++++++++
fs/super.c | 19 ++-----------------
fs/xfs/xfs_super.c | 12 ++++++++++++
mm/shmem.c | 11 +++++++++++
4 files changed, 36 insertions(+), 17 deletions(-)
Looks reasonable to me. So
Acked-by: Qi Zheng <qi.zheng@xxxxxxxxx>
Thanks!