From: Jeff Layton <jlayton@kernel.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Christian Brauner <brauner@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>,
Amir Goldstein <amir73il@gmail.com>,
Josef Bacik <josef@toxicpanda.com>
Subject: Re: [PATCH] uidgid: make sure we fit into one cacheline
Date: Tue, 10 Sep 2024 14:50:55 -0400 [thread overview]
Message-ID: <048dcc02caf1aeab1165674c4d910b7146248e8d.camel@kernel.org> (raw)
In-Reply-To: <ZuB-_q_rlAy8KkeQ@casper.infradead.org>
On Tue, 2024-09-10 at 18:16 +0100, Matthew Wilcox wrote:
> On Tue, Sep 10, 2024 at 09:51:37AM -0400, Jeff Layton wrote:
> > > Before:
> > >
> > > struct uid_gid_map {
> > > u32 nr_extents; /* 0 4 */
> > >
> > > /* XXX 4 bytes hole, try to pack */
> > >
> > > union {
> > > struct uid_gid_extent extent[5]; /* 8 60 */
> > > struct {
> > > struct uid_gid_extent * forward; /* 8 8 */
> > > struct uid_gid_extent * reverse; /* 16 8 */
> > > }; /* 8 16 */
> > > }; /* 8 64 */
> > >
> > > /* size: 72, cachelines: 2, members: 2 */
> > > /* sum members: 68, holes: 1, sum holes: 4 */
> > > /* last cacheline: 8 bytes */
> > > };
> > >
> > > After:
> > >
> > > struct uid_gid_map {
> > > union {
> > > struct {
> > > struct uid_gid_extent extent[5]; /* 0 60 */
> > > u32 nr_extents; /* 60 4 */
> > > }; /* 0 64 */
> > > struct {
> > > struct uid_gid_extent * forward; /* 0 8 */
> > > struct uid_gid_extent * reverse; /* 8 8 */
> > > }; /* 0 16 */
> > > }; /* 0 64 */
> > >
> > > /* size: 64, cachelines: 1, members: 1 */
> > > };
> >
> > Is this any different from just moving nr_extents to the end of
> > struct_uid_gid_map? I don't quite get how moving it into the union
> > improves things.
>
> It's an alignment question. Look more carefully at the pahole output.
> The array of uid_gid_extent is 4-byte aligned and 60 bytes in size,
> but the two pointers must be eight bytes aligned. That forces the
> compiler to make the whole union 8-byte aligned. If the nr_extents is
> within the union, then it can pack with the array of extents. If not,
> it has to leave a 4-byte gap.
Thanks, that makes sense. With that clarified:
Reviewed-by: Jeff Layton <jlayton@kernel.org>
prev parent reply other threads:[~2024-09-10 18:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 8:16 [PATCH] uidgid: make sure we fit into one cacheline Christian Brauner
2024-09-10 10:48 ` Mateusz Guzik
2024-09-10 13:00 ` Theodore Ts'o
2024-09-10 13:44 ` Mateusz Guzik
2024-09-10 13:51 ` Jeff Layton
2024-09-10 17:16 ` Matthew Wilcox
2024-09-10 18:50 ` Jeff Layton [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=048dcc02caf1aeab1165674c4d910b7146248e8d.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=amir73il@gmail.com \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=josef@toxicpanda.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=willy@infradead.org \
/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