Re: [PATCH v4] zswap: memcontrol: implement zswap writeback disabling

From: Nhat Pham
Date: Fri Nov 10 2023 - 19:10:36 EST


On Fri, Nov 10, 2023 at 3:10 PM Chris Li <chrisl@xxxxxxxxxx> wrote:
>
> Hi Nhat,
>
> Acked-by: Chris Li <chrisl@xxxxxxxxxx>

Thanks, Chris!

>
> On Mon, Nov 6, 2023 at 3:12 PM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -219,6 +219,12 @@ struct mem_cgroup {
>
> #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
> unsigned long zswap_max;
> +
> + /*
> + * Prevent pages from this memcg from being written back from zswap to
> + * swap, and from being swapped out on zswap store failures.
> + */
> + bool zswap_writeback;
> #endif
>
> I notice the bool is between two integers.
> mem_cgroup structure has a few bool sprinkle in different locations.
> Arrange them together might save a few padding bytes. We can also
> consider using bit fields.
> It is a very minor point, the condition also exists before your change.

This sounds like an optimization worthy of its own patch. Two random
thoughts however:

a) Can this be done at the compiler level? I believe you can reduce
the padding required by sorting the fields of a struct by its size, correct?
That sounds like a job that a compiler should do for us...

b) Re: the bitfield idea, some of the fields are CONFIG-dependent (well
like this one). Might be a bit hairier to do it...

>
> > #endif /* _LINUX_ZSWAP_H */
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index e43b5aba8efc..9cb3ea912cbe 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -5545,6 +5545,11 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
> > WRITE_ONCE(memcg->soft_limit, PAGE_COUNTER_MAX);
> > #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
> > memcg->zswap_max = PAGE_COUNTER_MAX;
> > +
> > + if (parent)
> > + WRITE_ONCE(memcg->zswap_writeback, READ_ONCE(parent->zswap_writeback));
> > + else
> > + WRITE_ONCE(memcg->zswap_writeback, true);
>
> You can combine this two WRITE_ONCE to one
>
> bool writeback = !parent || READ_ONCE(parent->zswap_writeback);
> WRITE_ONCE(memcg->zswap_writeback, writeback);
>

Yeah I originally did something similar, but then decided to do the if-else
instead. Honest no strong preference here - just felt that the if-else was
cleaner at that moment.

> Chris