* [PATCH v5 0/4] mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem
@ 2026-11-23 10:53 Qinyun Tan
2026-11-23 10:53 ` [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID Qinyun Tan
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Qinyun Tan @ 2026-11-23 10:53 UTC (permalink / raw)
To: akpm
Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
mkoutny, david, ziy, baolin.wang, usama.arif, david, qi.zheng,
yosry, nphamcs, chengming.zhou, xlpang, ryncsn, gourry, cgroups,
linux-mm, linux-kernel, Qinyun Tan
With cgroup.memory=nokmem, the THP deferred split shrinker and the
zswap shrinker lose their memcg awareness because neither sets
SHRINKER_NONSLAB. When a cgroup hits its memory limit, these shrinkers
do not split its partially unmapped THPs or write back its zswap
entries.
Under nokmem, __list_lru_init() also disables per-memcg lists. Setting
SHRINKER_NONSLAB alone would leave all memcgs sharing one list per node
for each shrinker. Adding the first object to an empty list sets the
shrinker bit for its memcg. A second memcg can add objects without
setting its own bit, so reclaim in that memcg may skip the shrinker.
A scan for the first memcg can then reach objects belonging to both.
Before commit fafaeceb89a5 ("mm: switch deferred split shrinker to
list_lru"), THP had fully per-memcg deferred split queues embedded
in struct mem_cgroup, working independently of kmem accounting.
nokmem only opts out of kernel slab accounting; THPs and zswapped
pages are user memory and remain charged to their cgroups, so
per-memcg reclaim is still what these shrinkers want.
Patch 1 drops kmemcg_id and indexes non-root lists by the memory CSS
ID. The root memcg keeps index zero and uses the per-node list
directly. The lists are reparented when their memcg goes offline,
including under nokmem.
Patch 2 keeps a list_lru memcg aware under nokmem when its backing
shrinker is registered SHRINKER_NONSLAB.
Patch 3 restores SHRINKER_NONSLAB on the THP deferred split shrinker.
Patch 4 sets the same flag on the zswap shrinker.
Slab-backed lrus (e.g. the superblock dentry/inode lrus) still fall
back to per-node lists under nokmem. The per-memcg lists for the two
shrinkers are allocated on demand.
With nokmem enabled, the test_memcontrol and test_zswap kselftests
showed no new failures compared with the unpatched kernel. When one of
two sibling cgroups exceeded memory.high, the patched kernel split THPs
and wrote back zswap entries only in that cgroup.
Changes in v5:
- Rebase on mm-unstable (7d1a16abe4cc) as discussed with Andrew [7].
- Fold v4 patches 1 and 2 [6] into patch 1. Use the memory CSS ID so
that two generations of the memory controller on the same cgroup
have distinct indices while both are alive.
- Keep the memcg argument to the internal walk for the owner check
on restart. Hold RCU from the XArray lookup until the walker takes
a reference to an online CSS.
Changes in v4:
- Fix the boot hang reported by Kairui against v3 [3]: the walker
no longer reverse-resolves the xarray keys; the index is passed
directly through the internal walk path (new patch 1, split out
as a preparation so patch 2 remains a pure key switch).
- Drop the kmemcg_id member from memcg_struct_check() along with
the field removal, as pointed out by Gregory Price [4].
- Otherwise unchanged from v3.
Changes in v3:
- Index the list_lru xarray with mem_cgroup_id() (the cgroup ID)
instead of the private memcg ID, whose lifetime only covers
online groups, and pass memcg pointers through the list_lru
plumbing; inline memcg_online_kmem()/memcg_offline_kmem() into
the css online/offline hooks (patch 1 as numbered in v3, per
Johannes's review of v2 [5]).
- Describe in the THP patch's changelog why the list_lru conversion
dropped SHRINKER_NONSLAB knowingly, per Johannes's pointer to the
original discussion [5].
- Collected review tags: Johannes's Reviewed-by on patches 2-4,
Nhat's and Yosry's Acked-by on patch 4 (numbering as in v3).
Changes in v2:
- Keep the list_lrus behind the two shrinkers per-memcg under
nokmem, so the shrinker bits are set for the right memcgs and
scans stay scoped to the target cgroup's objects (patches 1-2
as numbered in v2, new; addresses Sashiko's review of v1 [2]).
- Patches 3-4 are unchanged from v1 [1] apart from review tags.
[1] https://lore.kernel.org/lkml/20260904033503.4067283-1-qinyuntan@linux.alibaba.com/
[2] https://sashiko.dev/#/patchset/20260904033503.4067283-1-qinyuntan@linux.alibaba.com
[3] https://lore.kernel.org/lkml/20260910080722.3961351-1-qinyuntan@linux.alibaba.com/
[4] https://lore.kernel.org/lkml/arNK64PxTXbVEhis@gourry-fedora-PF4VCD3F/
[5] https://lore.kernel.org/lkml/20260907110111.2286932-1-qinyuntan@linux.alibaba.com/
[6] https://lore.kernel.org/lkml/20261013031221.1997194-1-qinyuntan@linux.alibaba.com/
[7] https://lore.kernel.org/lkml/20261120191122.f31167fc1c987196e5a0b86b@linux-foundation.org/
Qinyun Tan (4):
mm: list_lru: index per-memcg lists by memory CSS ID
mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus
mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker
mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB
include/linux/memcontrol.h | 16 -------------
mm/huge_memory.c | 3 ++-
mm/list_lru.c | 49 +++++++++++++++++++++++++-------------
mm/memcontrol.c | 45 +++++++---------------------------
mm/zswap.c | 4 ++--
5 files changed, 45 insertions(+), 72 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID 2026-11-23 10:53 [PATCH v5 0/4] mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem Qinyun Tan @ 2026-11-23 10:53 ` Qinyun Tan 2026-11-23 12:22 ` Muchun Song 2026-12-05 8:05 ` + mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch added to mm-new branch Andrew Morton 2026-11-23 10:53 ` [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus Qinyun Tan ` (2 subsequent siblings) 3 siblings, 2 replies; 14+ messages in thread From: Qinyun Tan @ 2026-11-23 10:53 UTC (permalink / raw) To: akpm Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, mkoutny, david, ziy, baolin.wang, usama.arif, david, qi.zheng, yosry, nphamcs, chengming.zhou, xlpang, ryncsn, gourry, cgroups, linux-mm, linux-kernel, Qinyun Tan list_lru uses kmemcg_id, a copy of the private memcg ID, to index its per-memcg lists. kmemcg_id is only set when kmem accounting is enabled. Non-slab shrinkers need an index that also works with cgroup.memory=nokmem. Use memcg->css.id for non-root lists. The ID stays allocated until the CSS is freed, so disabling and re-enabling the memory controller on the same cgroup gives the new CSS a distinct index while the old CSS is still referenced. Reserve index zero for the root, which uses the per-node list directly. In list_lru_walk_node(), hold the RCU read lock across both lookups so the CSS ID cannot be reused between them. css_from_id() can see a CSS before its online callback succeeds, so check that the CSS is online before taking a reference. Drop the RCU read lock for the walk and keep the reference across restarts to recheck the same owner. Remove kmemcg_id and reparent the lists before the objcgs on memcg offline, including when kmem accounting is disabled. Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> --- include/linux/memcontrol.h | 16 -------------- mm/list_lru.c | 45 +++++++++++++++++++++++++------------- mm/memcontrol.c | 45 +++++++------------------------------- 3 files changed, 38 insertions(+), 68 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 980358bc6f49..f0001174180c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -335,8 +335,6 @@ struct mem_cgroup { /* Private memcg ID. Used to ID objects that outlive the cgroup */ int private_id; - int kmemcg_id; - /* * Should the OOM killer kill all belonging tasks, had it kill one? */ @@ -1796,15 +1794,6 @@ static inline void memcg_kmem_uncharge_page(struct page *page, int order) __memcg_kmem_uncharge_page(page, order); } -/* - * A helper for accessing memcg's kmem_id, used for getting - * corresponding LRU lists. - */ -static inline int memcg_kmem_id(const struct mem_cgroup *memcg) -{ - return memcg ? memcg->kmemcg_id : -1; -} - struct mem_cgroup *mem_cgroup_from_virt(void *p); static inline void count_objcg_events(struct obj_cgroup *objcg, @@ -1872,11 +1861,6 @@ static inline bool memcg_kmem_online(void) return false; } -static inline int memcg_kmem_id(const struct mem_cgroup *memcg) -{ - return -1; -} - static inline struct mem_cgroup *mem_cgroup_from_virt(void *p) { return NULL; diff --git a/mm/list_lru.c b/mm/list_lru.c index 651983d0bf8b..b4c879d7ba01 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -41,6 +41,15 @@ static inline void unlock_list_lru(struct list_lru_one *l, bool irq_off, static LIST_HEAD(memcg_list_lrus); static DEFINE_MUTEX(list_lrus_mutex); +static inline unsigned long list_lru_memcg_idx(const struct mem_cgroup *memcg) +{ + /* Index 0 selects the per-node root list. */ + if (!memcg || mem_cgroup_is_root(memcg)) + return 0; + + return memcg->css.id; +} + static inline bool list_lru_memcg_aware(struct list_lru *lru) { return lru->memcg_aware; @@ -74,9 +83,9 @@ static int lru_shrinker_id(struct list_lru *lru) static inline struct list_lru_one * list_lru_from_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg) { - int idx = memcg_kmem_id(memcg); + unsigned long idx = list_lru_memcg_idx(memcg); - if (list_lru_memcg_aware(lru) && idx >= 0) { + if (list_lru_memcg_aware(lru) && idx) { struct list_lru_memcg *mlru = xa_load(&lru->xa, idx); /* Lists at a reused index belong to another memcg. */ @@ -425,25 +434,30 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, #ifdef CONFIG_MEMCG if (*nr_to_walk > 0 && list_lru_memcg_aware(lru)) { struct list_lru_memcg *mlru; - struct mem_cgroup *memcg; + struct cgroup_subsys_state *css; unsigned long index; + /* + * Keep the ID from being reused between the two lookups. + * css_from_id() can see a CSS before ->css_online() succeeds. + */ + rcu_read_lock(); xa_for_each(&lru->xa, index, mlru) { - rcu_read_lock(); - memcg = mem_cgroup_from_private_id(index); - if (!memcg || !mem_cgroup_tryget(memcg)) { - rcu_read_unlock(); + css = css_from_id(index, &memory_cgrp_subsys); + if (!css || !css_is_online(css) || !css_tryget(css)) continue; - } rcu_read_unlock(); - isolated += __list_lru_walk_one(lru, nid, memcg, + isolated += __list_lru_walk_one(lru, nid, + mem_cgroup_from_css(css), isolate, cb_arg, nr_to_walk, false); - mem_cgroup_put(memcg); + css_put(css); + rcu_read_lock(); if (*nr_to_walk <= 0) break; } + rcu_read_unlock(); } #endif @@ -526,6 +540,7 @@ static void memcg_reparent_list_lru_one(struct list_lru *lru, int nid, void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent) { + unsigned long idx = list_lru_memcg_idx(memcg); struct list_lru *lru; int i; @@ -538,7 +553,7 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren * allocating a new mlru since CSS_DYING is already set for this * memcg a rcu grace period ago. */ - mlru = xa_load(&lru->xa, memcg->kmemcg_id); + mlru = xa_load(&lru->xa, idx); if (!mlru) continue; @@ -553,7 +568,7 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren for_each_node(i) memcg_reparent_list_lru_one(lru, i, &mlru->node[i], parent); - xa_erase_irq(&lru->xa, memcg->kmemcg_id); + xa_erase_irq(&lru->xa, idx); /* * Here all list_lrus corresponding to the cgroup are guaranteed @@ -568,11 +583,11 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren static inline bool memcg_list_lru_allocated(struct mem_cgroup *memcg, struct list_lru *lru) { + unsigned long idx = list_lru_memcg_idx(memcg); struct list_lru_memcg *mlru; bool allocated; - int idx = memcg->kmemcg_id; - if (idx < 0) + if (!idx) return true; rcu_read_lock(); @@ -616,7 +631,7 @@ static int __memcg_list_lru_alloc(struct mem_cgroup *memcg, } /* Set before the lists are published, and never changed after. */ mlru->memcg = pos; - xas_set(&xas, pos->kmemcg_id); + xas_set(&xas, list_lru_memcg_idx(pos)); do { xas_lock_irqsave(&xas, flags); if (!xas_load(&xas) && !css_is_dying(&pos->css)) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 091401cecf39..f6c8ee7f6fed 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3839,33 +3839,6 @@ void folio_split_memcg_refs(struct folio *folio, unsigned old_order, obj_cgroup_get_many(folio_objcg(folio), new_refs); } -static void memcg_online_kmem(struct mem_cgroup *memcg) -{ - if (mem_cgroup_kmem_disabled()) - return; - - if (unlikely(mem_cgroup_is_root(memcg))) - return; - - static_branch_enable(&memcg_kmem_online_key); - - memcg->kmemcg_id = memcg->private_id; -} - -static void memcg_offline_kmem(struct mem_cgroup *memcg) -{ - struct mem_cgroup *parent; - - if (mem_cgroup_kmem_disabled()) - return; - - if (unlikely(mem_cgroup_is_root(memcg))) - return; - - parent = parent_mem_cgroup(memcg); - memcg_reparent_list_lrus(memcg, parent); -} - #ifdef CONFIG_CGROUP_WRITEBACK #include <trace/events/writeback.h> @@ -4341,7 +4314,6 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent) seqlock_init(&memcg->socket_pressure_seqlock); #endif memcg1_memcg_init(memcg); - memcg->kmemcg_id = -1; #ifdef CONFIG_CGROUP_WRITEBACK INIT_LIST_HEAD(&memcg->cgwb_list); for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++) @@ -4415,7 +4387,8 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) struct obj_cgroup *objcg; int nid; - memcg_online_kmem(memcg); + if (!mem_cgroup_kmem_disabled() && likely(!mem_cgroup_is_root(memcg))) + static_branch_enable(&memcg_kmem_online_key); /* * A memcg must be visible for expand_shrinker_info() @@ -4423,7 +4396,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) * here, when mem_cgroup_iter() can't skip it. */ if (alloc_shrinker_info(memcg)) - goto offline_kmem; + goto reparent_lrus; for_each_node(nid) { objcg = obj_cgroup_alloc(); @@ -4481,8 +4454,8 @@ free_objcg: } } free_shrinker_info(memcg); -offline_kmem: - memcg_offline_kmem(memcg); +reparent_lrus: + memcg_reparent_list_lrus(memcg, parent_mem_cgroup(memcg)); mem_cgroup_private_id_remove(memcg); return -ENOMEM; } @@ -4500,11 +4473,11 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) zswap_memcg_offline_cleanup(memcg); - memcg_offline_kmem(memcg); + memcg_reparent_list_lrus(memcg, parent_mem_cgroup(memcg)); /* * The reparenting of objcg must be after the reparenting of - * the list_lru in memcg_offline_kmem(), which ensures that - * they will not mistakenly get the parent list_lru. + * the list_lru above, which ensures that they will not + * mistakenly get the parent list_lru. */ memcg_reparent_objcgs(memcg); reparent_shrinker_deferred(memcg); @@ -5942,8 +5915,6 @@ static void __init memcg_struct_check(void) private_id_objcg); CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly, private_id); - CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly, - kmemcg_id); CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly, oom_group); -- 2.55.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID 2026-11-23 10:53 ` [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID Qinyun Tan @ 2026-11-23 12:22 ` Muchun Song 2026-12-05 8:05 ` + mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch added to mm-new branch Andrew Morton 1 sibling, 0 replies; 14+ messages in thread From: Muchun Song @ 2026-11-23 12:22 UTC (permalink / raw) To: Qinyun Tan Cc: Muchun Song, akpm, Johannes Weiner, mhocko, Roman Gushchin, Shakeel Butt, mkoutny, David Hildenbrand, ziy, baolin.wang, usama.arif, david, Qi Zheng, yosry, nphamcs, chengming.zhou, xlpang, Kairui Song, gourry, cgroups, linux-mm, linux-kernel > On Nov 23, 2026, at 18:53, Qinyun Tan <qinyuntan@linux.alibaba.com> wrote: > > list_lru uses kmemcg_id, a copy of the private memcg ID, to index its > per-memcg lists. kmemcg_id is only set when kmem accounting is enabled. > Non-slab shrinkers need an index that also works with cgroup.memory=nokmem. > > Use memcg->css.id for non-root lists. The ID stays allocated until the > CSS is freed, so disabling and re-enabling the memory controller on the > same cgroup gives the new CSS a distinct index while the old CSS is > still referenced. Reserve index zero for the root, which uses the > per-node list directly. > > In list_lru_walk_node(), hold the RCU read lock across both lookups so > the CSS ID cannot be reused between them. css_from_id() can see a CSS > before its online callback succeeds, so check that the CSS is online > before taking a reference. Drop the RCU read lock for the walk and > keep the reference across restarts to recheck the same owner. > > Remove kmemcg_id and reparent the lists before the objcgs on memcg > offline, including when kmem accounting is disabled. > > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Nice cleanup. Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Thanks. ^ permalink raw reply [flat|nested] 14+ messages in thread
* + mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch added to mm-new branch 2026-11-23 10:53 ` [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID Qinyun Tan 2026-11-23 12:22 ` Muchun Song @ 2026-12-05 8:05 ` Andrew Morton 1 sibling, 0 replies; 14+ messages in thread From: Andrew Morton @ 2026-12-05 8:05 UTC (permalink / raw) To: mm-commits, ziy, yosry, xlpang, usama.arif, shakeel.butt, ryncsn, roman.gushchin, qi.zheng, nphamcs, muchun.song, mkoutny, mhocko, hannes, gourry, david, david, chengming.zhou, baolin.wang, qinyuntan, akpm [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 14537 bytes --] The patch titled Subject: mm: list_lru: index per-memcg lists by memory CSS ID has been added to the -mm mm-new branch. Its filename is mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Qinyun Tan <qinyuntan@linux.alibaba.com> Subject: mm: list_lru: index per-memcg lists by memory CSS ID Date: Mon, 23 Nov 2026 18:53:31 +0800 Patch series "mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem", v5. With cgroup.memory=nokmem, the THP deferred split shrinker and the zswap shrinker lose their memcg awareness because neither sets SHRINKER_NONSLAB. When a cgroup hits its memory limit, these shrinkers do not split its partially unmapped THPs or write back its zswap entries. Under nokmem, __list_lru_init() also disables per-memcg lists. Setting SHRINKER_NONSLAB alone would leave all memcgs sharing one list per node for each shrinker. Adding the first object to an empty list sets the shrinker bit for its memcg. A second memcg can add objects without setting its own bit, so reclaim in that memcg may skip the shrinker. A scan for the first memcg can then reach objects belonging to both. Before commit fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru"), THP had fully per-memcg deferred split queues embedded in struct mem_cgroup, working independently of kmem accounting. nokmem only opts out of kernel slab accounting; THPs and zswapped pages are user memory and remain charged to their cgroups, so per-memcg reclaim is still what these shrinkers want. Patch 1 drops kmemcg_id and indexes non-root lists by the memory CSS ID. The root memcg keeps index zero and uses the per-node list directly. The lists are reparented when their memcg goes offline, including under nokmem. Patch 2 keeps a list_lru memcg aware under nokmem when its backing shrinker is registered SHRINKER_NONSLAB. Patch 3 restores SHRINKER_NONSLAB on the THP deferred split shrinker. Patch 4 sets the same flag on the zswap shrinker. Slab-backed lrus (e.g. the superblock dentry/inode lrus) still fall back to per-node lists under nokmem. The per-memcg lists for the two shrinkers are allocated on demand. With nokmem enabled, the test_memcontrol and test_zswap kselftests showed no new failures compared with the unpatched kernel. When one of two sibling cgroups exceeded memory.high, the patched kernel split THPs and wrote back zswap entries only in that cgroup. This patch (of 4): list_lru uses kmemcg_id, a copy of the private memcg ID, to index its per-memcg lists. kmemcg_id is only set when kmem accounting is enabled. Non-slab shrinkers need an index that also works with cgroup.memory=nokmem. Use memcg->css.id for non-root lists. The ID stays allocated until the CSS is freed, so disabling and re-enabling the memory controller on the same cgroup gives the new CSS a distinct index while the old CSS is still referenced. Reserve index zero for the root, which uses the per-node list directly. In list_lru_walk_node(), hold the RCU read lock across both lookups so the CSS ID cannot be reused between them. css_from_id() can see a CSS before its online callback succeeds, so check that the CSS is online before taking a reference. Drop the RCU read lock for the walk and keep the reference across restarts to recheck the same owner. Remove kmemcg_id and reparent the lists before the objcgs on memcg offline, including when kmem accounting is disabled. Link: https://lore.kernel.org/20261123105334.2524066-1-qinyuntan@linux.alibaba.com Link: https://patch.msgid.link/20261123105334.2524066-2-qinyuntan@linux.alibaba.com Link: https://lore.kernel.org/lkml/20260904033503.4067283-1-qinyuntan@linux.alibaba.com/ [1] Link: https://sashiko.dev/#/patchset/20260904033503.4067283-1-qinyuntan@linux.alibaba.com [2] Link: https://lore.kernel.org/lkml/20260910080722.3961351-1-qinyuntan@linux.alibaba.com/ [3] Link: https://lore.kernel.org/lkml/arNK64PxTXbVEhis@gourry-fedora-PF4VCD3F/ [4] Link: https://lore.kernel.org/lkml/20260907110111.2286932-1-qinyuntan@linux.alibaba.com/ [5] Link: https://lore.kernel.org/lkml/20261013031221.1997194-1-qinyuntan@linux.alibaba.com/ [6] Link: https://lore.kernel.org/lkml/20261120191122.f31167fc1c987196e5a0b86b@linux-foundation.org/ [7] Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Michal Koutný <mkoutny@suse.com> Cc: David Hildenbrand <david@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Usama Arif <usama.arif@linux.dev> Cc: Dave Chinner <david@fromorbit.com> Cc: Qi Zheng <qi.zheng@linux.dev> Cc: Yosry Ahmed <yosry@kernel.org> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Xunlei Pang <xlpang@linux.alibaba.com> Cc: Kairui Song <ryncsn@gmail.com> Cc: Gregory Price <gourry@gourry.net> include/linux/memcontrol.h | 16 ------------ mm/list_lru.c | 45 +++++++++++++++++++++++------------ mm/memcontrol.c | 45 ++++++----------------------------- 3 files changed, 38 insertions(+), 68 deletions(-) --- a/include/linux/memcontrol.h~mm-list_lru-index-per-memcg-lists-by-memory-css-id +++ a/include/linux/memcontrol.h @@ -337,8 +337,6 @@ struct mem_cgroup { /* Private memcg ID. Used to ID objects that outlive the cgroup */ int private_id; - int kmemcg_id; - /* * Should the OOM killer kill all belonging tasks, had it kill one? */ @@ -1854,15 +1852,6 @@ static inline void memcg_kmem_uncharge_p __memcg_kmem_uncharge_page(page, order); } -/* - * A helper for accessing memcg's kmem_id, used for getting - * corresponding LRU lists. - */ -static inline int memcg_kmem_id(const struct mem_cgroup *memcg) -{ - return memcg ? memcg->kmemcg_id : -1; -} - struct mem_cgroup *mem_cgroup_from_virt(void *p); static inline void count_objcg_events(struct obj_cgroup *objcg, @@ -1925,11 +1914,6 @@ static inline bool memcg_kmem_online(voi return false; } -static inline int memcg_kmem_id(const struct mem_cgroup *memcg) -{ - return -1; -} - static inline struct mem_cgroup *mem_cgroup_from_virt(void *p) { return NULL; --- a/mm/list_lru.c~mm-list_lru-index-per-memcg-lists-by-memory-css-id +++ a/mm/list_lru.c @@ -41,6 +41,15 @@ static inline void unlock_list_lru(struc static LIST_HEAD(memcg_list_lrus); static DEFINE_MUTEX(list_lrus_mutex); +static inline unsigned long list_lru_memcg_idx(const struct mem_cgroup *memcg) +{ + /* Index 0 selects the per-node root list. */ + if (!memcg || mem_cgroup_is_root(memcg)) + return 0; + + return memcg->css.id; +} + static inline bool list_lru_memcg_aware(struct list_lru *lru) { return lru->memcg_aware; @@ -74,9 +83,9 @@ static int lru_shrinker_id(struct list_l static inline struct list_lru_one * list_lru_from_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg) { - int idx = memcg_kmem_id(memcg); + unsigned long idx = list_lru_memcg_idx(memcg); - if (list_lru_memcg_aware(lru) && idx >= 0) { + if (list_lru_memcg_aware(lru) && idx) { struct list_lru_memcg *mlru = xa_load(&lru->xa, idx); /* Lists at a reused index belong to another memcg. */ @@ -425,25 +434,30 @@ unsigned long list_lru_walk_node(struct #ifdef CONFIG_MEMCG if (*nr_to_walk > 0 && list_lru_memcg_aware(lru)) { struct list_lru_memcg *mlru; - struct mem_cgroup *memcg; + struct cgroup_subsys_state *css; unsigned long index; + /* + * Keep the ID from being reused between the two lookups. + * css_from_id() can see a CSS before ->css_online() succeeds. + */ + rcu_read_lock(); xa_for_each(&lru->xa, index, mlru) { - rcu_read_lock(); - memcg = mem_cgroup_from_private_id(index); - if (!memcg || !mem_cgroup_tryget(memcg)) { - rcu_read_unlock(); + css = css_from_id(index, &memory_cgrp_subsys); + if (!css || !css_is_online(css) || !css_tryget(css)) continue; - } rcu_read_unlock(); - isolated += __list_lru_walk_one(lru, nid, memcg, + isolated += __list_lru_walk_one(lru, nid, + mem_cgroup_from_css(css), isolate, cb_arg, nr_to_walk, false); - mem_cgroup_put(memcg); + css_put(css); + rcu_read_lock(); if (*nr_to_walk <= 0) break; } + rcu_read_unlock(); } #endif @@ -526,6 +540,7 @@ static void memcg_reparent_list_lru_one( void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent) { + unsigned long idx = list_lru_memcg_idx(memcg); struct list_lru *lru; int i; @@ -538,7 +553,7 @@ void memcg_reparent_list_lrus(struct mem * allocating a new mlru since CSS_DYING is already set for this * memcg a rcu grace period ago. */ - mlru = xa_load(&lru->xa, memcg->kmemcg_id); + mlru = xa_load(&lru->xa, idx); if (!mlru) continue; @@ -553,7 +568,7 @@ void memcg_reparent_list_lrus(struct mem for_each_node(i) memcg_reparent_list_lru_one(lru, i, &mlru->node[i], parent); - xa_erase_irq(&lru->xa, memcg->kmemcg_id); + xa_erase_irq(&lru->xa, idx); /* * Here all list_lrus corresponding to the cgroup are guaranteed @@ -568,11 +583,11 @@ void memcg_reparent_list_lrus(struct mem static inline bool memcg_list_lru_allocated(struct mem_cgroup *memcg, struct list_lru *lru) { + unsigned long idx = list_lru_memcg_idx(memcg); struct list_lru_memcg *mlru; bool allocated; - int idx = memcg->kmemcg_id; - if (idx < 0) + if (!idx) return true; rcu_read_lock(); @@ -616,7 +631,7 @@ static int __memcg_list_lru_alloc(struct } /* Set before the lists are published, and never changed after. */ mlru->memcg = pos; - xas_set(&xas, pos->kmemcg_id); + xas_set(&xas, list_lru_memcg_idx(pos)); do { xas_lock_irqsave(&xas, flags); if (!xas_load(&xas) && !css_is_dying(&pos->css)) { --- a/mm/memcontrol.c~mm-list_lru-index-per-memcg-lists-by-memory-css-id +++ a/mm/memcontrol.c @@ -3889,33 +3889,6 @@ void folio_split_memcg_refs(struct folio obj_cgroup_get_many(folio_objcg(folio), new_refs); } -static void memcg_online_kmem(struct mem_cgroup *memcg) -{ - if (mem_cgroup_kmem_disabled()) - return; - - if (unlikely(mem_cgroup_is_root(memcg))) - return; - - static_branch_enable(&memcg_kmem_online_key); - - memcg->kmemcg_id = memcg->private_id; -} - -static void memcg_offline_kmem(struct mem_cgroup *memcg) -{ - struct mem_cgroup *parent; - - if (mem_cgroup_kmem_disabled()) - return; - - if (unlikely(mem_cgroup_is_root(memcg))) - return; - - parent = parent_mem_cgroup(memcg); - memcg_reparent_list_lrus(memcg, parent); -} - #ifdef CONFIG_CGROUP_WRITEBACK #include <trace/events/writeback.h> @@ -4395,7 +4368,6 @@ static struct mem_cgroup *mem_cgroup_all seqlock_init(&memcg->socket_pressure_seqlock); #endif memcg1_memcg_init(memcg); - memcg->kmemcg_id = -1; #ifdef CONFIG_CGROUP_WRITEBACK INIT_LIST_HEAD(&memcg->cgwb_list); for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++) @@ -4469,7 +4441,8 @@ static int mem_cgroup_css_online(struct struct obj_cgroup *objcg; int nid; - memcg_online_kmem(memcg); + if (!mem_cgroup_kmem_disabled() && likely(!mem_cgroup_is_root(memcg))) + static_branch_enable(&memcg_kmem_online_key); /* * A memcg must be visible for expand_shrinker_info() @@ -4477,7 +4450,7 @@ static int mem_cgroup_css_online(struct * here, when mem_cgroup_iter() can't skip it. */ if (alloc_shrinker_info(memcg)) - goto offline_kmem; + goto reparent_lrus; for_each_node(nid) { objcg = obj_cgroup_alloc(); @@ -4535,8 +4508,8 @@ free_objcg: } } free_shrinker_info(memcg); -offline_kmem: - memcg_offline_kmem(memcg); +reparent_lrus: + memcg_reparent_list_lrus(memcg, parent_mem_cgroup(memcg)); mem_cgroup_private_id_remove(memcg); return -ENOMEM; } @@ -4554,11 +4527,11 @@ static void mem_cgroup_css_offline(struc zswap_memcg_offline_cleanup(memcg); - memcg_offline_kmem(memcg); + memcg_reparent_list_lrus(memcg, parent_mem_cgroup(memcg)); /* * The reparenting of objcg must be after the reparenting of - * the list_lru in memcg_offline_kmem(), which ensures that - * they will not mistakenly get the parent list_lru. + * the list_lru above, which ensures that they will not + * mistakenly get the parent list_lru. */ memcg_reparent_objcgs(memcg); reparent_shrinker_deferred(memcg); @@ -6006,8 +5979,6 @@ static void __init memcg_struct_check(vo CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly, private_id); CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly, - kmemcg_id); - CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly, oom_group); CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup_per_node, _ Patches currently in -mm which might be from qinyuntan@linux.alibaba.com are mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus 2026-11-23 10:53 [PATCH v5 0/4] mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem Qinyun Tan 2026-11-23 10:53 ` [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID Qinyun Tan @ 2026-11-23 10:53 ` Qinyun Tan 2026-11-23 12:23 ` Muchun Song 2026-12-05 8:05 ` + mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch added to mm-new branch Andrew Morton 2026-11-23 10:53 ` [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker Qinyun Tan 2026-11-23 10:53 ` [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Qinyun Tan 3 siblings, 2 replies; 14+ messages in thread From: Qinyun Tan @ 2026-11-23 10:53 UTC (permalink / raw) To: akpm Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, mkoutny, david, ziy, baolin.wang, usama.arif, david, qi.zheng, yosry, nphamcs, chengming.zhou, xlpang, ryncsn, gourry, cgroups, linux-mm, linux-kernel, Qinyun Tan With cgroup.memory=nokmem, __list_lru_init() collapses every list_lru into per-node lists. That is fine for slab objects, which are not charged per memcg without kmem accounting. But a lru backed by a SHRINKER_NONSLAB shrinker, e.g. the THP deferred split queue or the zswap entries, holds user memory, which is charged regardless of nokmem. Collapsing such an lru loses the per-memcg view of its objects. Reclaim can no longer target just the cgroup under pressure. Keep such lrus memcg aware under nokmem when their backing shrinker is registered SHRINKER_NONSLAB. This leaves the savings of nokmem intact: slab-backed lrus (e.g. the superblock dentry/inode lrus) still fall back to the per-node lists, and the per-memcg lists are allocated only when a memcg actually holds such objects. Fixes: fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/list_lru.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index b4c879d7ba01..78ca07bbc3a3 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -712,7 +712,9 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware, struct shrinker *shr else lru->shrinker_id = -1; - if (mem_cgroup_disabled() || mem_cgroup_kmem_disabled()) + if (mem_cgroup_disabled() || + (mem_cgroup_kmem_disabled() && + (!shrinker || !(shrinker->flags & SHRINKER_NONSLAB)))) memcg_aware = false; #endif -- 2.55.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus 2026-11-23 10:53 ` [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus Qinyun Tan @ 2026-11-23 12:23 ` Muchun Song 2026-12-05 8:05 ` + mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch added to mm-new branch Andrew Morton 1 sibling, 0 replies; 14+ messages in thread From: Muchun Song @ 2026-11-23 12:23 UTC (permalink / raw) To: Qinyun Tan Cc: Muchun Song, akpm, Johannes Weiner, mhocko, Roman Gushchin, Shakeel Butt, mkoutny, David Hildenbrand, ziy, baolin.wang, usama.arif, david, Qi Zheng, yosry, nphamcs, chengming.zhou, xlpang, Kairui Song, gourry, cgroups, linux-mm, linux-kernel > On Nov 23, 2026, at 18:53, Qinyun Tan <qinyuntan@linux.alibaba.com> wrote: > > With cgroup.memory=nokmem, __list_lru_init() collapses every list_lru > into per-node lists. That is fine for slab objects, which are not > charged per memcg without kmem accounting. But a lru backed by a > SHRINKER_NONSLAB shrinker, e.g. the THP deferred split queue or the > zswap entries, holds user memory, which is charged regardless of > nokmem. Collapsing such an lru loses the per-memcg view of its > objects. Reclaim can no longer target just the cgroup under pressure. > > Keep such lrus memcg aware under nokmem when their backing shrinker is > registered SHRINKER_NONSLAB. > > This leaves the savings of nokmem intact: slab-backed lrus (e.g. the > superblock dentry/inode lrus) still fall back to the per-node lists, > and the per-memcg lists are allocated only when a memcg actually holds > such objects. > > Fixes: fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> > Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> ^ permalink raw reply [flat|nested] 14+ messages in thread
* + mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch added to mm-new branch 2026-11-23 10:53 ` [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus Qinyun Tan 2026-11-23 12:23 ` Muchun Song @ 2026-12-05 8:05 ` Andrew Morton 1 sibling, 0 replies; 14+ messages in thread From: Andrew Morton @ 2026-12-05 8:05 UTC (permalink / raw) To: mm-commits, ziy, yosry, xlpang, usama.arif, shakeel.butt, ryncsn, roman.gushchin, qi.zheng, nphamcs, muchun.song, mkoutny, mhocko, hannes, gourry, david, david, chengming.zhou, baolin.wang, qinyuntan, akpm [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 4415 bytes --] The patch titled Subject: mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus has been added to the -mm mm-new branch. Its filename is mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Qinyun Tan <qinyuntan@linux.alibaba.com> Subject: mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus Date: Mon, 23 Nov 2026 18:53:32 +0800 With cgroup.memory=nokmem, __list_lru_init() collapses every list_lru into per-node lists. That is fine for slab objects, which are not charged per memcg without kmem accounting. But a lru backed by a SHRINKER_NONSLAB shrinker, e.g. the THP deferred split queue or the zswap entries, holds user memory, which is charged regardless of nokmem. Collapsing such an lru loses the per-memcg view of its objects. Reclaim can no longer target just the cgroup under pressure. Keep such lrus memcg aware under nokmem when their backing shrinker is registered SHRINKER_NONSLAB. This leaves the savings of nokmem intact: slab-backed lrus (e.g. the superblock dentry/inode lrus) still fall back to the per-node lists, and the per-memcg lists are allocated only when a memcg actually holds such objects. Link: https://patch.msgid.link/20261123105334.2524066-3-qinyuntan@linux.alibaba.com Fixes: fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Michal Koutný <mkoutny@suse.com> Cc: David Hildenbrand <david@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Usama Arif <usama.arif@linux.dev> Cc: Dave Chinner <david@fromorbit.com> Cc: Qi Zheng <qi.zheng@linux.dev> Cc: Yosry Ahmed <yosry@kernel.org> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Xunlei Pang <xlpang@linux.alibaba.com> Cc: Kairui Song <ryncsn@gmail.com> Cc: Gregory Price <gourry@gourry.net> mm/list_lru.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/mm/list_lru.c~mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus +++ a/mm/list_lru.c @@ -712,7 +712,9 @@ int __list_lru_init(struct list_lru *lru else lru->shrinker_id = -1; - if (mem_cgroup_disabled() || mem_cgroup_kmem_disabled()) + if (mem_cgroup_disabled() || + (mem_cgroup_kmem_disabled() && + (!shrinker || !(shrinker->flags & SHRINKER_NONSLAB)))) memcg_aware = false; #endif _ Patches currently in -mm which might be from qinyuntan@linux.alibaba.com are mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker 2026-11-23 10:53 [PATCH v5 0/4] mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem Qinyun Tan 2026-11-23 10:53 ` [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID Qinyun Tan 2026-11-23 10:53 ` [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus Qinyun Tan @ 2026-11-23 10:53 ` Qinyun Tan 2026-11-23 12:19 ` Muchun Song 2026-12-05 8:05 ` + mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch added to mm-new branch Andrew Morton 2026-11-23 10:53 ` [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Qinyun Tan 3 siblings, 2 replies; 14+ messages in thread From: Qinyun Tan @ 2026-11-23 10:53 UTC (permalink / raw) To: akpm Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, mkoutny, david, ziy, baolin.wang, usama.arif, david, qi.zheng, yosry, nphamcs, chengming.zhou, xlpang, ryncsn, gourry, cgroups, linux-mm, linux-kernel, Qinyun Tan On a system booted with cgroup.memory=nokmem, the deferred split shrinker is 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. The shrinker has carried SHRINKER_NONSLAB since commit 0a432dcbeb32 ("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Commit fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") dropped it knowingly: under nokmem the list_lru collapses into a shared per-node list while __list_lru_add() still sets the shrinker bit on whichever memcg happens to add the first item, and with the flag set the shrinker would run twice per reclaim cycle. NONSLAB-backed lrus keep their per-memcg lists under nokmem now, so the shrinker bit identifies the owning memcg again. Restore the flag. This was noticed by Michal during review of the patch "mm/list_lru: don't copy stale shrinker id from non-memcg-aware shrinkers". Link: https://lore.kernel.org/all/ah9PGv12mqai84ES@cmpxchg.org/ Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ Fixes: fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") Suggested-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Acked-by: Zi Yan <ziy@nvidia.com> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Acked-by: Usama Arif <usama.arif@linux.dev> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 75e8641bf9ff..0f1714b10614 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1058,7 +1058,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; -- 2.55.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker 2026-11-23 10:53 ` [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker Qinyun Tan @ 2026-11-23 12:19 ` Muchun Song 2026-12-05 8:05 ` + mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch added to mm-new branch Andrew Morton 1 sibling, 0 replies; 14+ messages in thread From: Muchun Song @ 2026-11-23 12:19 UTC (permalink / raw) To: Qinyun Tan Cc: Muchun Song, akpm, Johannes Weiner, mhocko, Roman Gushchin, Shakeel Butt, mkoutny, David Hildenbrand, ziy, baolin.wang, usama.arif, david, Qi Zheng, yosry, nphamcs, chengming.zhou, xlpang, Kairui Song, gourry, cgroups, linux-mm, linux-kernel > On Nov 23, 2026, at 18:53, Qinyun Tan <qinyuntan@linux.alibaba.com> wrote: > > On a system booted with cgroup.memory=nokmem, the deferred split > shrinker is 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. > > The shrinker has carried SHRINKER_NONSLAB since commit 0a432dcbeb32 > ("mm: shrinker: make shrinker not depend on memcg kmem") precisely > so it would keep working with kmem accounting disabled. Commit > fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") > dropped it knowingly: under nokmem the list_lru collapses into a > shared per-node list while __list_lru_add() still sets the shrinker > bit on whichever memcg happens to add the first item, and with the > flag set the shrinker would run twice per reclaim cycle. > > NONSLAB-backed lrus keep their per-memcg lists under nokmem now, so > the shrinker bit identifies the owning memcg again. Restore the > flag. > > This was noticed by Michal during review of the patch "mm/list_lru: > don't copy stale shrinker id from non-memcg-aware shrinkers". > > Link: https://lore.kernel.org/all/ah9PGv12mqai84ES@cmpxchg.org/ > Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ > Fixes: fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") > Suggested-by: Michal Koutný <mkoutny@suse.com> > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> > Acked-by: Zi Yan <ziy@nvidia.com> > Acked-by: David Hildenbrand (Arm) <david@kernel.org> > Acked-by: Usama Arif <usama.arif@linux.dev> > Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> > Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> ^ permalink raw reply [flat|nested] 14+ messages in thread
* + mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch added to mm-new branch 2026-11-23 10:53 ` [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker Qinyun Tan 2026-11-23 12:19 ` Muchun Song @ 2026-12-05 8:05 ` Andrew Morton 1 sibling, 0 replies; 14+ messages in thread From: Andrew Morton @ 2026-12-05 8:05 UTC (permalink / raw) To: mm-commits, ziy, yosry, xlpang, usama.arif, shakeel.butt, ryncsn, roman.gushchin, qi.zheng, nphamcs, muchun.song, mkoutny, mhocko, hannes, gourry, david, david, chengming.zhou, baolin.wang, qinyuntan, akpm [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 4913 bytes --] The patch titled Subject: mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker has been added to the -mm mm-new branch. Its filename is mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Qinyun Tan <qinyuntan@linux.alibaba.com> Subject: mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker Date: Mon, 23 Nov 2026 18:53:33 +0800 On a system booted with cgroup.memory=nokmem, the deferred split shrinker is 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. The shrinker has carried SHRINKER_NONSLAB since commit 0a432dcbeb32 ("mm: shrinker: make shrinker not depend on memcg kmem") precisely so it would keep working with kmem accounting disabled. Commit fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") dropped it knowingly: under nokmem the list_lru collapses into a shared per-node list while __list_lru_add() still sets the shrinker bit on whichever memcg happens to add the first item, and with the flag set the shrinker would run twice per reclaim cycle. NONSLAB-backed lrus keep their per-memcg lists under nokmem now, so the shrinker bit identifies the owning memcg again. Restore the flag. This was noticed by Michal during review of the patch "mm/list_lru: don't copy stale shrinker id from non-memcg-aware shrinkers". Link: https://patch.msgid.link/20261123105334.2524066-4-qinyuntan@linux.alibaba.com Link: https://lore.kernel.org/all/ah9PGv12mqai84ES@cmpxchg.org/ Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ Fixes: fafaeceb89a5 ("mm: switch deferred split shrinker to list_lru") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Suggested-by: Michal Koutný <mkoutny@suse.com> Acked-by: Zi Yan <ziy@nvidia.com> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Acked-by: Usama Arif <usama.arif@linux.dev> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Dave Chinner <david@fromorbit.com> Cc: Qi Zheng <qi.zheng@linux.dev> Cc: Yosry Ahmed <yosry@kernel.org> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Xunlei Pang <xlpang@linux.alibaba.com> Cc: Kairui Song <ryncsn@gmail.com> Cc: Gregory Price <gourry@gourry.net> mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/huge_memory.c~mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker +++ a/mm/huge_memory.c @@ -1058,7 +1058,8 @@ int folio_memcg_alloc_deferred(struct fo 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; _ Patches currently in -mm which might be from qinyuntan@linux.alibaba.com are mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB 2026-11-23 10:53 [PATCH v5 0/4] mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem Qinyun Tan ` (2 preceding siblings ...) 2026-11-23 10:53 ` [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker Qinyun Tan @ 2026-11-23 10:53 ` Qinyun Tan 2026-11-23 12:18 ` Muchun Song ` (2 more replies) 3 siblings, 3 replies; 14+ messages in thread From: Qinyun Tan @ 2026-11-23 10:53 UTC (permalink / raw) To: akpm Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, mkoutny, david, ziy, baolin.wang, usama.arif, david, qi.zheng, yosry, nphamcs, chengming.zhou, xlpang, ryncsn, gourry, cgroups, linux-mm, linux-kernel, 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 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". Mark it SHRINKER_NONSLAB so it keeps its memcg awareness and runs under memcg reclaim with nokmem. Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") Suggested-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Acked-by: Usama Arif <usama.arif@linux.dev> Acked-by: Nhat Pham <nphamcs@gmail.com> Acked-by: Yosry Ahmed <yosry@kernel.org> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index a2e0314db1cf..730ddf6f5005 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1379,8 +1379,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; -- 2.55.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB 2026-11-23 10:53 ` [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Qinyun Tan @ 2026-11-23 12:18 ` Muchun Song 2026-12-04 14:35 ` Johannes Weiner 2026-12-05 8:05 ` + mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch added to mm-new branch Andrew Morton 2 siblings, 0 replies; 14+ messages in thread From: Muchun Song @ 2026-11-23 12:18 UTC (permalink / raw) To: Qinyun Tan Cc: Muchun Song, akpm, Johannes Weiner, mhocko, Roman Gushchin, Shakeel Butt, mkoutny, David Hildenbrand, ziy, baolin.wang, usama.arif, david, Qi Zheng, yosry, nphamcs, chengming.zhou, xlpang, Kairui Song, gourry, cgroups, linux-mm, linux-kernel > On Nov 23, 2026, at 18:53, Qinyun Tan <qinyuntan@linux.alibaba.com> wrote: > > 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 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". > > Mark it SHRINKER_NONSLAB so it keeps its memcg awareness and runs > under memcg reclaim with nokmem. > > Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ > Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") > Suggested-by: Michal Koutný <mkoutny@suse.com> > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> > Acked-by: Usama Arif <usama.arif@linux.dev> > Acked-by: Nhat Pham <nphamcs@gmail.com> > Acked-by: Yosry Ahmed <yosry@kernel.org> > Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB 2026-11-23 10:53 ` [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Qinyun Tan 2026-11-23 12:18 ` Muchun Song @ 2026-12-04 14:35 ` Johannes Weiner 2026-12-05 8:05 ` + mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch added to mm-new branch Andrew Morton 2 siblings, 0 replies; 14+ messages in thread From: Johannes Weiner @ 2026-12-04 14:35 UTC (permalink / raw) To: Qinyun Tan Cc: akpm, mhocko, roman.gushchin, shakeel.butt, muchun.song, mkoutny, david, ziy, baolin.wang, usama.arif, david, qi.zheng, yosry, nphamcs, chengming.zhou, xlpang, ryncsn, gourry, cgroups, linux-mm, linux-kernel On Mon, Nov 23, 2026 at 06:53:34PM +0800, Qinyun Tan wrote: > 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 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". > > Mark it SHRINKER_NONSLAB so it keeps its memcg awareness and runs > under memcg reclaim with nokmem. > > Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ > Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") > Suggested-by: Michal Koutný <mkoutny@suse.com> > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> > Acked-by: Usama Arif <usama.arif@linux.dev> > Acked-by: Nhat Pham <nphamcs@gmail.com> > Acked-by: Yosry Ahmed <yosry@kernel.org> > Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> This also fixes https://sashiko.dev/#/bug/linux-9e938a12-299b-45b6-bc3f-dfab34a0132a Would you mind adding this to the changelog as well as Fixes: 03375203e1da ("mm: do not allocate shrinker info with cgroup.memory=nokmem") please? ^ permalink raw reply [flat|nested] 14+ messages in thread
* + mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch added to mm-new branch 2026-11-23 10:53 ` [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Qinyun Tan 2026-11-23 12:18 ` Muchun Song 2026-12-04 14:35 ` Johannes Weiner @ 2026-12-05 8:05 ` Andrew Morton 2 siblings, 0 replies; 14+ messages in thread From: Andrew Morton @ 2026-12-05 8:05 UTC (permalink / raw) To: mm-commits, ziy, yosry, xlpang, usama.arif, shakeel.butt, ryncsn, roman.gushchin, qi.zheng, nphamcs, muchun.song, mkoutny, mhocko, hannes, gourry, david, david, chengming.zhou, baolin.wang, qinyuntan, akpm [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 4672 bytes --] The patch titled Subject: mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB has been added to the -mm mm-new branch. Its filename is mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Qinyun Tan <qinyuntan@linux.alibaba.com> Subject: mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Date: Mon, 23 Nov 2026 18:53:34 +0800 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 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". Mark it SHRINKER_NONSLAB so it keeps its memcg awareness and runs under memcg reclaim with nokmem. Link: https://patch.msgid.link/20261123105334.2524066-5-qinyuntan@linux.alibaba.com Link: https://lore.kernel.org/lkml/697713c4-0857-485b-aba7-c74f37a3c8b4@linux.alibaba.com/ Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Suggested-by: Michal Koutný <mkoutny@suse.com> Acked-by: Usama Arif <usama.arif@linux.dev> Acked-by: Nhat Pham <nphamcs@gmail.com> Acked-by: Yosry Ahmed <yosry@kernel.org> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: David Hildenbrand <david@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Dave Chinner <david@fromorbit.com> Cc: Qi Zheng <qi.zheng@linux.dev> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Xunlei Pang <xlpang@linux.alibaba.com> Cc: Kairui Song <ryncsn@gmail.com> Cc: Gregory Price <gourry@gourry.net> mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/zswap.c~mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab +++ a/mm/zswap.c @@ -1379,8 +1379,8 @@ static struct shrinker *zswap_alloc_shri { 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; _ Patches currently in -mm which might be from qinyuntan@linux.alibaba.com are mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-12-05 8:05 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-23 10:53 [PATCH v5 0/4] mm: restore per-memcg reclaim for NONSLAB shrinkers under nokmem Qinyun Tan 2026-11-23 10:53 ` [PATCH v5 1/4] mm: list_lru: index per-memcg lists by memory CSS ID Qinyun Tan 2026-11-23 12:22 ` Muchun Song 2026-12-05 8:05 ` + mm-list_lru-index-per-memcg-lists-by-memory-css-id.patch added to mm-new branch Andrew Morton 2026-11-23 10:53 ` [PATCH v5 2/4] mm: list_lru: keep per-memcg lists with nokmem for NONSLAB-backed lrus Qinyun Tan 2026-11-23 12:23 ` Muchun Song 2026-12-05 8:05 ` + mm-list_lru-keep-per-memcg-lists-with-nokmem-for-nonslab-backed-lrus.patch added to mm-new branch Andrew Morton 2026-11-23 10:53 ` [PATCH v5 3/4] mm: thp: restore SHRINKER_NONSLAB on the deferred split shrinker Qinyun Tan 2026-11-23 12:19 ` Muchun Song 2026-12-05 8:05 ` + mm-thp-restore-shrinker_nonslab-on-the-deferred-split-shrinker.patch added to mm-new branch Andrew Morton 2026-11-23 10:53 ` [PATCH v5 4/4] mm: zswap: mark the zswap shrinker SHRINKER_NONSLAB Qinyun Tan 2026-11-23 12:18 ` Muchun Song 2026-12-04 14:35 ` Johannes Weiner 2026-12-05 8:05 ` + mm-zswap-mark-the-zswap-shrinker-shrinker_nonslab.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.