From: Yosry Ahmed <yosryahmed@google.com>
To: Shakeel Butt <shakeelb@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Greg Thelen <gthelen@google.com>
Subject: Re: [PATCH mm-hotfixes-unstable] mm: memcg: fix struct memcg_vmstats_percpu size and alignment
Date: Fri, 2 Feb 2024 20:39:49 -0800 [thread overview]
Message-ID: <CAJD7tkbzaiOWpxPTf6xbNvy=6HXdLbnGQMGgi6Krq9q4j+L-WQ@mail.gmail.com> (raw)
In-Reply-To: <CALvZod62OZVQ7sYKY5V4685eo3RC8esXNyK87JG9VLX3bjeKpw@mail.gmail.com>
On Fri, Feb 2, 2024 at 8:34 PM Shakeel Butt <shakeelb@google.com> wrote:
>
> On Fri, Feb 2, 2024 at 8:23 PM Yosry Ahmed <yosryahmed@google.com> wrote:
> >
> > On Fri, Feb 2, 2024 at 8:13 PM Shakeel Butt <shakeelb@google.com> wrote:
> > >
> > > On Fri, Feb 2, 2024 at 4:34 PM Yosry Ahmed <yosryahmed@google.com> wrote:
> > > >
> > > > Commit da10d7e140196 ("mm: memcg: optimize parent iteration in
> > > > memcg_rstat_updated()") added two additional pointers to the end of
> > > > struct memcg_vmstats_percpu with CACHELINE_PADDING to put them in a
> > > > separate cacheline. This caused the struct size to increase from 1200 to
> > > > 1280 on my config (80 extra bytes instead of 16).
> > > >
> > > > Upon revisiting, the relevant struct members do not need to be on a
> > > > separate cacheline, they just need to fit in a single one. This is a
> > > > percpu struct, so there shouldn't be any contention on that cacheline
> > > > anyway. Move the members to the beginning of the struct and cachealign
> > > > the first member. Add a comment about the members that need to fit
> > > > together in a cacheline.
> > > >
> > > > The struct size is now 1216 on my config with this change.
> > > >
> > > > Fixes: da10d7e140196 ("mm: memcg: optimize parent iteration in memcg_rstat_updated()")
> > > > Reported-by: Greg Thelen <gthelen@google.com>
> > > > Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
> > > > ---
> > > > mm/memcontrol.c | 19 +++++++++----------
> > > > 1 file changed, 9 insertions(+), 10 deletions(-)
> > > >
> > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > > > index d9ca0fdbe4ab0..09f09f37e397e 100644
> > > > --- a/mm/memcontrol.c
> > > > +++ b/mm/memcontrol.c
> > > > @@ -621,6 +621,15 @@ static inline int memcg_events_index(enum vm_event_item idx)
> > > > }
> > > >
> > > > struct memcg_vmstats_percpu {
> > > > + /* Stats updates since the last flush */
> > > > + unsigned int stats_updates ____cacheline_aligned;
> > >
> > > Why do you need ____cacheline_aligned here? From what I understand for
> > > the previous patch you want stats_updates, parent and vmstats on the
> > > same cacheline, right?
> >
> > Yes. I am trying to ensure that stats_updates sits at the beginning of
> > a cacheline to ensure they all fit in one cacheline. Is this
> > implicitly guaranteed somehow?
> >
> > >
> > > I would say just remove the CACHELINE_PADDING() from the previous
> > > patch and we are good.
> >
> > IIUC, without CACHELINE_PADDING(), they may end up on different cache
> > lines, depending on the size of the arrays before them in the struct
> > (which depends on several configs). Am I misunderstanding?
> >
>
> Yeah keeping them at the start will be better. Move
> ____cacheline_aligned to the end of the struct definition like:
>
> struct memcg_vmstats_percpu {
> ...
> } ____cacheline_aligned;
Will send a v2 shortly, thanks. I honestly didn't know what the
difference was, but both gave me the same results. Is using
____cacheline_aligned with the first member the same as using it at
the end of the definition?
prev parent reply other threads:[~2024-02-03 4:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-03 0:34 [PATCH mm-hotfixes-unstable] mm: memcg: fix struct memcg_vmstats_percpu size and alignment Yosry Ahmed
2024-02-03 4:13 ` Shakeel Butt
2024-02-03 4:22 ` Yosry Ahmed
2024-02-03 4:34 ` Shakeel Butt
2024-02-03 4:39 ` Yosry Ahmed [this message]
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='CAJD7tkbzaiOWpxPTf6xbNvy=6HXdLbnGQMGgi6Krq9q4j+L-WQ@mail.gmail.com' \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).