From: Trond Myklebust <trondmy@kernel.org>
To: Jeff Layton <jlayton@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: Chuck Lever <cel@kernel.org>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] NFS: don't wait for writeback on close() with a write delegation
Date: Mon, 23 Nov 2026 16:23:00 -0500 [thread overview]
Message-ID: <21053572ab2e8743fe4ba47464d21e719ec445b1.camel@kernel.org> (raw)
In-Reply-To: <185ae981c8250143bc519151d3d4f937a76b9a92.camel@kernel.org>
On Mon, 2026-11-23 at 16:18 -0500, Trond Myklebust wrote:
> On Mon, 2026-11-23 at 14:43 -0500, Jeff Layton wrote:
> > On Fri, 2026-11-20 at 10:04 -0800, Trond Myklebust wrote:
> > > On Mon, 2026-11-16 at 15:55 -0500, Jeff Layton wrote:
> > > > Commit 5445b1fbd123 ("NFSv4: Respect the server imposed limit
> > > > on
> > > > how
> > > > many changes we may cache") made close() write back, COMMIT and
> > > > wait
> > > > whenever outstanding requests exceed the write delegation's
> > > > space_limit. Servers that send a limit of 0, knfsd included,
> > > > therefore
> > > > get no close() benefit from write delegations, which knfsd now
> > > > grants
> > > > even on write-only opens.
> > > >
> > > > That flush buys nothing:
> > > >
> > > > - CTO: no other client can open the file until the delegation
> > > > is
> > > > recalled, and the recall writes back our dirty data first.
> > > > - Error reporting is all that's left, and it's pointless.
> > > > close()
> > > > is
> > > > not required to flush, and most filesystems don't, so
> > > > checking
> > > > for
> > > > writeback errors there is unreliable at best: the failing
> > > > writeback
> > > > may not have happened yet. Applications that care must
> > > > fsync(),
> > > > which this doesn't change; errors are still recorded in the
> > > > mapping
> > > > and reported there.
> > > > - RFC 8881 says only that the client "should" abide by
> > > > space_limit;
> > > > exceeding it leaves the server's behavior undefined, and
> > > > knfsd
> > > > just
> > > > returns NFS4ERR_NOSPC/NFS4ERR_DQUOT on WRITE or COMMIT.
> > > >
> > > > Go back to just starting writeback on close() whenever we hold
> > > > a
> > > > write
> > > > delegation. In testing against a knfsd patched to send a
> > > > nonzero
> > > > space_limit, single-threaded create/write/close went from ~92
> > > > to
> > > > ~1,500 files/s.
> > > >
> > > > User-visible change: ENOSPC/EDQUOT for data written just before
> > > > close()
> > > > now shows up only via fsync(), not close().
> > > >
> > > > For now, the pagemod_limit is still decoded but unused.
> > > >
> > > > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > > > ---
> > > > I started looking at wiring up space_limit for nfsd's write
> > > > delegations,
> > > > but afrer looking at how the client uses it, I think we're best
> > > > off
> > > > just
> > > > not bothering to respect it at all. Thoughts?
> > > > ---
> > > > fs/nfs/delegation.c | 25 -------------------------
> > > > fs/nfs/delegation.h | 1 -
> > > > fs/nfs/nfs4file.c | 7 ++++---
> > > > 3 files changed, 4 insertions(+), 29 deletions(-)
> > > >
> > > > diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
> > > > index ad774316f716..3a141d5ee0bd 100644
> > > > --- a/fs/nfs/delegation.c
> > > > +++ b/fs/nfs/delegation.c
> > > > @@ -1587,31 +1587,6 @@ bool nfs4_copy_delegation_stateid(struct
> > > > inode
> > > > *inode, fmode_t flags,
> > > > return ret;
> > > > }
> > > >
> > > > -/**
> > > > - * nfs4_delegation_flush_on_close - Check if we must flush
> > > > file
> > > > on
> > > > close
> > > > - * @inode: inode to check
> > > > - *
> > > > - * This function checks the number of outstanding writes to
> > > > the
> > > > file
> > > > - * against the delegation 'space_limit' field to see if
> > > > - * the spec requires us to flush the file on close.
> > > > - */
> > > > -bool nfs4_delegation_flush_on_close(const struct inode *inode)
> > > > -{
> > > > - struct nfs_inode *nfsi = NFS_I(inode);
> > > > - struct nfs_delegation *delegation;
> > > > - bool ret = true;
> > > > -
> > > > - rcu_read_lock();
> > > > - delegation = rcu_dereference(nfsi->delegation);
> > > > - if (delegation == NULL || !(delegation->type &
> > > > FMODE_WRITE))
> > > > - goto out;
> > > > - if (atomic_long_read(&nfsi->nrequests) < delegation-
> > > > > pagemod_limit)
> > > > - ret = false;
> > > > -out:
> > > > - rcu_read_unlock();
> > > > - return ret;
> > > > -}
> > > > -
> > > > int nfs4_delegation_hash_alloc(struct nfs_server *server)
> > > > {
> > > > int delegation_buckets, i;
> > > > diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
> > > > index fba4699952b8..75f0edde65ea 100644
> > > > --- a/fs/nfs/delegation.h
> > > > +++ b/fs/nfs/delegation.h
> > > > @@ -83,7 +83,6 @@ void nfs_put_delegation(struct nfs_delegation
> > > > *delegation);
> > > > void nfs_mark_delegation_referenced(struct nfs_delegation
> > > > *delegation);
> > > > int nfs4_have_delegation(struct inode *inode, fmode_t type,
> > > > int
> > > > flags);
> > > > int nfs4_check_delegation(struct inode *inode, fmode_t type);
> > > > -bool nfs4_delegation_flush_on_close(const struct inode
> > > > *inode);
> > > > void nfs_inode_find_delegation_state_and_recover(struct inode
> > > > *inode,
> > > > const nfs4_stateid *stateid);
> > > > void nfs4_inode_make_writeable(struct inode *inode);
> > > > diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
> > > > index 9a434f5dda8d..04f4d8967e5b 100644
> > > > --- a/fs/nfs/nfs4file.c
> > > > +++ b/fs/nfs/nfs4file.c
> > > > @@ -122,10 +122,11 @@ nfs4_file_flush(struct file *file,
> > > > fl_owner_t
> > > > id)
> > > > return 0;
> > > >
> > > > /*
> > > > - * If we're holding a write delegation, then check if
> > > > we're
> > > > required
> > > > - * to flush the i/o on close. If not, then just start
> > > > the
> > > > i/o now.
> > > > + * A write delegation already provides close-to-open
> > > > consistency:
> > > > + * no other client can open the file until it is
> > > > recalled,
> > > > and the
> > > > + * recall writes back our dirty data. Just start the
> > > > i/o.
> > > > */
> > > > - if (!nfs4_delegation_flush_on_close(inode))
> > > > + if (nfs_have_write_delegation(inode))
> > > > return filemap_fdatawrite(file->f_mapping);
> > > >
> > > > /* Flush writes to the server and return any errors */
> > > >
> > > > ---
> > > > base-commit: 9d66f26fefacebfeed15de31c1123451a17ff119
> > > > change-id: 20261113-nfs-space-limit-025199334e52
> > > >
> > > > Best regards,
> > >
> > > Maybe we can call filemap_flush() in order to kick off non-
> > > blocking
> > > writes in this situation?
> >
> > This sounds like a good idea, but agentic review came up with this,
> > and
> > it seems to be valid, AFAICT:
> >
> > ------------8<-------------
> > - filemap_flush() → WB_SYNC_NONE: it skips folios already in
> > flight,
> > but it can block on server-wide congestion caused by other files.
> >
> > - filemap_fdatawrite() → WB_SYNC_ALL: it may wait on this file's
> > own
> > rewritten in-flight folios, which a create/write/close workload
> > rarely
> > hits. It never waits on congestion, and a small file gets a
> > FILE_SYNC
> > WRITE with no COMMIT.
> > ------------8<-------------
> >
> > I think we may want to switch this code back to using
> > filemap_fdatawrite()
> > like it did before. Thoughts?
>
> Urgh...
>
> OK, I've got to stop and ask why commit 2f1f31042ef0 ("nfs: Block on
> write congestion") only applies congestion control to the
> WB_SYNC_NONE
> case?
>
> Also, why does it not re-check for congestion in the loops further
> down
> in nfs_writepages where it's adding fuel to the congestion fire?
>
> Put differently: If we're going to apply congestion control, then why
> are we not doing so consistently here?
Another note: this is almost certainly completely borked for the pNFS
case, since nfss->write_congestion_wait is global to the metadata
server. In the pNFS case, you can have lots of data servers that have
completely independent congestion characteristics.
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com
next prev parent reply other threads:[~2026-11-23 21:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 20:55 [PATCH RFC] NFS: don't wait for writeback on close() with a write delegation Jeff Layton
2026-11-20 18:04 ` Trond Myklebust
2026-11-23 19:43 ` Jeff Layton
2026-11-23 21:18 ` Trond Myklebust
2026-11-23 21:23 ` Trond Myklebust [this message]
2026-11-23 22:10 ` Jeff Layton
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=21053572ab2e8743fe4ba47464d21e719ec445b1.camel@kernel.org \
--to=trondmy@kernel.org \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.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.