Re: [PATCH v7 3/6] zswap: make shrinking memcg-aware

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 29, 2023 at 4:21 PM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
>
> On Wed, Nov 29, 2023 at 7:17 AM Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
> >
> > On Mon, Nov 27, 2023 at 03:45:57PM -0800, Nhat Pham wrote:
> > >  static void shrink_worker(struct work_struct *w)
> > >  {
> > >       struct zswap_pool *pool = container_of(w, typeof(*pool),
> > >                                               shrink_work);
> > > +     struct mem_cgroup *memcg;
> > >       int ret, failures = 0;
> > >
> > > +     /* global reclaim will select cgroup in a round-robin fashion. */
> > >       do {
> > > -             ret = zswap_reclaim_entry(pool);
> > > -             if (ret) {
> > > -                     zswap_reject_reclaim_fail++;
> > > -                     if (ret != -EAGAIN)
> > > -                             break;
> > > +             spin_lock(&zswap_pools_lock);
> > > +             memcg = pool->next_shrink =
> > > +                     mem_cgroup_iter_online(NULL, pool->next_shrink, NULL, true);
> > > +
> > > +             /* full round trip */
> > > +             if (!memcg) {
> > > +                     spin_unlock(&zswap_pools_lock);
> > >                       if (++failures == MAX_RECLAIM_RETRIES)
> > >                               break;
> > > +
> > > +                     goto resched;
> > >               }
> > > +
> > > +             /*
> > > +              * Acquire an extra reference to the iterated memcg in case the
> > > +              * original reference is dropped by the zswap offlining callback.
> > > +              */
> > > +             css_get(&memcg->css);
> >
> > struct mem_cgroup isn't defined when !CONFIG_MEMCG. This needs a
> > mem_cgroup_get() wrapper and a dummy function for no-memcg builds.
>
> I got this exact same issue a couple of versions ago, but it was
> hidden behind another helper function which can be implemented as a
> no-op in the case of !CONFIG_MEMCG, so I forgot about it until now. It
> always strikes me a bit weird that we have mem_cgroup_put() but not an
> equivalent get - let me correct that.

Actually, I'll instead implement mem_cgroup_tryget_online(), as we
have to check for the cgroup's onlineness as well anyway! If it's
online, then keep the extra reference - all good. If it's not, then
drop the original reference before releasing the lock.


>
> >
> > With that fixed, though, everything else looks good to me:
> >
> > Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>
>
> Thanks for the review, Johannes!





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux