From: Jeff Layton <jlayton@kernel.org>
To: Mike Snitzer <snitzer@kernel.org>, linux-nfs@vger.kernel.org
Cc: Anna Schumaker <anna@kernel.org>,
Trond Myklebust <trondmy@hammerspace.com>
Subject: Re: [PATCH v2] nfs: avoid i_lock contention in nfs_clear_invalid_mapping
Date: Mon, 21 Oct 2024 10:29:42 -0400 [thread overview]
Message-ID: <bf4c7b07b542c2f7c4ce692e4f0bd908c60a2796.camel@kernel.org> (raw)
In-Reply-To: <20241018211541.42705-1-snitzer@kernel.org>
On Fri, 2024-10-18 at 17:15 -0400, Mike Snitzer wrote:
> Multi-threaded buffered reads to the same file exposed significant
> inode spinlock contention in nfs_clear_invalid_mapping().
>
> Eliminate this spinlock contention by checking flags without locking,
> instead using smp_rmb and smp_load_acquire accordingly, but then take
> spinlock and double-check these inode flags.
>
> Also refactor nfs_set_cache_invalid() slightly to use
> smp_store_release() to pair with nfs_clear_invalid_mapping()'s
> smp_load_acquire().
>
> While this fix is beneficial for all multi-threaded buffered reads
> issued by an NFS client, this issue was identified in the context of
> surprisingly low LOCALIO performance with 4K multi-threaded buffered
> read IO. This fix dramatically speeds up LOCALIO performance:
>
> before: read: IOPS=1583k, BW=6182MiB/s (6482MB/s)(121GiB/20002msec)
> after: read: IOPS=3046k, BW=11.6GiB/s (12.5GB/s)(232GiB/20001msec)
>
> Fixes: 17dfeb911339 ("NFS: Fix races in nfs_revalidate_mapping")
> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
> ---
> fs/nfs/inode.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> v2: fix issue Jeff Layton raised, need: flags |= nfsi->cache_validity;
>
> diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
> index 542c7d97b235..cc7a32b32676 100644
> --- a/fs/nfs/inode.c
> +++ b/fs/nfs/inode.c
> @@ -205,12 +205,15 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
> nfs_fscache_invalidate(inode, 0);
> flags &= ~NFS_INO_REVAL_FORCED;
>
> - nfsi->cache_validity |= flags;
> + flags |= nfsi->cache_validity;
> + if (inode->i_mapping->nrpages == 0)
> + flags &= ~NFS_INO_INVALID_DATA;
>
> - if (inode->i_mapping->nrpages == 0) {
> - nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
> - nfs_ooo_clear(nfsi);
> - } else if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
> + /* pairs with nfs_clear_invalid_mapping()'s smp_load_acquire() */
> + smp_store_release(&nfsi->cache_validity, flags);
> +
> + if (inode->i_mapping->nrpages == 0 ||
> + nfsi->cache_validity & NFS_INO_INVALID_DATA) {
> nfs_ooo_clear(nfsi);
> }
> trace_nfs_set_cache_invalid(inode, 0);
> @@ -1408,6 +1411,13 @@ int nfs_clear_invalid_mapping(struct address_space *mapping)
> TASK_KILLABLE|TASK_FREEZABLE_UNSAFE);
> if (ret)
> goto out;
> + smp_rmb(); /* pairs with smp_wmb() below */
> + if (test_bit(NFS_INO_INVALIDATING, bitlock))
> + continue;
> + /* pairs with nfs_set_cache_invalid()'s smp_store_release() */
> + if (!(smp_load_acquire(&nfsi->cache_validity) & NFS_INO_INVALID_DATA))
> + goto out;
> + /* Slow-path that double-checks with spinlock held */
> spin_lock(&inode->i_lock);
> if (test_bit(NFS_INO_INVALIDATING, bitlock)) {
> spin_unlock(&inode->i_lock);
LGTM!
Reviewed-by: Jeff Layton <jlayton@kernel.org>
prev parent reply other threads:[~2024-10-21 14:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 21:15 [PATCH v2] nfs: avoid i_lock contention in nfs_clear_invalid_mapping Mike Snitzer
2024-10-21 14:29 ` 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=bf4c7b07b542c2f7c4ce692e4f0bd908c60a2796.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=anna@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=snitzer@kernel.org \
--cc=trondmy@hammerspace.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 NNTP newsgroup(s).