mm: restore SHRINKER_NONSLAB on THP and zswap shrinkers
Subsystems (3)
cover mm: restore SHRINKER_NONSLAB on THP and zswap shrinkers
While reviewing the patch "mm/list_lru: don't copy stale shrinker id from non-memcg-aware shrinkers" (now in mm-unstable), Michal noticed that the two non-slab memcg-aware shrinkers, the THP deferred split shrinker and the zswap shrinker, are registered without SHRINKER_NONSLAB [1].
Without that flag, booting with cgroup.memory=nokmem silently demotes both shrinkers to non-memcg-aware ones: memcg (limit-induced) reclaim neither splits partially unmapped THPs nor writes back zswapped pages of the cgroup under pressure.
Patch 1 restores the flag on the deferred split shrinker; it was lost when commit fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") re-registered the shrinker.
Patch 2 adds the flag to the zswap shrinker, which has never carried it since its introduction in commit b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure").
The series is based on mm-new, on top of the list_lru patch above, but the changes are independent of it.
[1] https://lore.kernel.org/lkml/[email protected]/
Qinyun Tan (2):
mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB
mm/huge_memory.c | 3 ++- mm/zswap.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.7
PATCH 1/2 mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
On a system booted with cgroup.memory=nokmem, the deferred split shrinker is quietly demoted to a non-memcg-aware one. As a result, partially unmapped THPs are only split under global reclaim; memcg (limit-induced) reclaim never splits them, so a cgroup under memory pressure keeps its underused THPs intact.
This is a regression from commit fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru"), which re-registered the shrinker without SHRINKER_NONSLAB. The shrinker had carried this flag since commit 0a432dcbeb32 ("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Without the flag, shrinker_memcg_alloc() fails with -ENOSYS under nokmem and the shrinker loses its memcg awareness.
This was noticed by Michal during review of the patch "mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].
Restore the flag.
[1] https://lore.kernel.org/lkml/[email protected]/
--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/huge_memory.c +2 -1
@@ -1022,7 +1022,8 @@ int folio_memcg_alloc_deferred(struct folio *folio)static int __init thp_shrinker_init (void ) { deferred_split_shrinker =shrinker_alloc (SHRINKER_NUMA_AWARE | -SHRINKER_MEMCG_AWARE , +SHRINKER_MEMCG_AWARE | +SHRINKER_NONSLAB ,"thp-deferred_split" );if (!deferred_split_shrinker)return -ENOMEM ;
Signature · 1 line
2.43.7
Re: [PATCH 1/2] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
Quoted 19 lines · Qinyun Tan
On a system booted with cgroup.memory=nokmem, the deferred split shrinker is quietly demoted to a non-memcg-aware one. As a result, partially unmapped THPs are only split under global reclaim; memcg (limit-induced) reclaim never splits them, so a cgroup under memory pressure keeps its underused THPs intact.
This is a regression from commit
fafaeceb89a5("mm: switch deferred split shrinker tolist_lru"), which re-registered the shrinker withoutSHRINKER_NONSLAB. The shrinker had carried this flag since commit0a432dcbeb32("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Without the flag,shrinker_memcg_alloc()fails with-ENOSYSunder nokmem and the shrinker loses its memcg awareness.This was noticed by Michal during review of the patch "
mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].Restore the flag.
Quoted 9 lines
[1] https://lore.kernel.org/lkml/[email protected]/
Fixes fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru")Suggested-by Michal Koutný <[email protected]>Signed-off-by Qinyun Tan <[email protected]>--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Makes sense.
Signature · 2 lines
Best Regards, Yan, Zi
Re: [PATCH 1/2] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
In reply to Qinyun TanQuoted 17 lines · Qinyun Tan
On a system booted with cgroup.memory=nokmem, the deferred split shrinker is quietly demoted to a non-memcg-aware one. As a result, partially unmapped THPs are only split under global reclaim; memcg (limit-induced) reclaim never splits them, so a cgroup under memory pressure keeps its underused THPs intact.
This is a regression from commit
fafaeceb89a5("mm: switch deferred split shrinker tolist_lru"), which re-registered the shrinker withoutSHRINKER_NONSLAB. The shrinker had carried this flag since commit0a432dcbeb32("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Without the flag,shrinker_memcg_alloc()fails with-ENOSYSunder nokmem and the shrinker loses its memcg awareness.This was noticed by Michal during review of the patch "
mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].
Quoted 8 lines
Restore the flag.
[1] https://lore.kernel.org/lkml/[email protected]/
Fixes fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru")Suggested-by Michal Koutný <[email protected]>Signed-off-by Qinyun Tan <[email protected]>---
LGTM.
Re: [PATCH 1/2] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
In reply to Qinyun TanQuoted 17 lines · Qinyun Tan
On a system booted with cgroup.memory=nokmem, the deferred split shrinker is quietly demoted to a non-memcg-aware one. As a result, partially unmapped THPs are only split under global reclaim; memcg (limit-induced) reclaim never splits them, so a cgroup under memory pressure keeps its underused THPs intact.
This is a regression from commit
fafaeceb89a5("mm: switch deferred split shrinker tolist_lru"), which re-registered the shrinker withoutSHRINKER_NONSLAB. The shrinker had carried this flag since commit0a432dcbeb32("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Without the flag,shrinker_memcg_alloc()fails with-ENOSYSunder nokmem and the shrinker loses its memcg awareness.This was noticed by Michal during review of the patch "
mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].
Quoted 8 lines
Restore the flag.
[1] https://lore.kernel.org/lkml/[email protected]/
Fixes fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru")Suggested-by Michal Koutný <[email protected]>Signed-off-by Qinyun Tan <[email protected]>---
Signature · 3 lines
Cheers, David
Re: [PATCH 1/2] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
In reply to Qinyun TanQuoted 33 lines · Qinyun Tan
On a system booted with cgroup.memory=nokmem, the deferred split shrinker is quietly demoted to a non-memcg-aware one. As a result, partially unmapped THPs are only split under global reclaim; memcg (limit-induced) reclaim never splits them, so a cgroup under memory pressure keeps its underused THPs intact.
This is a regression from commit
fafaeceb89a5("mm: switch deferred split shrinker tolist_lru"), which re-registered the shrinker withoutSHRINKER_NONSLAB. The shrinker had carried this flag since commit0a432dcbeb32("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Without the flag,shrinker_memcg_alloc()fails with-ENOSYSunder nokmem and the shrinker loses its memcg awareness.This was noticed by Michal during review of the patch "
mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].Restore the flag.
[1] https://lore.kernel.org/lkml/[email protected]/
Fixes fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru")Suggested-by Michal Koutný <[email protected]>Signed-off-by Qinyun Tan <[email protected]>--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/huge_memory.c +0
-0
mm/huge_memory.c int folio_memcg_alloc_deferred(struct folio *folio) · line 1029
Quoted 9 lines
mm/huge_memory.c +2
-1@@ -1022,7 +1022,8 @@ int folio_memcg_alloc_deferred(struct folio *folio)static int __init thp_shrinker_init (void ) { deferred_split_shrinker =shrinker_alloc (SHRINKER_NUMA_AWARE | -SHRINKER_MEMCG_AWARE , +SHRINKER_MEMCG_AWARE | +SHRINKER_NONSLAB ,"thp-deferred_split" );if (!deferred_split_shrinker)return -ENOMEM ;
PATCH 2/2 mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB
In reply to Qinyun TanWith kmem accounting disabled (cgroup.memory=nokmem), memcg reclaim never invokes the zswap shrinker: a cgroup under memory pressure does not write back its own zswapped pages to make room; they are only written back by global reclaim or once the global pool limit kicks in.
The zswap shrinker is registered memcg-aware but without SHRINKER_NONSLAB, so under nokmem it is treated as a slab shrinker:
before commit 03375203e1da ("mm: do not allocate shrinker info with cgroup.memory=nokmem") it was skipped by the !memcg_kmem_online() check in shrink_slab_memcg(); since that commit it is demoted to non-memcg-aware at registration. But the zswap shrinker is not a slab
shrinker: it tracks zswap entries and resolves the owning memcg from the folio's objcg, independent of kmem accounting.
This was noticed by Michal during review of the patch "mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].
Mark it SHRINKER_NONSLAB so it keeps its memcg awareness and runs under memcg reclaim with nokmem.
[1] https://lore.kernel.org/lkml/[email protected]/
--- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/zswap.c +2 -2
@@ -1263,8 +1263,8 @@ static struct shrinker *zswap_alloc_shrinker(void) {struct shrinker *shrinker; - shrinker = -shrinker_alloc (SHRINKER_NUMA_AWARE |SHRINKER_MEMCG_AWARE ,"mm-zswap" ); + shrinker =shrinker_alloc (SHRINKER_NUMA_AWARE |SHRINKER_MEMCG_AWARE | +SHRINKER_NONSLAB ,"mm-zswap" );if (!shrinker)return NULL ;
Signature · 1 line
2.43.7
Re: [PATCH 2/2] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB
Quoted 34 lines · Qinyun Tan
With kmem accounting disabled (cgroup.memory=nokmem), memcg reclaim never invokes the zswap shrinker: a cgroup under memory pressure does not write back its own zswapped pages to make room; they are only written back by global reclaim or once the global pool limit kicks in.
The zswap shrinker is registered memcg-aware but without
SHRINKER_NONSLAB, so under nokmem it is treated as a slab shrinker:
before commit03375203e1da("mm: do not allocate shrinker info with cgroup.memory=nokmem") it was skipped by the !memcg_kmem_online() check inshrink_slab_memcg(); since that commit it is demoted to non-memcg-aware at registration. But the zswap shrinker is not a slab
shrinker: it tracks zswap entries and resolves the owning memcg from the folio's objcg, independent of kmem accounting.This was noticed by Michal during review of the patch "
mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].Mark it
SHRINKER_NONSLABso it keeps its memcg awareness and runs under memcg reclaim with nokmem.[1] https://lore.kernel.org/lkml/[email protected]/
Fixes b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure")Suggested-by Michal Koutný <[email protected]>Signed-off-by Qinyun Tan <[email protected]>--- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/zswap.c +0
-0
mm/zswap.c static struct shrinker *zswap_alloc_shrinker(void) · line 1270
Quoted 10 lines
mm/zswap.c +2
-2@@ -1263,8 +1263,8 @@ static struct shrinker *zswap_alloc_shrinker(void) {struct shrinker *shrinker; - shrinker = -shrinker_alloc (SHRINKER_NUMA_AWARE |SHRINKER_MEMCG_AWARE ,"mm-zswap" ); + shrinker =shrinker_alloc (SHRINKER_NUMA_AWARE |SHRINKER_MEMCG_AWARE | +SHRINKER_NONSLAB ,"mm-zswap" );if (!shrinker)return NULL ;
Re: [PATCH 2/2] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB
In reply to Qinyun TanQuoted 18 lines · Qinyun Tan
With kmem accounting disabled (cgroup.memory=nokmem), memcg reclaim never invokes the zswap shrinker: a cgroup under memory pressure does not write back its own zswapped pages to make room; they are only written back by global reclaim or once the global pool limit kicks in.
The zswap shrinker is registered memcg-aware but without
SHRINKER_NONSLAB, so under nokmem it is treated as a slab shrinker:
before commit03375203e1da("mm: do not allocate shrinker info with cgroup.memory=nokmem") it was skipped by the !memcg_kmem_online() check inshrink_slab_memcg(); since that commit it is demoted to non-memcg-aware at registration. But the zswap shrinker is not a slab
shrinker: it tracks zswap entries and resolves the owning memcg from the folio's objcg, independent of kmem accounting.This was noticed by Michal during review of the patch "
mm/list_lru:
don't copy stale shrinker id from non-memcg-aware shrinkers" [1].
Quoted 8 lines
Mark it
SHRINKER_NONSLABso it keeps its memcg awareness and runs under memcg reclaim with nokmem.[1] https://lore.kernel.org/lkml/[email protected]/
Fixes b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure")Suggested-by Michal Koutný <[email protected]>Signed-off-by Qinyun Tan <[email protected]>