public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: NeilBrown <neilb@suse.de>
Cc: linux-nfs@vger.kernel.org, Jeff Layton <jlayton@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Trond Myklebust <trondmy@hammerspace.com>,
	snitzer@hammerspace.com
Subject: Re: [PATCH v6 06/18] nfs/nfsd: add "localio" support
Date: Tue, 25 Jun 2024 00:59:30 -0400	[thread overview]
Message-ID: <ZnpOsggaI3pC0ani@kernel.org> (raw)
In-Reply-To: <171918165963.14261.959545364150864599@noble.neil.brown.name>

On Mon, Jun 24, 2024 at 08:27:39AM +1000, NeilBrown wrote:
> On Sat, 22 Jun 2024, Mike Snitzer wrote:
> > On Fri, Jun 21, 2024 at 04:08:20PM +1000, NeilBrown wrote:
> > > 
> > > Both branches of this if() do exactly the same thing.  iov_iter_advance
> > > is a no-op if the size arg is zero.
> > 
> > iov_iter_advance doesn't look to be a no-op if the size arg is zero.
> 
> void iov_iter_advance(struct iov_iter *i, size_t size)
> {
> 	if (unlikely(i->count < size))
> 		size = i->count;
> 	if (likely(iter_is_ubuf(i)) || unlikely(iov_iter_is_xarray(i))) {
> 		i->iov_offset += size;
> 		i->count -= size;
> 	} else if (likely(iter_is_iovec(i) || iov_iter_is_kvec(i))) {
> 		/* iovec and kvec have identical layouts */
> 		iov_iter_iovec_advance(i, size);
> 	} else if (iov_iter_is_bvec(i)) {
> 		iov_iter_bvec_advance(i, size);
> 	} else if (iov_iter_is_discard(i)) {
> 		i->count -= size;
> 	}
> }
> 
> This adds "size" to offset, and subtracts "size" from count.  For iovec
> and bvec it is a slightly complicated dance to achieve this, but that is
> the net result.
> So if "size" is zero there is no change to the iov_iter.  Just some
> wasted cycles.  Do those cycles justify the extra conditional branch?  I
> don't know.  I would generally prefer simpler code which is only
> optimised with evidence.  Admittedly I don't always follow that
> preference myself and I won't hold you to it.  But I thought the review
> would be incomplete without mentioning it.

OK, thanks.

> > > > +static void
> > > > +nfs_get_vfs_attr(struct file *filp, struct nfs_fattr *fattr)
> > > > +{
> > > > +	struct kstat stat;
> > > > +
> > > > +	if (fattr != NULL && vfs_getattr(&filp->f_path, &stat,
> > > > +					 STATX_INO |
> > > > +					 STATX_ATIME |
> > > > +					 STATX_MTIME |
> > > > +					 STATX_CTIME |
> > > > +					 STATX_SIZE |
> > > > +					 STATX_BLOCKS,
> > > > +					 AT_STATX_SYNC_AS_STAT) == 0) {
> > > > +		fattr->valid = NFS_ATTR_FATTR_FILEID |
> > > > +			NFS_ATTR_FATTR_CHANGE |
> > > > +			NFS_ATTR_FATTR_SIZE |
> > > > +			NFS_ATTR_FATTR_ATIME |
> > > > +			NFS_ATTR_FATTR_MTIME |
> > > > +			NFS_ATTR_FATTR_CTIME |
> > > > +			NFS_ATTR_FATTR_SPACE_USED;
> > > > +		fattr->fileid = stat.ino;
> > > > +		fattr->size = stat.size;
> > > > +		fattr->atime = stat.atime;
> > > > +		fattr->mtime = stat.mtime;
> > > > +		fattr->ctime = stat.ctime;
> > > > +		fattr->change_attr = nfs_timespec_to_change_attr(&fattr->ctime);
> > > 
> > > This looks wrong for NFSv4.  I think we should use
> > > nfsd4_change_attribute().
> > > Maybe it isn't important, but if it isn't I'd like to see an explanation
> > > why.
> > > 
> > > > +		fattr->du.nfs3.used = stat.blocks << 9;
> > > > +	}
> > > > +}
> > 
> > Not following, this is client code so it doesn't have access to
> > nfsd4_change_attribute().
> 
> This is nfs-localio code which blurs the boundary between server and
> client...
> 
> The change_attr is used by NFS to detect if a file might have changed.
> This code is used to get the attributes after a write request.
> NFS uses a GETATTR request to the server at other times.  The
> change_attr should be consistent between the two else comparisons will
> be meaningless.
> 
> So I think that nfs_get_vfs_attr() should use the same change_attr as
> the one that would be used if the NFS GETATTR request were made.
> For NFSv3, that is nfs_timespec_to_change_attr() as you have.
> For NFSv4 it is something different.
> 
> I think that having inconsistent change_attrs could cause NFS to flush
> its page cache unnecessarily.  As it can read directly from the
> server-side where is likely is cached, that might not be a problem.  If
> that reasoning does apply it should be explained.
> 
> However there is talk of exporting the "i_version" number to userspace
> through xattr.  For NFS that is essentially the change_attr. If we did
> that we would really want to keep the number consistent.
> 
> We could easily move nfsd4_change_attribute() into nfs_common or even
> make it an inline in some common include file.  It doesn't use any nfsd
> internals.

OK, makes sense, thanks for clarifying.  I'll fix it for v8.

Mike

  reply	other threads:[~2024-06-25  4:59 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 20:40 [PATCH v6 00/18] nfs/nfsd: add support for localio Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 01/18] nfs: pass nfs_client to nfs_initiate_pgio Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 02/18] nfs: pass descriptor thru nfs_initiate_pgio path Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 03/18] nfs: pass struct file to nfs_init_pgio and nfs_init_commit Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 04/18] sunrpc: add rpcauth_map_to_svc_cred_local Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 05/18] nfs_common: add NFS LOCALIO auxiliary protocol enablement Mike Snitzer
2024-06-21  4:43   ` Jeff Johnson
2024-06-19 20:40 ` [PATCH v6 06/18] nfs/nfsd: add "localio" support Mike Snitzer
2024-06-21  6:08   ` NeilBrown
2024-06-21 23:28     ` Mike Snitzer
2024-06-23 22:27       ` NeilBrown
2024-06-25  4:59         ` Mike Snitzer [this message]
2024-06-19 20:40 ` [PATCH v6 07/18] nfsd/localio: manage netns reference in nfsd_open_local_fh Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 08/18] NFS: Enable localio for non-pNFS I/O Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 09/18] pnfs/flexfiles: Enable localio for flexfiles I/O Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 10/18] nfs/localio: use dedicated workqueues for filesystem read and write Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 11/18] nfs: implement v3 and v4 client support for NFS_LOCALIO_PROGRAM Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 12/18] nfsd: implement v3 and v4 server " Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 13/18] nfs/nfsd: consolidate {encode,decode}_opaque_fixed in nfs_xdr.h Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 14/18] nfsd: prepare to use SRCU to dereference nn->nfsd_serv Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 15/18] nfsd: " Mike Snitzer
2024-06-21  6:35   ` NeilBrown
2024-06-21 23:58     ` Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 16/18] nfsd/localio: use SRCU to dereference nn->nfsd_serv in nfsd_open_local_fh Mike Snitzer
2024-06-19 20:40 ` [PATCH v6 17/18] nfs: add Documentation/filesystems/nfs/localio.rst Mike Snitzer
2024-06-20 13:52   ` Chuck Lever
2024-06-20 14:33     ` Mike Snitzer
2024-06-20 14:45       ` Chuck Lever
2024-06-20 22:12     ` NeilBrown
2024-06-20 22:35       ` Mike Snitzer
2024-06-20 23:28         ` Chuck Lever
2024-06-20 23:42           ` NeilBrown
2024-06-21  0:30             ` Mike Snitzer
2024-06-21  0:38               ` Mike Snitzer
2024-06-21  0:28           ` Mike Snitzer
2024-06-21  2:18             ` Chuck Lever III
2024-06-19 20:40 ` [PATCH v6 18/18] nfs/nfsd: add Kconfig options to allow localio to be enabled Mike Snitzer
2024-06-20  5:04 ` [PATCH v6 00/18] nfs/nfsd: add support for localio 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=ZnpOsggaI3pC0ani@kernel.org \
    --to=snitzer@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=snitzer@hammerspace.com \
    --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