Re: [PATCH] mm: workingset: compare shadow nodes node-wide without kmem accounting
From: Barry Song
Date: Mon Nov 16 2026 - 15:05:54 EST
On Tue, Nov 17, 2026 at 1:40 AM T.J. Mercier <tjmercier@xxxxxxxxxx> wrote:
>
> On Fri, Nov 6, 2026 at 3:59 PM T.J. Mercier <tjmercier@xxxxxxxxxx> wrote:
> >
> > count_shadow_nodes() limits the number of xarray nodes holding shadow
> > entries to 1/8th of the pages that could be using them. For a memcg, it
> > counts the LRU and slab pages local to that memcg.
> >
> > With kmem accounting disabled (cgroup.memory=nokmem), shadow nodes are
> > not charged to any memcg and __list_lru_init() makes the shadow_nodes
> > list_lru non-memcg-aware, so all shadow nodes of a NUMA node are on a
> > single list. shrinker_alloc() falls back to a non-memcg-aware shadow
> > node shrinker, which shrink_slab() only invokes for the root memcg.
> > count_shadow_nodes() therefore compares every shadow node on the NUMA
> > node against the pages local to the root memcg.
> >
> > When most tasks run in child memcgs, the root memcg only holds a small
> > fraction of all pages, so the shadow node limit derived from the root
> > memcg page count is far below the number of shadow nodes on the NUMA
> > node. Since the shrinker has seeks == 0, every root shrink_slab() call
> > trims about half of the "excess" shadow nodes. Most refault information
> > is thrown away, so refaults of recently evicted file folios are not
> > detected. Refaulted folios lose PG_workingset and the workingset_refault
> > and workingset_restore stats drop.
> >
> > In testing on devices with kmem accounting disabled, moving tasks from
> > the root memcg into per-application memcgs dropped workingset_nodes from
> > ~37,000 to ~900 and raised workingset_nodereclaim 4.6x while
> > pgsteal_file rose by ~12%.
> >
> > When kmem accounting is disabled, compare the shadow nodes against the
> > whole NUMA node, as is done without memcg. Behavior with kmem
> > accounting enabled is unchanged.
> >
> > Cc: Jaewon Kim <jaewon31.kim@xxxxxxxxxxx>
> > Tested-by: Jaeseon Sim <jason.sim@xxxxxxxxxxx> # Galaxy A18 LTE
> > Tested-by: Youngchan Kim <ycshark.kim@xxxxxxxxxxx> # Galaxy S27
> > Tested-by: Dmitry Skiba <dskiba@xxxxxxxxxx> # Pixel 10
> > Signed-off-by: T.J. Mercier <tjmercier@xxxxxxxxxx>
>
> I'm guessing there aren't many other nokmem users?
>
Out of curiosity, is `cgroup.memory=nokmem` commonly used
on Android devices? If so, what's the rationale behind it?
As for the patch itself, it makes sense to me.
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>