On Sat, Apr 3, 2021 at 12:21 AM Johannes Weiner <han...@cmpxchg.org> wrote:
>
> On Tue, Mar 30, 2021 at 06:15:20PM +0800, Muchun Song wrote:
> > We already have a helper lruvec_memcg() to get the memcg from lruvec, we
> > do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So use
> > lruvec_memcg() instead.
> >
> > Signed-off-by: Muchun Song <songmuc...@bytedance.com>
> > ---
> >  include/linux/memcontrol.h | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index a35a22994cf7..6e3283828391 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -744,20 +744,20 @@ static inline struct lruvec 
> > *mem_cgroup_page_lruvec(struct page *page)
> >       return mem_cgroup_lruvec(memcg, pgdat);
> >  }
> >
> > +static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec);
>
> Please reorder the functions instead to avoid forward decls.

OK. Will fix it in the next version.


>
> >  static inline bool lruvec_holds_page_lru_lock(struct page *page,
> >                                             struct lruvec *lruvec)
> >  {
> >       pg_data_t *pgdat = page_pgdat(page);
> >       const struct mem_cgroup *memcg;
> > -     struct mem_cgroup_per_node *mz;
> >
> >       if (mem_cgroup_disabled())
> >               return lruvec == &pgdat->__lruvec;
> >
> > -     mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
> >       memcg = page_memcg(page) ? : root_mem_cgroup;
> >
> > -     return lruvec->pgdat == pgdat && mz->memcg == memcg;
> > +     return lruvec->pgdat == pgdat && lruvec_memcg(lruvec) == memcg;
>
> Looks reasonable to me, but I wonder if there is more we can do.
>
> lruvec_memcg() already handles CONFIG_MEMCG and mem_cgroup_disabled()
> combinations, and there is also a lruvec_pgdat() which does.
>
> One thing that is odd is page_memcg(page) ? : root_mem_cgroup. How can
> lruvec pages not have a page_memcg()? mem_cgroup_page_lruvec() has:

You are right. page_memcg() cannot be NULL.

>
>         memcg = page_memcg(page);
>         VM_WARN_ON_ONCE_PAGE(!memcg && !mem_cgroup_disabled(), page);
>
> Unless I'm missing something, we should be able to have a single
> definition for this function that works for !CONFIG_MEMCG,
> CONFIG_MEMCG + mem_cgroup_disabled() and CONFIG_MEMCG:
>
> lruvec_holds_page_lru_lock()
> {
>         return lruvec_pgdat(lruvec) == page_pgdat(page) &&
>                 lruvec_memcg(lruvec) == page_memcg(page);
> }

Aha, how wonderful! It is simpler than mine. I will use this.
Thanks for your suggestions.

Reply via email to