Skip to content

Commit 0b98133

Browse files
ahacigu-linuxopsiff
authored andcommitted
mm/shrinker: fix refcount leak in shrink_slab_memcg()
mainline inclusion from mainline-v7.1-rc1 category: bugfix When kmem is disabled for memcg, slab-backed shrinkers are skipped. However, shrink_slab_memcg() doesn't drop the reference acquired via shrinker_try_get() before continuing. Add the missing shrinker_put(). Also, since memcg_kmem_online() and shrinker flags cannot change dynamically, remove the shrinker from the bitmap to avoid unnecessary future scans. Link: https://lkml.kernel.org/r/20260204033553.50039-1-ahacigu.linux@gmail.com Fixes: 50d09da ("mm: shrinker: make memcg slab shrink lockless") Signed-off-by: Altan Hacigumus <ahacigu.linux@gmail.com> Acked-by: Qi Zheng <zhengqi.arch@bytedance.com> Link: https://lore.kernel.org/r/20260203073757.135088-1-ahacigu.linux@gmail.com Reviewed-by: Muchun Song <muchun.song@linux.dev> Cc: Dave Chinner <david@fromorbit.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 260d70819c37cf59383286f8dc6566eaa32776bb) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 97afe56 commit 0b98133

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

mm/shrinker.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,11 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid,
544544

545545
/* Call non-slab shrinkers even though kmem is disabled */
546546
if (!memcg_kmem_online() &&
547-
!(shrinker->flags & SHRINKER_NONSLAB))
547+
!(shrinker->flags & SHRINKER_NONSLAB)) {
548+
clear_bit(offset, unit->map);
549+
shrinker_put(shrinker);
548550
continue;
551+
}
549552

550553
ret = do_shrink_slab(&sc, shrinker, priority);
551554
if (ret == SHRINK_EMPTY) {

0 commit comments

Comments
 (0)