All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: JonasZhou <jonaszhou-oc@zhaoxin.com>
Cc: CobeChen@zhaoxin.com, JonasZhou@zhaoxin.com, LouisQi@zhaoxin.com,
	brauner@kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk
Subject: Re: [PATCH] fs/address_space: move i_mmap_rwsem to mitigate a false sharing with i_mmap.
Date: Mon, 5 Feb 2024 23:08:10 +0000	[thread overview]
Message-ID: <ZcFqWifk2cBExIvG@casper.infradead.org> (raw)
In-Reply-To: <20240205062229.5283-1-jonaszhou-oc@zhaoxin.com>

On Mon, Feb 05, 2024 at 02:22:29PM +0800, JonasZhou wrote:
> When running UnixBench/execl, each execl process repeatedly performs 
> i_mmap_lock_write -> vma_interval_tree_remove/insert -> 
> i_mmap_unlock_write. As indicated below, when i_mmap and i_mmap_rwsem 
> are in the same CACHE Line, there will be more HITM.

(I wasn't familiar with the term HITM.  For anyone else who's
unfamiliar, this appears to mean a HIT in another core's cache, which
has the cachline in the Modified state)

> Func0: i_mmap_lock_write
> Func1: vma_interval_tree_remove/insert
> Func2: i_mmap_unlock_write
> In the same CACHE Line
> Process A | Process B | Process C | Process D | CACHE Line state 
> ----------+-----------+-----------+-----------+-----------------
> Func0     |           |           |           | I->M
>           | Func0     |           |           | HITM M->S
> Func1     |           |           |           | may change to M
>           |           | Func0     |           | HITM M->S
> Func2     |           |           |           | S->M
>           |           |           | Func0     | HITM M->S
> 
> In different CACHE Lines
> Process A | Process B | Process C | Process D | CACHE Line state 
> ----------+-----------+-----------+-----------+-----------------
> Func0     |           |           |           | I->M
>           | Func0     |           |           | HITM M->S
> Func1     |           |           |           | 
>           |           | Func0     |           | S->S
> Func2     |           |           |           | S->M
>           |           |           | Func0     | HITM M->S
> 
> The same issue will occur in Unixbench/shell because the shell 
> launches a lot of shell commands, loads executable files and dynamic 
> libraries into memory, execute, and exit.

OK, I see.

> Yes, his commit has been merged into the Linux kernel, but there 
> is an issue. After moving i_mmap_rwsem below flags, there is a 
> 32-byte gap between i_mmap_rwsem and i_mmap. However, the struct 
> address_space is aligned to sizeof(long), which is 8 on the x86-64 
> architecture. As a result, i_mmap_rwsem and i_mmap may be placed on 
> the same CACHE Line, causing a false sharing problem. This issue has 
> been observed using the perf c2c tool.

Got it.  OK, let's put this patch in.  It's a stopgap measure, clearly.
I'll reply to Dave's email with a longer term solution.

  reply	other threads:[~2024-02-05 23:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02  9:34 [PATCH] fs/address_space: move i_mmap_rwsem to mitigate a false sharing with i_mmap 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
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 [this message]
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=ZcFqWifk2cBExIvG@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=CobeChen@zhaoxin.com \
    --cc=JonasZhou@zhaoxin.com \
    --cc=LouisQi@zhaoxin.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jonaszhou-oc@zhaoxin.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.