From: Nhat Pham <nphamcs@gmail.com>
To: Chris Li <chrisl@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
tj@kernel.org, lizefan.x@bytedance.com,
Johannes Weiner <hannes@cmpxchg.org>,
Domenico Cerasuolo <cerasuolodomenico@gmail.com>,
Yosry Ahmed <yosryahmed@google.com>,
Seth Jennings <sjenning@redhat.com>,
Dan Streetman <ddstreet@ieee.org>,
Vitaly Wool <vitaly.wool@konsulko.com>,
mhocko@kernel.org, roman.gushchin@linux.dev,
Shakeel Butt <shakeelb@google.com>,
muchun.song@linux.dev, Hugh Dickins <hughd@google.com>,
corbet@lwn.net, Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
senozhatsky@chromium.org, rppt@kernel.org,
linux-mm <linux-mm@kvack.org>,
kernel-team@meta.com, LKML <linux-kernel@vger.kernel.org>,
linux-doc@vger.kernel.org, david@ixit.cz
Subject: Re: [PATCH v4] zswap: memcontrol: implement zswap writeback disabling
Date: Fri, 10 Nov 2023 16:10:14 -0800 [thread overview]
Message-ID: <CAKEwX=OgN_xQWrp_OYkK1BRq3DFW4he9OSycdjBm0BNy+vpPAg@mail.gmail.com> (raw)
In-Reply-To: <CAF8kJuPXBLpG2d4sje6ntrA+U-AnLzu3sNpJK02YxNcg04YNng@mail.gmail.com>
On Fri, Nov 10, 2023 at 3:10 PM Chris Li <chrisl@kernel.org> wrote:
>
> Hi Nhat,
>
> Acked-by: Chris Li <chrisl@kernel.org>
Thanks, Chris!
>
> On Mon, Nov 6, 2023 at 3:12 PM Nhat Pham <nphamcs@gmail.com> 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
next prev parent reply other threads:[~2023-11-11 0:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 23:11 Nhat Pham
2023-11-10 23:09 ` Chris Li
2023-11-11 0:10 ` Nhat Pham [this message]
2023-11-11 18:22 ` Chris Li
2023-11-12 0:06 ` Nhat Pham
2023-11-14 22:50 ` Andrew Morton
2023-11-15 17:25 ` Nhat Pham
2023-11-14 17:19 ` Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKEwX=OgN_xQWrp_OYkK1BRq3DFW4he9OSycdjBm0BNy+vpPAg@mail.gmail.com' \
--to=nphamcs@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cerasuolodomenico@gmail.com \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=david@ixit.cz \
--cc=ddstreet@ieee.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kernel-team@meta.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=shakeelb@google.com \
--cc=sjenning@redhat.com \
--cc=tj@kernel.org \
--cc=vitaly.wool@konsulko.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox