mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v2] NFS: don't wait for writeback on close() with a write delegation
Date: Fri, 20 Nov 2026 13:51:17 -0800	[thread overview]
Message-ID: <20261120-nfs-space-limit-v2-1-7a5c0f9280ad@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.

That flush is the wrong tool:

- CTO: no other client can open the file until the delegation is
  recalled. The recall doesn't flush before DELEGRETURN, though: since
  commit 4816fdadab9f ("NFSv4: Don't use synchronous delegation recall
  in exception handling") CB_RECALL doesn't even start writeback, and
  the state manager can't wait for it. WRITEs still in flight after
  close() can thus race with another client's OPEN. That gap already
  exists for servers that send a nonzero space_limit, and needs fixing
  in the recall path, not with a flush on every close().
- 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. 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.

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>
---
Only a small change from the RFC, to incorporate Trond's suggestion to
switch to filemap_flush(). Also Cc'ing Sagi since he raised this issue
with Chuck and I a couple of years ago.
---
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   |  9 +++++----
 3 files changed, 5 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..6ff82e7edbf8 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -122,11 +122,12 @@ 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))
-		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-20 21:51 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=20261120-nfs-space-limit-v2-1-7a5c0f9280ad@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®