From: Jeff Layton <jlayton@kernel.org>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: Chuck Lever <cel@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v3] NFS: don't wait for writeback on close() with a write delegation
Date: Mon, 23 Nov 2026 13:53:04 -0500 [thread overview]
Message-ID: <20261123-nfs-space-limit-v3-1-993945e1a526@kernel.org> (raw)
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.
Dropping that flush breaks close-to-open consistency. The NFS client
returns a write delegation without waiting for writeback. Since commit
4816fdadab9f ("NFSv4: Don't use synchronous delegation recall in
exception handling"), CB_RECALL does not even start writeback.
This is a conscious decision that it's better to break CTO than block
the DELEGRETURN.
Beyond CTO, the flush buys little:
- Error reporting is 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. While we're in here, change to using filemap_flush() so the
writeback is (mostly) non-blocking.
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.
For now, the pagemod_limit is still decoded but unused.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
One more minor change. The last version's comment was misleading. This
version should make it clear that we're aware of the potential CTO race
but consider that less harmful than blocking the DELEGRETURN.
---
Changes in v3:
- Change comment and changelog to better describe the CTO effects.
- Link to v2: https://lore.kernel.org/r/20261120-nfs-space-limit-v2-1-7a5c0f9280ad@kernel.org
Changes in v2:
- Switch to using filemap_flush() instead of filemap_fdatawrite()
- Link to v1: https://lore.kernel.org/r/20261116-nfs-space-limit-v1-1-fcc1335169a7@kernel.org
---
fs/nfs/delegation.c | 25 -------------------------
fs/nfs/delegation.h | 1 -
fs/nfs/nfs4file.c | 11 +++++++----
3 files changed, 7 insertions(+), 30 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..74071c63a786 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -122,11 +122,14 @@ 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.
+ * Under a write delegation, start the i/o without waiting for it.
+ * The NFS client also sends DELEGRETURN without waiting for
+ * writeback, so another client can open the file and read data
+ * older than this close(). Losing close-to-open consistency is
+ * preferred over holding the delegation until the WRITEs finish.
*/
- if (!nfs4_delegation_flush_on_close(inode))
- return filemap_fdatawrite(file->f_mapping);
+ if (nfs_have_write_delegation(inode))
+ return filemap_flush(file->f_mapping);
/* Flush writes to the server and return any errors */
since = filemap_sample_wb_err(file->f_mapping);
---
base-commit: 9d66f26fefacebfeed15de31c1123451a17ff119
change-id: 20261113-nfs-space-limit-025199334e52
Best regards,
--
Jeff Layton <jlayton@kernel.org>
reply other threads:[~2026-11-23 18:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261123-nfs-space-limit-v3-1-993945e1a526@kernel.org \
--to=jlayton@kernel.org \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=sagi@grimberg.me \
--cc=trondmy@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®