All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Anna Schumaker <anna@kernel.org>
Cc: Trond Myklebust <trondmy@kernel.org>,
	linux-nfs@vger.kernel.org,
	Jonathan Flynn <jonathan.flynn@hammerspace.com>
Subject: Re: [PATCH 01/11] NFSv4/flexfiles: move layoutstats accounting to a per-stripe lock
Date: Thu, 5 Nov 2026 16:19:31 -0500	[thread overview]
Message-ID: <auzy4-viIAkPoUVA@kernel.org> (raw)
In-Reply-To: <6fe7924c-dbd8-4121-a467-4645855b58ea@app.fastmail.com>

On Thu, Nov 05, 2026 at 11:12:44AM -0500, Anna Schumaker wrote:
> Hi Mike,
> 
> On Mon, Nov 2, 2026, at 2:10 PM, Mike Snitzer wrote:
> > From: Jonathan Flynn <jonathan.flynn@hammerspace.com>
> >
> > Since striped layouts were introduced, a mirror owns an array of
> > struct nfs4_ff_layout_ds_stripe and each stripe carries its own
> > read_stat and write_stat.  The lock protecting those statistics stayed
> > behind in the mirror, so every DS RPC in the layout serialises on the
> > same spinlock twice: once in ff_layout_{read,write}_prepare_common()
> > and again on completion in ff_layout_{read,write}_count_stats().
> >
> > For a RAID0-style layout (one mirror, many stripes) that lock is
> > effectively per-file, and striping then multiplies RPC parallelism
> > without multiplying lock parallelism.
> >
> > On a 64-core client reading a single file from a 32-stripe layout with
> > a 128KiB stripe unit (2MB O_DIRECT reads, ~36.7 GB/s, ~275k NFSv3 READ
> > RPCs/s, i.e. ~550k acquisitions/s of one lock), perf reports 45% of all
> > CPU in native_queued_spin_lock_slowpath, and lock:contention_begin
> > attributes 73% of the contention events to the two layoutstats paths:
> >
> >   36.4%  rpc_exit_task -> ff_layout_read_count_stats ->
> >          ff_layout_read_record_layoutstats_done -> _raw_spin_lock
> >   36.3%  ff_layout_read_prepare_v3 ->
> >          ff_layout_read_record_layoutstats_start -> _raw_spin_lock
> >
> > Move the lock into struct nfs4_ff_layout_ds_stripe, next to the
> > statistics it protects, so that I/O to different stripes no longer
> > contends.  The reporting paths take the same per-stripe lock.
> >
> > NFS4_FF_MIRROR_STAT_AVAIL is a mirror-wide bit operation and does not
> > need the lock; set it outside the critical section so the mirror's
> > cacheline is not written under it.
> >
> > ffl->last_report_time is shared by every mirror and stripe of a layout
> > and was already updated under different mirror locks, so it was never
> > serialised.  Make that explicit with a cmpxchg(): whichever racer wins
> > sends the LAYOUTSTATS report.
> >
> > Signed-off-by: Jonathan Flynn <jonathan.flynn@hammerspace.com>
> > Signed-off-by: Mike Snitzer <snitzer@hammerspace.com>
> > ---
> >  fs/nfs/flexfilelayout/flexfilelayout.c | 45 +++++++++++++++-----------
> >  fs/nfs/flexfilelayout/flexfilelayout.h |  2 ++
> >  2 files changed, 28 insertions(+), 19 deletions(-)
> >
> > diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c 
> > b/fs/nfs/flexfilelayout/flexfilelayout.c
> > index 9492d6bc1d1a7..bac0b7f559201 100644
> > --- a/fs/nfs/flexfilelayout/flexfilelayout.c
> > +++ b/fs/nfs/flexfilelayout/flexfilelayout.c
> > @@ -744,13 +747,17 @@ nfs4_ff_layoutstat_start_io(struct 
> > nfs4_ff_layout_mirror *mirror,
> >  		report_interval = (s64)mirror->report_interval * 1000LL;
> >  	else if (layoutstats_timer != 0)
> >  		report_interval = (s64)layoutstats_timer * 1000LL;
> > -	if (ktime_to_ms(ktime_sub(now, ffl->last_report_time)) >=
> > -			report_interval) {
> > -		ffl->last_report_time = now;
> > -		return true;
> > -	}
> > 
> > -	return false;
> > +	/*
> > +	 * last_report_time is shared by every mirror and stripe of this
> > +	 * layout, so it was never serialised by the mirror lock either.
> > +	 * Make that explicit: whoever wins the cmpxchg() reports.
> > +	 */
> > +	last_report = READ_ONCE(ffl->last_report_time);
> > +	if (ktime_to_ms(ktime_sub(now, last_report)) < report_interval)
> > +		return false;
> > +
> > +	return try_cmpxchg64(&ffl->last_report_time, &last_report, now);
> 
> As far as I can tell, this is the first use of try_cmpxchg64 in any filesystem
> code. This has me worried it's the wrong function to be calling here. Is there
> any reason we can't use atomic64_try_cmpxchg(), which is what I see being used
> by other filesystem code?

Not seeing any other caller of atomic64_try_cmpxchg() that isn't using
atomic64_t.

nfs4_flexfile_layout's last_report_time datatype is s64 (ktime_t), not
atomic64_t.

Later in this series nfs4_ff_layoutstat_set_start_time() also uses it
with nfs4_ff_layout_mirror's start_time.

  reply	other threads:[~2026-11-05 21:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 19:10 [PATCH 00/11] NFSv4/flexfiles: scale layoutstats for striped layouts Mike Snitzer
2026-11-02 19:10 ` [PATCH 01/11] NFSv4/flexfiles: move layoutstats accounting to a per-stripe lock Mike Snitzer
2026-11-05 16:12   ` Anna Schumaker
2026-11-05 21:19     ` Mike Snitzer [this message]
2026-11-02 19:11 ` [PATCH 02/11] NFSv4/flexfiles: drop the now-unused per-mirror lock Mike Snitzer
2026-11-02 19:11 ` [PATCH 03/11] NFSv4/flexfiles: cacheline align the per-stripe layoutstats Mike Snitzer
2026-11-05 15:34   ` Anna Schumaker
2026-11-05 21:23     ` Mike Snitzer
2026-11-02 19:11 ` [PATCH 04/11] NFSv4/flexfiles: make dss_info->start_time write-once Mike Snitzer
2026-11-05 16:14   ` Anna Schumaker
2026-11-05 21:27     ` Mike Snitzer
2026-11-02 19:11 ` [PATCH 05/11] NFSv4/flexfiles: drop the redundant atomic from the busy timer Mike Snitzer
2026-11-05 16:46   ` Anna Schumaker
2026-11-02 19:11 ` [PATCH 06/11] NFSv4/flexfiles: pair the in-flight count with the layoutstats updates Mike Snitzer
2026-11-05 17:44   ` Anna Schumaker
2026-11-02 19:11 ` [PATCH 07/11] NFSv4/flexfiles: derive ffil_ops_requested rather than storing it Mike Snitzer
2026-11-05 18:01   ` Anna Schumaker
2026-11-02 19:11 ` [PATCH 08/11] NFSv4/flexfiles: give each direction its own lock and cacheline Mike Snitzer
2026-11-05 19:58   ` Anna Schumaker
2026-11-02 19:11 ` [PATCH 09/11] NFSv4/flexfiles: drop NFS4_FF_MIRROR_STAT_AVAIL Mike Snitzer
2026-11-05 20:17   ` Anna Schumaker
2026-11-02 19:11 ` [PATCH 10/11] NFSv4/flexfiles: rotate LAYOUTSTATS reporting across a mirror's stripes Mike Snitzer
2026-11-05 21:41   ` Anna Schumaker
2026-11-02 19:11 ` [PATCH 11/11] NFSv4/flexfiles: take the report decision out of the critical section Mike Snitzer

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=auzy4-viIAkPoUVA@kernel.org \
    --to=snitzer@kernel.org \
    --cc=anna@kernel.org \
    --cc=jonathan.flynn@hammerspace.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@kernel.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 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.