From: Christian Brauner <brauner@kernel.org>
To: Amir Goldstein <amir73il@gmail.com>
Cc: chenzhiyin <zhiyin.chen@intel.com>,
viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, nanhai.zou@intel.com
Subject: Re: [PATCH] fs.h: Optimize file struct to prevent false sharing
Date: Wed, 31 May 2023 13:15:43 +0200 [thread overview]
Message-ID: <20230531-symmetrie-absender-8e9af6834753@brauner> (raw)
In-Reply-To: <CAOQ4uxhAn9JOGioLwqt0W6AvS532B5KOFzanWfPOBEuYHsDPTA@mail.gmail.com>
On Tue, May 30, 2023 at 01:02:06PM +0300, Amir Goldstein wrote:
> On Tue, May 30, 2023 at 12:31 PM Christian Brauner <brauner@kernel.org> wrote:
> >
> > On Mon, May 29, 2023 at 10:06:26PM -0400, chenzhiyin wrote:
> > > In the syscall test of UnixBench, performance regression occurred
> > > due to false sharing.
> > >
> > > The lock and atomic members, including file::f_lock, file::f_count
> > > and file::f_pos_lock are highly contended and frequently updated
> > > in the high-concurrency test scenarios. perf c2c indentified one
> > > affected read access, file::f_op.
> > > To prevent false sharing, the layout of file struct is changed as
> > > following
> > > (A) f_lock, f_count and f_pos_lock are put together to share the
> > > same cache line.
> > > (B) The read mostly members, including f_path, f_inode, f_op are
> > > put into a separate cache line.
> > > (C) f_mode is put together with f_count, since they are used
> > > frequently at the same time.
> > >
> > > The optimization has been validated in the syscall test of
> > > UnixBench. performance gain is 30~50%, when the number of parallel
> > > jobs is 16.
> > >
> > > Signed-off-by: chenzhiyin <zhiyin.chen@intel.com>
> > > ---
> >
> > Sounds interesting, but can we see the actual numbers, please?
> > So struct file is marked with __randomize_layout which seems to make
> > this whole reordering pointless or at least only useful if the
> > structure randomization Kconfig is turned off. Is there any precedence
> > to optimizing structures that are marked as randomizable?
>
> Good question!
>
> Also does the impressive improvement is gained only with (A)+(B)+(C)?
>
> (A) and (B) make sense, but something about the claim (C) does not sit right.
> Can you explain this claim?
>
> Putting the read mostly f_mode with frequently updated f_count seems
> counter to the goal of your patch.
> Aren't f_mode and f_flags just as frequently accessed as f_op?
> Shouldn't f_mode belong with the read-mostly members?
>
> What am I missing?
I think that f_mode will be more heavily used because it's checked
everytime you call fget variants. For example, f_mode is used to check
whether the file you're about to get a reference to is an O_PATH file
and, depending on the fget variant that the caller used, denies or
allows the caller to get a reference on that file depending on whether
FMODE_PATH is or isn't set. So you have
if (unlikely(file->f_mode & mask))
if (unlikely(!get_file_rcu(file))) // this is just try to bump f_count
everytime you call an fget variant which should be substantial. Other
places are fdget_pos() where f_mode is also checked right after an
fdget()...
next prev parent reply other threads:[~2023-05-31 11:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 2:06 chenzhiyin
2023-05-30 8:50 ` Christian Brauner
2023-05-30 10:02 ` Amir Goldstein
2023-05-31 11:15 ` Christian Brauner [this message]
2023-05-31 1:55 ` Eric Biggers
2023-05-31 7:54 ` Christian Brauner
2023-06-01 9:24 ` chenzhiyin
2023-06-01 9:49 ` Christian Brauner
2023-06-01 10:06 ` Bernd Schubert
2023-06-05 12:58 ` Christian Brauner
2023-05-31 10:31 ` Chen, Zhiyin
2023-05-31 22:30 ` Dave Chinner
2023-06-01 10:47 ` Chen, Zhiyin
2023-06-02 0:47 ` Dave Chinner
2023-06-02 11:01 ` Chen, Zhiyin
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=20230531-symmetrie-absender-8e9af6834753@brauner \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nanhai.zou@intel.com \
--cc=viro@zeniv.linux.org.uk \
--cc=zhiyin.chen@intel.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
all inboxes | Powered by JetHome®