[PATCH V3 0/4] record non-slab shrinkers for non-root memcgs when kmem is disabled

From: Haifeng Xu

Date: Tue Mar 10 2026 - 23:03:07 EST


When registering new shrinkers, all memcgs need to expand shrinker info
if new allocated id exceeds shrinker_nr_max. But if kmem is disabled,
only non-slab shrinkers is useful in memcg slab shrink. So in this case,
it is enough to allocate non-slab shrinker info for non-root memcg. This
can save a bit of memory and reduce the holding time of shrinker lock.

With this optimization, the finish time of pod creation in our internal
test is reduced from 150 seconds to 69 seconds. We test it based on
stable kernel 6.6.102.

Changes since V2:
- read shrinker_nonslab_nr_max and shrinker_nr_max under after acquring
the shrinker_mutex.

https://lore.kernel.org/all/20260310031250.289851-1-haifeng.xu@xxxxxxxxxx/

Changes since V1:
- reuse shrinker_id() to retrieve the id of shrinker, this also fix the
build error without CONFIG_MEMCG.

https://lore.kernel.org/all/20260306075757.198887-1-haifeng.xu@xxxxxxxxxx/

Haifeng Xu (4):
mm: shrinker: add one more parameter in shrinker_id()
mm: shrinker: move shrinker_id() code block below memcg_kmem_online()
mm: shrinker: optimize the allocation of shrinker_info when setting
cgroup_memory_nokmem
mm: shrinker: remove unnecessary check in shrink_slab_memcg()

include/linux/memcontrol.h | 194 +++++++++++++++++++------------------
include/linux/shrinker.h | 3 +
mm/huge_memory.c | 4 +-
mm/shrinker.c | 134 +++++++++++++++++++++----
4 files changed, 218 insertions(+), 117 deletions(-)

--
2.43.0