Re: [PATCH v3 6/7] mm: list_lru: introduce folio_memcg_list_lru_alloc()
From: Lorenzo Stoakes (Oracle)
Date: Wed Apr 01 2026 - 10:57:58 EST
On Mon, Mar 30, 2026 at 12:54:28PM -0400, Johannes Weiner wrote:
> On Tue, Mar 24, 2026 at 12:01:55PM +0000, Lorenzo Stoakes (Oracle) wrote:
> > On Wed, Mar 18, 2026 at 03:53:24PM -0400, Johannes Weiner wrote:
> > > memcg_list_lru_alloc() is called every time an object that may end up
> > > on the list_lru is created. It needs to quickly check if the list_lru
> > > heads for the memcg already exist, and allocate them when they don't.
> > >
> > > Doing this with folio objects is tricky: folio_memcg() is not stable
> > > and requires either RCU protection or pinning the cgroup. But it's
> > > desirable to make the existence check lightweight under RCU, and only
> > > pin the memcg when we need to allocate list_lru heads and may block.
> > >
> > > In preparation for switching the THP shrinker to list_lru, add a
> > > helper function for allocating list_lru heads coming from a folio.
> > >
> > > Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> > > Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
> >
> > Logic LGTM, but would be nice to have some kdoc. With that addressed, feel free
> > to add:
> >
> > Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@xxxxxxxxxx>
>
> Thanks!
>
> > > include/linux/list_lru.h | 12 ++++++++++++
> > > mm/list_lru.c | 39 ++++++++++++++++++++++++++++++++++-----
> > > 2 files changed, 46 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
> > > index 4afc02deb44d..4bd29b61c59a 100644
> > > --- a/include/linux/list_lru.h
> > > +++ b/include/linux/list_lru.h
> > > @@ -81,6 +81,18 @@ static inline int list_lru_init_memcg_key(struct list_lru *lru, struct shrinker
> > >
> > > int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
> > > gfp_t gfp);
> > > +
> > > +#ifdef CONFIG_MEMCG
> > > +int folio_memcg_list_lru_alloc(struct folio *folio, struct list_lru *lru,
> > > + gfp_t gfp);
> >
> > Could we have a kdoc comment for this? Thanks!
>
> And one kdoc comment.
>
> Your total will be 8.75, you can pull up to the next window, sir.
:>) Thanks!