From: Mike Snitzer <snitzer@kernel.org>
To: Trond Myklebust <trond.myklebust@hammerspace.com>,
Anna Schumaker <anna.schumaker@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v8 8/9] nfs/direct: add tracepoints for misaligned DIO READ and WRITE support
Date: Fri, 15 Aug 2025 19:30:02 -0400 [thread overview]
Message-ID: <20250815233003.55071-9-snitzer@kernel.org> (raw)
In-Reply-To: <20250815233003.55071-1-snitzer@kernel.org>
Add nfs_analyze_dio_class and use it to create nfs_analyze_read_dio
and nfs_analyze_write_dio trace events.
These trace events show how the NFS client splits a given misaligned
IO into a mix of misaligned head and/or tail extents and a DIO-aligned
middle extent. The misaligned head and/or tail extents are issued
using buffered IO and the DIO-aligned middle is issued using O_DIRECT.
This combination of trace events is useful for LOCALIO DIO READs:
echo 1 > /sys/kernel/tracing/events/nfs/nfs_analyze_read_dio/enable
echo 1 > /sys/kernel/tracing/events/nfs/nfs_initiate_read/enable
echo 1 > /sys/kernel/tracing/events/nfs/nfs_readpage_done/enable
echo 1 > /sys/kernel/tracing/events/xfs/xfs_file_direct_read/enable
This combination of trace events is useful for LOCALIO DIO WRITEs:
echo 1 > /sys/kernel/tracing/events/nfs/nfs_analyze_write_dio/enable
echo 1 > /sys/kernel/tracing/events/nfs/nfs_initiate_write/enable
echo 1 > /sys/kernel/tracing/events/nfs/nfs_writeback_done/enable
echo 1 > /sys/kernel/tracing/events/xfs/xfs_file_direct_write/enable
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
fs/nfs/direct.c | 10 +++++---
fs/nfs/nfstrace.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 3803289a94793..012f5bfa15c21 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -441,7 +441,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
* IO to a DIO-aligned middle and misaligned head and/or tail.
*/
static bool nfs_analyze_dio(loff_t offset, ssize_t len,
- struct nfs_direct_req *dreq)
+ struct nfs_direct_req *dreq, int rw)
{
#if IS_ENABLED(CONFIG_NFS_LOCALIO)
/* Hardcoded to PAGE_SIZE (since don't have LOCALIO nfsd_file's
@@ -471,6 +471,10 @@ static bool nfs_analyze_dio(loff_t offset, ssize_t len,
dreq->end_offset = middle_end;
dreq->end_len = orig_end - middle_end;
+ if (rw == READ)
+ trace_nfs_analyze_read_dio(offset, len, dreq);
+ else
+ trace_nfs_analyze_write_dio(offset, len, dreq);
return true;
#else
return false;
@@ -524,7 +528,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter,
goto out;
dreq->inode = inode;
- if (swap || !nfs_analyze_dio(iocb->ki_pos, count, dreq)) {
+ if (swap || !nfs_analyze_dio(iocb->ki_pos, count, dreq, READ)) {
dreq->max_count = count;
dreq->io_start = iocb->ki_pos;
}
@@ -1119,7 +1123,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter,
goto out;
dreq->inode = inode;
- if (swap || !nfs_analyze_dio(pos, count, dreq)) {
+ if (swap || !nfs_analyze_dio(pos, count, dreq, WRITE)) {
dreq->max_count = count;
dreq->io_start = pos;
}
diff --git a/fs/nfs/nfstrace.h b/fs/nfs/nfstrace.h
index 4ec66d5e9cc6c..ec4c0f073361a 100644
--- a/fs/nfs/nfstrace.h
+++ b/fs/nfs/nfstrace.h
@@ -1598,6 +1598,64 @@ DEFINE_NFS_DIRECT_REQ_EVENT(nfs_direct_write_completion);
DEFINE_NFS_DIRECT_REQ_EVENT(nfs_direct_write_schedule_iovec);
DEFINE_NFS_DIRECT_REQ_EVENT(nfs_direct_write_reschedule_io);
+DECLARE_EVENT_CLASS(nfs_analyze_dio_class,
+ TP_PROTO(
+ loff_t offset,
+ ssize_t count,
+ const struct nfs_direct_req *dreq
+ ),
+ TP_ARGS(offset, count, dreq),
+ TP_STRUCT__entry(
+ __field(dev_t, dev)
+ __field(u64, fileid)
+ __field(u32, fhandle)
+ __field(loff_t, offset)
+ __field(ssize_t, count)
+ __field(loff_t, start)
+ __field(ssize_t, start_len)
+ __field(loff_t, middle)
+ __field(ssize_t, middle_len)
+ __field(loff_t, end)
+ __field(ssize_t, end_len)
+ ),
+ TP_fast_assign(
+ const struct inode *inode = dreq->inode;
+ const struct nfs_inode *nfsi = NFS_I(inode);
+ const struct nfs_fh *fh = &nfsi->fh;
+
+ __entry->dev = inode->i_sb->s_dev;
+ __entry->fileid = nfsi->fileid;
+ __entry->fhandle = nfs_fhandle_hash(fh);
+ __entry->offset = offset;
+ __entry->count = count;
+ __entry->start = dreq->io_start;
+ __entry->start_len = dreq->start_len;
+ __entry->middle = dreq->middle_offset;
+ __entry->middle_len = dreq->middle_len;
+ __entry->end = dreq->end_offset;
+ __entry->end_len = dreq->end_len;
+ ),
+ TP_printk("fileid=%02x:%02x:%llu fhandle=0x%08x "
+ "offset=%lld count=%zd "
+ "start=%llu+%lu middle=%llu+%lu end=%llu+%lu",
+ MAJOR(__entry->dev), MINOR(__entry->dev),
+ (unsigned long long)__entry->fileid,
+ __entry->fhandle, __entry->offset, __entry->count,
+ __entry->start, __entry->start_len,
+ __entry->middle, __entry->middle_len,
+ __entry->end, __entry->end_len)
+)
+
+#define DEFINE_NFS_ANALYZE_DIO_EVENT(name) \
+DEFINE_EVENT(nfs_analyze_dio_class, nfs_analyze_##name##_dio, \
+ TP_PROTO(loff_t offset, \
+ ssize_t count, \
+ const struct nfs_direct_req *dreq), \
+ TP_ARGS(offset, count, dreq))
+
+DEFINE_NFS_ANALYZE_DIO_EVENT(read);
+DEFINE_NFS_ANALYZE_DIO_EVENT(write);
+
TRACE_EVENT(nfs_fh_to_dentry,
TP_PROTO(
const struct super_block *sb,
--
2.44.0
next prev parent reply other threads:[~2025-08-15 23:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 23:29 [PATCH v8 0/9] NFS DIRECT: align misaligned DIO for LOCALIO Mike Snitzer
2025-08-15 23:29 ` [PATCH v8 1/9] nfs/localio: avoid bouncing LOCALIO if nfs_client_is_local() Mike Snitzer
2025-08-15 23:29 ` [PATCH v8 2/9] nfs/localio: make trace_nfs_local_open_fh more useful Mike Snitzer
2025-08-15 23:29 ` [PATCH v8 3/9] nfs/localio: avoid issuing misaligned IO using O_DIRECT Mike Snitzer
2025-08-15 23:29 ` [PATCH v8 4/9] nfs/localio: refactor iocb and iov_iter_bvec initialization Mike Snitzer
2025-08-15 23:29 ` [PATCH v8 5/9] nfs/localio: refactor iocb initialization Mike Snitzer
2025-08-15 23:30 ` [PATCH v8 6/9] nfs/direct: add misaligned READ handling Mike Snitzer
2025-08-15 23:30 ` [PATCH v8 7/9] nfs/direct: add misaligned WRITE handling Mike Snitzer
2025-08-15 23:30 ` Mike Snitzer [this message]
2025-08-15 23:30 ` [PATCH v8 9/9] NFS: add basic STATX_DIOALIGN and STATX_DIO_READ_ALIGN support 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=20250815233003.55071-9-snitzer@kernel.org \
--to=snitzer@kernel.org \
--cc=anna.schumaker@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@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).