Re: [PATCH RFC] NFS: don't wait for writeback on close() with a write delegation
From: Jeff Layton
Date: Mon Nov 23 2026 - 14:44:09 EST
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@xxxxxxxxxx>
> > ---
> > 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?
--
Jeff Layton <jlayton@xxxxxxxxxx>