mm/list_lru: don't copy stale shrinker id from non-memcg-aware shrinkers
Subsystems (2)
PATCH 1/1 mm/list_lru: don't copy stale shrinker id from non-memcg-aware shrinkers
With cgroup.memory=nokmem, shrinker_memcg_alloc() fails with -ENOSYS for shrinkers without SHRINKER_NONSLAB, and shrinker_alloc() falls back to a non-memcg-aware shrinker. On this fallback path, shrinker->id is never assigned and keeps 0 from kzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init() copies shrinker->id unconditionally, so every list_lru backed by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up with lru->shrinker_id == 0 instead of -1.
Under nokmem the list_lru collapses to the shared per-node lists, but __list_lru_add() still calls set_shrinker_bit() against the memcg of the added object. Most list_lru users are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem, shrinker_nr_max stays 0 and every memcg's shrinker_info has map_nr_max == 0, so the first folio added by khugepaged triggers on every boot:
WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0
On systems where a SHRINKER_NONSLAB shrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.
shrinker->id is only meaningful while SHRINKER_MEMCG_AWARE is set, and all readers inside mm/shrinker.c already check the flag before using the id. Make __list_lru_init() do the same and fall back to -1, so set_shrinker_bit() is never reached with a bogus id. The stale shrinker->id itself is left as is; cleaning that up is a separate topic.
---
Verified on a machine booting with cgroup.memory=nokmem and CONFIG_TRANSPARENT_HUGEPAGE=y: the warning fires once per boot from khugepaged, disappears when nokmem is removed from the command line, and no longer triggers with this fix applied and nokmem set.
mm/list_lru.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/list_lru.c +6 -1
@@ -666,7 +666,12 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware, struct shrinker *shrint i;#ifdef CONFIG_MEMCG -if (shrinker) +/* +* If the shrinker fell back to being non-memcg-aware (e.g. with +* cgroup.memory=nokmem), its id was never assigned and holds a +* stale 0. Don't let set_shrinker_bit() act on it. +*/ +if (shrinker && (shrinker->flags &SHRINKER_MEMCG_AWARE )) lru->shrinker_id = shrinker->id;else lru->shrinker_id =-1 ;
Signature · 1 line
2.43.7
Andrew Morton
maintainerQuoted 27 lines · On Tue, 1 Sep 2026 19:51:04 +0800 Qinyun Tan <[email protected]>…
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.
Quoted 6 lines
shrinker->idis only meaningful whileSHRINKER_MEMCG_AWAREis set, and all readers insidemm/shrinker.calready check the flag before using the id. Make__list_lru_init()do the same and fall back to -1, soset_shrinker_bit()is never reached with a bogus id. The staleshrinker->iditself is left as is; cleaning that up is a separate topic.
Thanks. I'll queue this for test and review.
Quoted 1 line
Fixes 03375203e1da8 ("mm: do not allocate shrinker info with cgroup.memory=nokmem")
Worth a cc:stable, I assume.
Quoted 6 lines
---
Verified on a machine booting with cgroup.memory=nokmem and
CONFIG_TRANSPARENT_HUGEPAGE=y: the warning fires once per boot from khugepaged, disappears when nokmem is removed from the command line, and no longer triggers with this fix applied and nokmem set.
That's useful info. I'll move it into the changelog.
Sashiko thinks there's a problem with cgroup_disable=memory as well:
https://sashiko.dev/#/patchset/[email protected]
Hi,
Quoted 49 lines · Andrew Morton
Quoted 27 lines · On Tue, 1 Sep 2026 19:51:04 +0800 Qinyun Tan <[email protected]>…
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.Quoted 6 lines
shrinker->idis only meaningful whileSHRINKER_MEMCG_AWAREis set, and all readers insidemm/shrinker.calready check the flag before using the id. Make__list_lru_init()do the same and fall back to -1, soset_shrinker_bit()is never reached with a bogus id. The staleshrinker->iditself is left as is; cleaning that up is a separate topic.Thanks. I'll queue this for test and review.
Quoted 1 line
Fixes 03375203e1da8 ("mm: do not allocate shrinker info with cgroup.memory=nokmem")Worth a cc:stable, I assume.
Quoted 6 lines
---
Verified on a machine booting with cgroup.memory=nokmem and
CONFIG_TRANSPARENT_HUGEPAGE=y: the warning fires once per boot from khugepaged, disappears when nokmem is removed from the command line, and no longer triggers with this fix applied and nokmem set.
Quoted 5 lines
That's useful info. I'll move it into the changelog.
Sashiko thinks there's a problem with cgroup_disable=memory as well:
https://sashiko.dev/#/patchset/[email protected]
Yes, the observation is valid, and it turned out to be a real crash on mm-new, not just a semantic inconsistency.
__list_lru_init() only checks mem_cgroup_kmem_disabled(), which covers cgroup.memory=nokmem but not cgroup_disable=memory. With the controller disabled entirely, the lru stays memcg aware while folio_memcg() is always NULL.
On mainline this is unreachable: the only caller of folio_memcg_list_lru_alloc(), folio_memcg_alloc_deferred(), bails out on mem_cgroup_disabled() first. But the shmem unused-huge shrinker conversion in mm-new ("mm: shmem: make unused huge shrinker memcg aware") calls folio_memcg_list_lru_alloc() without such a guard, so booting with cgroup_disable=memory and writing to a huge=always tmpfs oopses immediately:
BUG: unable to handle page fault for address: 0000000000000488 RIP: 0010:folio_memcg_list_lru_alloc+0x41/0xf0 Call Trace: shmem_get_folio_gfp+0x1cd/0x7c0 shmem_write_begin+0x5d/0x100 generic_perform_write+0x89/0x2a0 shmem_file_write_iter+0x82/0x90 vfs_write+0x256/0x410 ksys_write+0x61/0xe0
The faulting address is the offset of mem_cgroup->kmemcg_id, dereferenced on the NULL memcg in memcg_list_lru_allocated().
I've verified that checking mem_cgroup_disabled() in __list_lru_init() fixes this: with the lru collapsed to plain per-node lists, folio_memcg_list_lru_alloc() returns early, the inode is queued on the per-node list with a NULL objcg (which the shmem code and obj_cgroup_memcg() handle fine), and the shrinker still reclaims via the global scan. Same reproducer runs cleanly.
I'll send the fix as a follow-up patch shortly. Since the triggering commit is only in mm-new, no stable backport is needed; it may make sense to keep it ahead of (or folded near) the shmem series.
Thanks,
Qinyun Tan
Quoted 38 lines · Qinyun Tan
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.
shrinker->idis only meaningful whileSHRINKER_MEMCG_AWAREis set, and all readers insidemm/shrinker.calready check the flag before using the id. Make__list_lru_init()do the same and fall back to -1, soset_shrinker_bit()is never reached with a bogus id. The staleshrinker->iditself is left as is; cleaning that up is a separate topic.
Quoted 2 lines
Fixes 03375203e1da8 ("mm: do not allocate shrinker info with cgroup.memory=nokmem")Signed-off-by Qinyun Tan <[email protected]>
Thanks.
Quoted 34 lines · Qinyun Tan
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.
shrinker->idis only meaningful whileSHRINKER_MEMCG_AWAREis set, and all readers insidemm/shrinker.calready check the flag before using the id. Make__list_lru_init()do the same and fall back to -1, soset_shrinker_bit()is never reached with a bogus id. The staleshrinker->iditself is left as is; cleaning that up is a separate topic.
Quoted 3 lines
Fixes 03375203e1da8 ("mm: do not allocate shrinker info with cgroup.memory=nokmem")Signed-off-by Qinyun Tan <[email protected]>---
LGTM.
Hello Qinyun.
Quoted 10 lines · Qinyun Tan
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.
<del>thp-deferred_split shrinek has SHRINKER_NONSLAB so, the id should be assigned (at least I see it in thp_shrinker_init()).</del> I was looking at 6.12 kernel.
Quoted 6 lines
Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,
Not sure I understand here, the SHRINKER_NONSLAB are excluded and should still register for per-memcg info.
Quoted 9 lines
shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.
Could it be that you see this issue because of a shrinker which isn't marked as SHRINKER_NONSLAB?
I'd even go as far as pointing atfafaeceb89a5e ("mm: switch deferred split shrinker to list_lru") which removed the flag from the the thp-deferred_split shrinker.
IOW, the proper fix should be addition of SHRINKER_NONSLAB so that per-memcg maps are properly allocated.
Thanks,
Michal
Hi Michal,
Quoted 25 lines · Michal Koutný
Hello Qinyun.
Quoted 10 lines · Qinyun Tan
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.<del>thp-deferred_split shrinek has
SHRINKER_NONSLABso, the id should be assigned (at least I see it in thp_shrinker_init()).</del> I was looking at 6.12 kernel.Quoted 6 lines
Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,
Quoted 3 lines
Not sure I understand here, the
SHRINKER_NONSLABare excluded and should still register for per-memcg info.
You're right, that sentence is imprecise - SHRINKER_NONSLAB shrinkers do register per-memcg under nokmem. What I meant is that on a system where no NONSLAB shrinker happens to register, shrinker_nr_max stays 0.
Quoted 17 lines
Quoted 9 lines
shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.Could it be that you see this issue because of a shrinker which isn't marked as
SHRINKER_NONSLAB?I'd even go as far as pointing at
fafaeceb89a5e("mm: switch deferred split shrinker tolist_lru") which removed the flag from the the thp-deferred_split shrinker.
Quoted 5 lines
IOW, the proper fix should be addition of
SHRINKER_NONSLABso that per-memcg maps are properly allocated.Thanks,
Michal
Yes, good catch. The flag was originally introduced for this very shrinker by 0a432dcbeb32 ("mm: shrinker: make shrinker not depend on memcg kmem"), and your 03375203e1da8 changelog even cites deferred_split_shrinker as the NONSLAB example that still needs per-memcg data. fafaeceb89a5e dropped the flag without mentioning it in the changelog, so this looks like an unintended loss.
That said, I see the flag restoration and this patch as complementary rather than either-or: other MEMCG_AWARE-but-not-NONSLAB shrinkers (superblock, workingset shadow nodes) still take the fallback path under nokmem by design, and __list_lru_init() copying an unassigned id there is a landmine independent of the deferred split case. So I think this patch is still wanted as the generic fix, with the flag restoration on top for THP.
(zswap might deserve the same NONSLAB treatment as THP, btw - its entries resolve the memcg from the folio's objcg, which is available regardless of nokmem.)
Would you like me to send a separate patch restoring SHRINKER_NONSLAB in thp_shrinker_init() (Fixes: fafaeceb89a5e)? Happy to do so if that works for you.
Andrew, since the patch is already in mm-new, could you please update this changelog sentence
"Since no memcg-aware shrinker can register under nokmem,"
to
"On a system where no SHRINKER_NONSLAB shrinker registers,"
per Michal's comment above? Or I can send a v2 if you prefer.
Thanks,
Qinyun Tan
Quoted 3 lines · Qinyun Tan
You're right, that sentence is imprecise -
SHRINKER_NONSLABshrinkers do register per-memcg under nokmem. What I meant is that on a system where no NONSLAB shrinker happens to register,shrinker_nr_maxstays 0.
And ideally, with cgroup.memory=nokmem no slab-based code should call set_shrinker_bit() with whatever shrinker_id.
Quoted 2 lines
That said, I see the flag restoration and this patch as complementary rather than either-or:
Yes, it fixes your immediate issue and it is a prudent approach in list_lru_init(). OTOH, with this fixup, we won't be able to learn about shrinkers that are missing SHRINKER_NONSLAB.
Quoted 10 lines
other MEMCG_AWARE-but-not-NONSLAB shrinkers
(superblock, workingset shadow nodes) still take the fallback path under nokmem by design, and__list_lru_init()copying an unassigned id there is a landmine independent of the deferred split case. So I think this patch is still wanted as the generic fix, with the flag restoration on top for THP.(zswap might deserve the same NONSLAB treatment as THP, btw - its entries resolve the memcg from the folio's objcg, which is available regardless of nokmem.)
_That_ is an important point.
So that would need a fix too, and likely Fixes: b5ba474f3f518 ("zswap:
shrink zswap pool based on memory pressure").
(I'd have preferred if there weren't Fixes: 03375203e1da8 which honors the SHRINKER_NONSLAB semantics and it only uncovered pre-existing missing flags. Or keep that Fixes: but explain the relation to the other commits. (To make it clear to backporters.))
Quoted 3 lines
Would you like me to send a separate patch restoring
SHRINKER_NONSLABinthp_shrinker_init()(Fixes:fafaeceb89a5e)? Happy to do so if that works for you.
SHRINKER_MEMCG_AWARE are due to be checked for correct marking with SHRINKER_NONSLAB. I can see that it is missing in: thp-deferred_split, zswap-shrinker in the v7.3-rc1. (The shrinkers in nfs42xattr.c seem to be slab-based so they're correct.)
The shrinkers mentioned in your original commit message: workingset shadow nodes, superblock lrus are both slab-based, so systemd with only those shouldn't be affected by this bug.
Thanks,
Michal
Hi, Michal
Quoted 8 lines · Michal Koutný
Quoted 3 lines · Qinyun Tan
You're right, that sentence is imprecise -
SHRINKER_NONSLABshrinkers do register per-memcg under nokmem. What I meant is that on a system where no NONSLAB shrinker happens to register,shrinker_nr_maxstays 0.And ideally, with cgroup.memory=nokmem no slab-based code should call
set_shrinker_bit()with whatevershrinker_id.
Agreed, and with this patch that holds: slab-based lrus fall back to shrinker_id == -1 and set_shrinker_bit() is never reached.
Quoted 7 lines
Quoted 2 lines
That said, I see the flag restoration and this patch as complementary rather than either-or:
Yes, it fixes your immediate issue and it is a prudent approach in
list_lru_init(). OTOH, with this fixup, we won't be able to learn about shrinkers that are missingSHRINKER_NONSLAB.
True. Though the old behavior wasn't a reliable canary either: the warning only fired while shrinker_nr_max was still 0. Once any SHRINKER_NONSLAB shrinker had expanded the maps, a missing flag showed up as a silently mis-set bit 0 rather than a warning. With your audit below covering the current tree, I think losing that accidental signal is an acceptable trade-off.
Quoted 8 lines
Quoted 8 lines
other MEMCG_AWARE-but-not-NONSLAB shrinkers
(superblock, workingset shadow nodes) still take the fallback path under nokmem by design, and__list_lru_init()copying an unassigned id there is a landmine independent of the deferred split case. So I think this patch is still wanted as the generic fix, with the flag restoration on top for THP.
Quoted 8 lines
Quoted 3 lines
(zswap might deserve the same NONSLAB treatment as THP, btw - its entries resolve the memcg from the folio's objcg, which is available regardless of nokmem.)
_That_ is an important point.
So that would need a fix too, and likely Fixes:b5ba474f3f518("zswap:
shrink zswap pool based on memory pressure").
Will do.
Quoted 5 lines
(I'd have preferred if there weren't Fixes:
03375203e1da8which honors theSHRINKER_NONSLABsemantics and it only uncovered pre-existing missing flags. Or keep that Fixes: but explain the relation to the other commits. (To make it clear to backporters.))
Fair point. I'd propose retargeting the tag to
as that is the commit that made the problem user-visible: it put a list_lru holding charged user folios behind a fallback shrinker, and the boot-time warning is reproducible from v7.2 on. Does that work for you?
Andrew, thanks for the sentence fixup yesterday. If Michal agrees, could you please also retarget the Fixes: tag:
-Fixes: 03375203e1da8 ("mm: do not allocate shrinker info with cgroup.memory=nokmem") +Fixes: fafaeceb89a5e ("mm: switch deferred split shrinker to list_lru")
Quoted 9 lines
Quoted 3 lines
Would you like me to send a separate patch restoring
SHRINKER_NONSLABinthp_shrinker_init()(Fixes:fafaeceb89a5e)? Happy to do so if that works for you.
SHRINKER_MEMCG_AWAREare due to be checked for correct marking withSHRINKER_NONSLAB. I can see that it is missing in: thp-deferred_split, zswap-shrinker in the v7.3-rc1. (The shrinkers innfs42xattr.cseem to be slab-based so they're correct.)
Thanks for auditing the whole tree. I'll send a two-patch series restoring/adding SHRINKER_NONSLAB for thp-deferred_split (Fixes: fafaeceb89a5e) and zswap-shrinker (Fixes: b5ba474f3f518).
Quoted 4 lines
The shrinkers mentioned in your original commit message: workingset shadow nodes, superblock lrus are both slab-based, so systemd with only those shouldn't be affected by this bug.
Right - they were listed only as lrus that end up carrying the bogus id 0, not as triggers; as the changelog notes, their objects resolve to a NULL memcg under nokmem so set_shrinker_bit() is never called for them. The only actual trigger is thp-deferred_split.
Quoted 2 lines
Thanks,
Michal
Thanks,
Qinyun Tan
Andrew Morton
maintainerQuoted 5 lines · On Fri, 4 Sep 2026 10:10:20 +0800 Qinyun Tan <[email protected]>…
Andrew, thanks for the sentence fixup yesterday. If Michal agrees, could you please also retarget the Fixes: tag:
-Fixes:
03375203e1da8("mm: do not allocate shrinker info with cgroup.memory=nokmem") +Fixes:fafaeceb89a5e("mm: switch deferred split shrinker tolist_lru")
Done.
Andrew Morton
maintainerQuoted 8 lines · On Thu, 3 Sep 2026 12:06:53 +0800 Qinyun Tan <[email protected]>…
Andrew, since the patch is already in mm-new, could you please update this changelog sentence
"Since no memcg-aware shrinker can register under nokmem,"
to
"On a system where noSHRINKER_NONSLABshrinker registers,"per Michal's comment above?
Done.
Such changes can also be made while a patch is in the mm-unstable branch, btw.
Quoted 36 lines · Qinyun Tan
With cgroup.memory=nokmem,
shrinker_memcg_alloc()fails with-ENOSYSfor shrinkers withoutSHRINKER_NONSLAB, andshrinker_alloc()falls back to a non-memcg-aware shrinker. On this fallback path,shrinker->idis never assigned and keeps 0 fromkzalloc(), which is a valid id belonging to whichever memcg-aware shrinker registers first.
__list_lru_init()copiesshrinker->idunconditionally, so everylist_lrubacked by such a fallback shrinker (thp-deferred_split, zswap-shrinker, workingset shadow nodes, superblock lrus, ...) ends up withlru->shrinker_id== 0 instead of -1.Under nokmem the
list_lrucollapses to the shared per-node lists, but__list_lru_add()still callsset_shrinker_bit()against the memcg of the added object. Mostlist_lruusers are unaffected because their objects resolve to a NULL memcg without kmem accounting, but the THP deferred split queue holds user folios, which are charged regardless of nokmem. Since no memcg-aware shrinker can register under nokmem,shrinker_nr_maxstays 0 and every memcg'sshrinker_infohasmap_nr_max== 0, so the first folio added by khugepaged triggers on every boot:WARNING: mm/shrinker.c:212 at set_shrinker_bit+0x99/0xa0On systems where a
SHRINKER_NONSLABshrinker (btrfs, xfs) did register and expand the maps, there is no warning; instead bit 0 is set spuriously for an unrelated shrinker.
shrinker->idis only meaningful whileSHRINKER_MEMCG_AWAREis set, and all readers insidemm/shrinker.calready check the flag before using the id. Make__list_lru_init()do the same and fall back to -1, soset_shrinker_bit()is never reached with a bogus id. The staleshrinker->iditself is left as is; cleaning that up is a separate topic.
Quoted 2 lines
Fixes 03375203e1da8 ("mm: do not allocate shrinker info with cgroup.memory=nokmem")Signed-off-by Qinyun Tan <[email protected]>
The patch solved my problem in link:
https://lore.kernel.org/linux-mm/[email protected]/
Thanks
Wentao Guan