public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	linux-nfs@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>,
	Mike Snitzer <snitzer@kernel.org>
Subject: Re: [PATCH v5 4/6] NFSD: Implement NFSD_IO_DIRECT for NFS READ
Date: Fri, 3 Oct 2025 11:06:49 -0400	[thread overview]
Message-ID: <96f1a103-6b8c-4281-8450-68ab14219518@kernel.org> (raw)
In-Reply-To: <aN9451-HZqvPBrlp@infradead.org>

On 10/3/25 3:19 AM, Christoph Hellwig wrote:
>> +/*
>> + * The byte range of the client's READ request is expanded on both
>> + * ends until it meets the underlying file system's direct I/O
>> + * alignment requirements. After the internal read is complete, the
>> + * byte range of the NFS READ payload is reduced to the byte range
>> + * that was originally requested.
>> + *
>> + * Note that a direct read can be done only when the xdr_buf
>> + * containing the NFS READ reply does not already have contents in
>> + * its .pages array. This is due to potentially restrictive
>> + * alignment requirements on the read buffer. When .page_len and
>> + * @base are zero, the .pages array is guaranteed to be page-
>> + * aligned.
>> + */
> 
> Any reason you are not using the full 80 characters available for the
> comment?

Yep: I find comment blocks that fill the whole line more difficult
to read because my eyes are gray and bent. :-)


>> +	v = 0;
>> +	total = dio_end - dio_start;
>> +	while (total && v < rqstp->rq_maxpages &&
>> +	       rqstp->rq_next_page < rqstp->rq_page_end) {
>> +		len = min_t(size_t, total, PAGE_SIZE);
>> +		bvec_set_page(&rqstp->rq_bvec[v], *rqstp->rq_next_page,
>> +			      len, 0);
>> +
>> +		total -= len;
>> +		++rqstp->rq_next_page;
>> +		++v;
> 
> I find this loop style very hard to follow.  Why not do something like:
> 
> Why not something like:
> 
> 	for (v = 0; v < rqstp->rq_maxpages; v++) {
> 		size_t len = min_t(size_t, total, PAGE_SIZE);
> 
> 		bvec_set_page(&rqstp->rq_bvec[v], *rqstp->rq_next_page, len, 0);
> 		rqstp->rq_next_page++;
> 		total -= len;
> 		if (!total)
> 			break;
> 	}
> 
> ?

We copied this loop from nfsd_iter_read(), where we just reworked it
because there are several conditions that need to terminate the loop:

- There are no more bytes to process
- There are no more pages available in rq_pages
- There are no more entries in rq_bvec

Your proposed rewrite drops the array bounds checking that we just
added, IIUC. Neil doesn't like adding termination conditions at the end
of a loop.

I'm open to utilizing for() instead of while() but I didn't find that
writing it as for() improved legibility.

(Yes this is duplicate code, which I'm OK with until we have optimized
direct reads properly and have nailed down exactly when NFSD will employ
them).


>> +	case NFSD_IO_DIRECT:
>> +		/* When dio_read_offset_align is zero, dio is not supported */
>> +		if (nf->nf_dio_read_offset_align &&
>> +		    !rqstp->rq_res.page_len)
> 
> Nit: the entire if clause fits into a single line.
> 

I'll fix that; an additional check was removed during the last
revision, and that shortened the second line.


-- 
Chuck Lever

  reply	other threads:[~2025-10-03 15:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-29 15:56 [PATCH v5 0/6] NFSD direct I/O read Chuck Lever
2025-09-29 15:56 ` [PATCH v5 1/6] NFSD: filecache: add STATX_DIOALIGN and STATX_DIO_READ_ALIGN support Chuck Lever
2025-10-03  7:09   ` Christoph Hellwig
2025-09-29 15:56 ` [PATCH v5 2/6] NFSD: pass nfsd_file to nfsd_iter_read() Chuck Lever
2025-10-03  7:09   ` Christoph Hellwig
2025-09-29 15:56 ` [PATCH v5 3/6] NFSD: Relocate the xdr_reserve_space_vec() call site Chuck Lever
2025-09-29 15:56 ` [PATCH v5 4/6] NFSD: Implement NFSD_IO_DIRECT for NFS READ Chuck Lever
2025-10-03  7:19   ` Christoph Hellwig
2025-10-03 15:06     ` Chuck Lever [this message]
2025-09-29 15:56 ` [PATCH v5 5/6] NFSD: Prevent a NULL pointer dereference in fh_getattr() Chuck Lever
2025-09-29 16:13   ` Jeff Layton
2025-09-29 17:39   ` Mike Snitzer
2025-10-03  7:11   ` Christoph Hellwig
2025-10-03 14:18     ` Chuck Lever
2025-09-29 15:56 ` [PATCH v5 6/6] NFSD: Ignore vfs_getattr() failure in nfsd_file_get_dio_attrs() Chuck Lever
2025-09-29 16:51   ` Jeff Layton
2025-09-29 17:39   ` Mike Snitzer
2025-10-03  7:13   ` Christoph Hellwig
2025-10-03 14:23     ` Chuck Lever

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=96f1a103-6b8c-4281-8450-68ab14219518@kernel.org \
    --to=cel@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=dai.ngo@oracle.com \
    --cc=hch@infradead.org \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=snitzer@kernel.org \
    --cc=tom@talpey.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