From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neilb@ownmail.net>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
Mike Snitzer <snitzer@kernel.org>, Christoph Hellwig <hch@lst.de>
Cc: <linux-nfs@vger.kernel.org>, Chuck Lever <chuck.lever@oracle.com>
Subject: [RFC PATCH v2] NFSD: Add asynchronous write throttling support for UNSTABLE WRITEs
Date: Fri, 9 Jan 2026 16:56:13 -0500 [thread overview]
Message-ID: <20260109215613.25250-1-cel@kernel.org> (raw)
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
next reply other threads:[~2026-01-09 21:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 21:56 Chuck Lever [this message]
2026-01-10 5:30 ` [RFC PATCH v2] NFSD: Add asynchronous write throttling support for UNSTABLE WRITEs 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
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=20260109215613.25250-1-cel@kernel.org \
--to=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=hch@lst.de \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@ownmail.net \
--cc=okorniev@redhat.com \
--cc=snitzer@kernel.org \
--cc=tom@talpey.com \
/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