From: Mike Snitzer <snitzer@kernel.org>
To: Anna Schumaker <anna@kernel.org>, Trond Myklebust <trondmy@kernel.org>
Cc: Mike Snitzer <snitzer@hammerspace.com>,
linux-nfs@vger.kernel.org,
Jonathan Flynn <jonathan.flynn@hammerspace.com>
Subject: [PATCH v3 11/12] NFSv4/flexfiles: take the report decision out of the critical section
Date: Fri, 6 Nov 2026 13:20:59 -0500 [thread overview]
Message-ID: <20261106182105.78611-12-snitzer@kernel.org> (raw)
In-Reply-To: <20261106182105.78611-1-snitzer@kernel.org>
From: Mike Snitzer <snitzer@hammerspace.com>
When an I/O to a data server starts, the stripe lock also covered the
decision to send a LAYOUTSTATS report. That decision reads the mirror
and the layout header, divides in ktime_to_ms(), and does a cmpxchg on
ffl->last_report_time. None of it is data that the lock protects.
Move the decision into nfs4_ff_layoutstat_report_due() and call it,
and nfs4_ff_layoutstat_set_start_time(), after the unlock. The lock now
covers two writes to one cacheline. The order of the updates and the
report does not change.
nfs4_ff_layoutstat_end_io() loses its unused dss_info argument.
Signed-off-by: Mike Snitzer <snitzer@hammerspace.com>
---
fs/nfs/flexfilelayout/flexfilelayout.c | 49 ++++++++++++++------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 5c61d32a7cbde..31d5dbd4debcc 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -739,32 +739,36 @@ nfs4_ff_layoutstat_set_start_time(struct nfs4_ff_layout_ds_stripe *dss_info,
atomic64_try_cmpxchg(&dss_info->start_time, &unset, now);
}
-/*
- * Account for an I/O about to be sent to this stripe, and return true if a
- * LAYOUTSTATS report is due.
- */
-static bool
-nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_ds_stripe *dss_info,
- struct nfs4_ff_layoutstat *layoutstat,
+/* Account for an I/O about to be sent to this stripe. */
+static void
+nfs4_ff_layoutstat_start_io(struct nfs4_ff_layoutstat *layoutstat,
__u64 requested, ktime_t now)
+{
+ lockdep_assert_held(&layoutstat->lock);
+
+ nfs4_ff_start_busy_timer(layoutstat, now);
+ layoutstat->io_stat.bytes_requested += requested;
+}
+
+/*
+ * Is a LAYOUTSTATS report due? Called outside the statistics locks, which
+ * protect none of this. last_report_time is shared by every mirror and
+ * stripe of the layout: the cmpxchg winner reports.
+ */
+static bool
+nfs4_ff_layoutstat_report_due(struct nfs4_ff_layout_ds_stripe *dss_info,
+ ktime_t now)
{
struct nfs4_ff_layout_mirror *mirror = dss_info->mirror;
struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(mirror->layout);
s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
s64 last_report;
- lockdep_assert_held(&layoutstat->lock);
-
- nfs4_ff_start_busy_timer(layoutstat, now);
- layoutstat->io_stat.bytes_requested += requested;
-
- nfs4_ff_layoutstat_set_start_time(dss_info, now);
if (mirror->report_interval != 0)
report_interval = (s64)mirror->report_interval * 1000LL;
else if (layoutstats_timer != 0)
report_interval = (s64)layoutstats_timer * 1000LL;
- /* Shared by every mirror and stripe: the cmpxchg winner reports. */
last_report = atomic64_read(&ffl->last_report_time);
if (ktime_to_ms(ktime_sub(now, last_report)) < report_interval)
return false;
@@ -774,8 +778,7 @@ nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_ds_stripe *dss_info,
/* Account for an I/O that has completed on this stripe. */
static void
-nfs4_ff_layoutstat_end_io(struct nfs4_ff_layout_ds_stripe *dss_info,
- struct nfs4_ff_layoutstat *layoutstat,
+nfs4_ff_layoutstat_end_io(struct nfs4_ff_layoutstat *layoutstat,
__u64 requested,
__u64 completed,
ktime_t time_completed,
@@ -809,10 +812,11 @@ nfs4_ff_layout_stat_io_start_read(struct inode *inode,
bool report;
spin_lock(&dss_info->read_stat.lock);
- report = nfs4_ff_layoutstat_start_io(dss_info, &dss_info->read_stat,
- requested, now);
+ nfs4_ff_layoutstat_start_io(&dss_info->read_stat, requested, now);
spin_unlock(&dss_info->read_stat.lock);
+ nfs4_ff_layoutstat_set_start_time(dss_info, now);
+ report = nfs4_ff_layoutstat_report_due(dss_info, now);
if (report)
pnfs_report_layoutstat(inode, nfs_io_gfp_mask());
}
@@ -827,7 +831,7 @@ nfs4_ff_layout_stat_io_end_read(struct rpc_task *task,
struct nfs4_ff_layout_ds_stripe *dss_info = &mirror->dss[dss_id];
spin_lock(&dss_info->read_stat.lock);
- nfs4_ff_layoutstat_end_io(dss_info, &dss_info->read_stat,
+ nfs4_ff_layoutstat_end_io(&dss_info->read_stat,
requested, completed,
ktime_get(), task->tk_start);
spin_unlock(&dss_info->read_stat.lock);
@@ -843,10 +847,11 @@ nfs4_ff_layout_stat_io_start_write(struct inode *inode,
bool report;
spin_lock(&dss_info->write_stat.lock);
- report = nfs4_ff_layoutstat_start_io(dss_info, &dss_info->write_stat,
- requested, now);
+ nfs4_ff_layoutstat_start_io(&dss_info->write_stat, requested, now);
spin_unlock(&dss_info->write_stat.lock);
+ nfs4_ff_layoutstat_set_start_time(dss_info, now);
+ report = nfs4_ff_layoutstat_report_due(dss_info, now);
if (report)
pnfs_report_layoutstat(inode, nfs_io_gfp_mask());
}
@@ -865,7 +870,7 @@ nfs4_ff_layout_stat_io_end_write(struct rpc_task *task,
requested = completed = 0;
spin_lock(&dss_info->write_stat.lock);
- nfs4_ff_layoutstat_end_io(dss_info, &dss_info->write_stat,
+ nfs4_ff_layoutstat_end_io(&dss_info->write_stat,
requested, completed,
ktime_get(), task->tk_start);
spin_unlock(&dss_info->write_stat.lock);
--
2.52.0
next prev parent reply other threads:[~2026-11-06 18:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 18:20 [PATCH v3 00/12] NFSv4/flexfiles: scale layoutstats for striped layouts Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 01/12] NFSv4/flexfiles: move layoutstats accounting to a per-stripe lock Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 02/12] NFSv4/flexfiles: drop the now-unused per-mirror lock Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 03/12] NFSv4/flexfiles: cacheline align the per-stripe layoutstats Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 04/12] NFSv4/flexfiles: make dss_info->start_time write-once Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 05/12] NFSv4/flexfiles: drop the redundant atomic from the busy timer Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 06/12] NFSv4/flexfiles: pair the in-flight count with the layoutstats updates Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 07/12] NFSv4/flexfiles: derive ffil_ops_requested rather than storing it Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 08/12] NFSv4/flexfiles: give each direction its own lock and cacheline Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 09/12] NFSv4/flexfiles: drop NFS4_FF_MIRROR_STAT_AVAIL Mike Snitzer
2026-11-06 18:20 ` [PATCH v3 10/12] NFSv4/flexfiles: rotate LAYOUTSTATS reporting across a mirror's stripes Mike Snitzer
2026-11-06 18:20 ` Mike Snitzer [this message]
2026-11-06 18:21 ` [PATCH v3 12/12] NFSv4/flexfiles: share one helper for the start of a read and a write 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=20261106182105.78611-12-snitzer@kernel.org \
--to=snitzer@kernel.org \
--cc=anna@kernel.org \
--cc=jonathan.flynn@hammerspace.com \
--cc=linux-nfs@vger.kernel.org \
--cc=snitzer@hammerspace.com \
--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.