public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2] NFSD: Add asynchronous write throttling support for UNSTABLE WRITEs
@ 2026-01-09 21:56 Chuck Lever
  2026-01-10  5:30 ` NeilBrown
  0 siblings, 1 reply; 7+ messages in thread
From: Chuck Lever @ 2026-01-09 21:56 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	Mike Snitzer, Christoph Hellwig
  Cc: linux-nfs, Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

When memory pressure occurs during buffered writes, the traditional
approach is for balance_dirty_pages() to put the writing thread to
sleep until dirty pages are flushed. For NFSD, this means server
threads block waiting for I/O, reducing overall server throughput.

Add asynchronous write throttling for UNSTABLE writes using the
BDP_ASYNC flag to balance_dirty_pages_ratelimited_flags(). NFSD
checks memory pressure before attempting a buffered write. If the
call returns -EAGAIN (indicating memory exhaustion), NFSD returns
NFS4ERR_DELAY (or NFSERR_JUKEBOX for NFSv3) to the client instead
of blocking.

Clients then wait and retry, rather than tying up server memory with
a cached uncommitted write payload.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/vfs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Compile tested only.

Changes since RFC v1:
- Remove the experimental debugfs setting
- Enforce throttling specifically only for UNSTABLE WRITEs


diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 168d3ccc8155..c4550105234e 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1458,6 +1458,30 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		}
 	}
 
+	/*
+	 * Throttle buffered writes under memory pressure. When dirty
+	 * page limits are exceeded, BDP_ASYNC causes -EAGAIN to be
+	 * returned rather than blocking the thread. This -EAGAIN
+	 * maps to nfserr_jukebox, signaling the client to back off
+	 * and retry rather than tying up a server thread during
+	 * writeback.
+	 *
+	 * NFSv2 writes commit to stable storage before reply; no
+	 * dirty pages accumulate, so throttling is unnecessary.
+	 * FILE_SYNC and DATA_SYNC writes flush immediately and do
+	 * not leave uncommitted dirty pages behind.
+	 * Direct I/O and DONTCACHE bypass the page cache entirely.
+	 */
+	if (rqstp->rq_vers > 2 &&
+	    stable == NFS_UNSTABLE &&
+	    nfsd_io_cache_write == NFSD_IO_BUFFERED) {
+		host_err =
+			balance_dirty_pages_ratelimited_flags(file->f_mapping,
+							      BDP_ASYNC);
+		if (host_err == -EAGAIN)
+			goto out_nfserr;
+	}
+
 	nvecs = xdr_buf_to_bvec(rqstp->rq_bvec, rqstp->rq_maxpages, payload);
 
 	since = READ_ONCE(file->f_wb_err);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-12 14:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-09 21:56 [RFC PATCH v2] NFSD: Add asynchronous write throttling support for UNSTABLE WRITEs Chuck Lever
2026-01-10  5:30 ` NeilBrown
2026-01-10 20:28   ` Chuck Lever
2026-01-10 21:38     ` NeilBrown
2026-01-10 23:33       ` Chuck Lever
2026-01-12  4:15         ` NeilBrown
2026-01-12 14:38           ` Chuck Lever

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox