From: Dave Chinner <david@fromorbit.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: JonasZhou-oc <JonasZhou-oc@zhaoxin.com>,
viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
CobeChen@zhaoxin.com, LouisQi@zhaoxin.com, JonasZhou@zhaoxin.com
Subject: Re: [PATCH] fs/address_space: move i_mmap_rwsem to mitigate a false sharing with i_mmap.
Date: Mon, 5 Feb 2024 14:22:18 +1100 [thread overview]
Message-ID: <ZcBUat4yjByQC7zg@dread.disaster.area> (raw)
In-Reply-To: <Zb1DVNGaorZCDS7R@casper.infradead.org>
On Fri, Feb 02, 2024 at 07:32:36PM +0000, Matthew Wilcox wrote:
> On Fri, Feb 02, 2024 at 03:03:51PM +0000, Matthew Wilcox wrote:
> > On Fri, Feb 02, 2024 at 05:34:07PM +0800, JonasZhou-oc wrote:
> > > In the struct address_space, there is a 32-byte gap between i_mmap
> > > and i_mmap_rwsem. Due to the alignment of struct address_space
> > > variables to 8 bytes, in certain situations, i_mmap and
> > > i_mmap_rwsem may end up in the same CACHE line.
> > >
> > > While running Unixbench/execl, we observe high false sharing issues
> > > when accessing i_mmap against i_mmap_rwsem. We move i_mmap_rwsem
> > > after i_private_list, ensuring a 64-byte gap between i_mmap and
> > > i_mmap_rwsem.
> >
> > I'm confused. i_mmap_rwsem protects i_mmap. Usually you want the lock
> > and the thing it's protecting in the same cacheline.
You are correct in the case that there is never any significant
contention on the lock. i.e. gaining the lock will also pull the
cacheline for the object it protects and so avoid an extra memory
fetch.
However....
> > Why is that not
> > the case here?
>
> We actually had this seven months ago:
>
> https://lore.kernel.org/all/20230628105624.150352-1-lipeng.zhu@intel.com/
>
> Unfortunately, no argumentation was forthcoming about *why* this was
> the right approach. All we got was a different patch and an assertion
> that it still improved performance.
>
> We need to understand what's going on! Please don't do the same thing
> as the other submitter and just assert that it does.
Intuition tells me that what the OP is seeing is the opposite case
to above: there is significant contention on the lock. In that case,
optimal "contention performance" comes from separating the lock and
the objects it protects into different cachelines.
The reason for this is that if the lock and objects it protects are
on the same cacheline, lock contention affects both the lock and the
objects being manipulated inside the critical section. i.e. attempts
to grab the lock pull the cacheline away from the CPU that holds the
lock, and then accesses to the object that are protected by the lock
then have to pull the cacheline back.
i.e. the cost of the extra memory fetch from an uncontended
cacheline is less than the cost of having to repeatedly fetch the
memory inside a critical section on a contended cacheline.
I consider optimisation attempts like this the canary in the mine:
it won't be long before these or similar workloads report
catastrophic lock contention on the lock in question. Moving items
in the structure is equivalent to re-arranging the deck chairs
whilst the ship sinks - we might keep our heads above water a
little longer, but the ship is still sinking and we're still going
to have to fix the leak sooner rather than later...
-Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2024-02-05 3:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-02 9:34 JonasZhou-oc
2024-02-02 10:18 ` Christian Brauner
2024-02-02 15:03 ` Matthew Wilcox
2024-02-02 19:32 ` Matthew Wilcox
2024-02-05 3:22 ` Dave Chinner [this message]
2024-02-05 23:28 ` Matthew Wilcox
2024-02-06 21:35 ` Dave Chinner
2024-02-06 23:33 ` Matthew Wilcox
2024-02-05 6:22 ` JonasZhou
2024-02-05 23:08 ` Matthew Wilcox
2024-02-06 13:06 ` Christian Brauner
2024-02-05 23:15 ` Dave Chinner
2024-03-06 6:16 ` JonasZhou
-- strict thread matches above, loose matches on Subject: below --
2024-02-02 8:33 JonasZhou-oc
2024-02-02 16:20 ` Al Viro
2024-02-05 11:56 ` Christian Brauner
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=ZcBUat4yjByQC7zg@dread.disaster.area \
--to=david@fromorbit.com \
--cc=CobeChen@zhaoxin.com \
--cc=JonasZhou-oc@zhaoxin.com \
--cc=JonasZhou@zhaoxin.com \
--cc=LouisQi@zhaoxin.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--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
Powered by JetHome