Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390090; b=LDvpSZOc5iYj4sm7/yWadvX1dnsKirKR4QDZpvO6BRU4iM5Rx2l95zdP5g3jlLa4EN10 V8VXN600QluVyB6w9/jW/BTwL6aBFyk0HEV32P8P1f0FyPgi5KgPs1Lu4UE6bOVL1PjxS 5IuiOQ9M9tLsixxshrSXRKSDBSshazUnqXGZIbmKaDuo9I1QEc1tzaqALRwSw0SamWCa3 7bgkVCp1xC2GQ912VNYkR9AL18HiLm54K1h/B80e20RTS2HnIUaEK+VkL2A73fq8QOsgX ye9Esl+XdOlLuWGyxDmPBqwDTE/Mu7SmaFSqnJCXOBFLngUKSW9X2GD1r58qJxemtRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390090; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=IbUC3kYKshOB6HVJwA2XRNRjbFudtl7nQCwKFeBeTNo=; b=oyqcs79dD5wTgg4dchg211TLJFDhIk+YxZDaehDHPKnREWcM4A7MsJMr1rBF+CGutkko QAze4/uEt19CuvceoUWnn+jJzk1ZHb6MKZCuGQg4E9XbI+RebfJCFSS3aulsq1BziAyiQ UYVQG5mS7dcbyNBV+UDkyGDESoUxiHLVFYHFwHtRuPdEPXmSfTGsPgXxzxUeg2JFTVvpi mfAixhgJCE95LeqBUfyEMgy3M+LbdPxFEkYGMaJU+niQOmiqwoJjSKdmk7pGaDzqHIGwP dKI4iP4nL4WNAXBJ5O2p+MdUbglMdlE3Dr6nVlIONvLRA9hGNyGhjff/0o1fEFXWsdQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lfy+7qT3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDE9B606A322; Fri, 4 Dec 2026 13:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lfy+7qT3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F321F00931; Fri, 4 Dec 2026 13:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796390089; bh=IbUC3kYKshOB6HVJwA2XRNRjbFudtl7nQCwKFeBeTNo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=lfy+7qT36D0D/5AwSnEUa9lHXwGebMpD4LOo35lCnUtql3LB+vEy3YqNAzc08WdIK 0miedKLIbqmIdapwv54DgDM4HE+7wRqsMaWpRG8iRsvShMA3sf50hvJoG0kCUtXrN2 3IXUbwkXl7Kki7iviBlvFTWdOUd+bo8Uo7GT3fjau/3rXM0qEGCIu1J+COUJZQfnX0 LSLPFZlyKS4/uZBajRvgoPhZ3osP5Lgw0BU03Jw0cL2jbgd63adxsdilF0Al02VwVo j4LlKYBMCHwYz6YhYmUM3iXSEY7TP38c5BJgli0t8u+U0gOd5UVbL/kzRcKZ/RR6IJ 4k9DenXbySm3g== From: Jeff Layton Date: Fri, 04 Dec 2026 08:14:16 -0500 Subject: [PATCH 2/6] NFS: move write congestion state to struct nfs_client X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-nfs-write-congestion-v1-2-f06cdcd58192@kernel.org> References: <20261204-nfs-write-congestion-v1-0-f06cdcd58192@kernel.org> In-Reply-To: <20261204-nfs-write-congestion-v1-0-f06cdcd58192@kernel.org> To: Trond Myklebust , Anna Schumaker , Benjamin Coddington , Jonathan Corbet , Shuah Khan , Randy Dunlap Cc: Jan Kara , Jeff Layton , linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7231; i=jlayton@kernel.org; h=from:subject:message-id; bh=9yqJvwQRx/AbazCKfz+7+wIzpFXdkmqbCrOQw4qrtFM=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBrErzERrCKGnSUmQ4hLsjlJL5WixkZaxihRSDNi rcPlRl0N8CJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaxK8xAAKCRAADmhBGVaC FWDBD/4ltu/9LW47Nx9Ocd4hD428onaZajq+aO65i7wnBF0SgEFqtwdmPLgvJaTohRIlvmG2+XA CqX29l2JgAu1J829wt72PNlktqKLXdnGoBfylMoIdI4kssXLwMykCZAA720EjvJXYlGl4UcTI1n QpcB3TkqEYbzYB0DP7UOArMKG//CF0+BhbAQsv6zNmtc0dvUPWv2+qlOxoV3Ichq1L/Jdtsi9aq 6CK5nkAXOTCBZkbVvwxxDHlG+Amk64p+kQ8O6UCAHq0RV8Z1UfVDoD3nqxPitzWu52+MCbykxl+ jLUhKAuiGSC5xfVowK5L7P9eN9ref+JxnSI+5z1Bco3Jib+fD1Y06NzM3i7I7gu7KEHZIpYbrDt Z0LirP49+7kt/5qhirenrubm+dG0Eb5pQT3+EFEbK/sWCdAMfOomF7g2m2asvnN52Umf6Dqhw0u NYCneBwgTVvzrd8uctugPYY4680XEA4o7mDGbQrA050OYnJgtsny1bNLyz9x668HGUYtdJCHzd6 EE4JYF4sFvzC2jSbuPwc3F97uSvZwx7Bcg72KiEnji37z0MT54xG94w/5PQs4VmovAX8AI3bEXT nXCYc6rZ9Xn2xvCAob+hPp2dRzx71NgYePto+utLHpz3HhVMm2aeVp/dJqJPomgAr15PWPOUCPR bwYwDPa8jHP/L4w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The write congestion count, flag and waitqueue live in struct nfs_server, one per superblock. Two mounts of the same server get separate nfs_server structs that share one nfs_client and one RPC transport, yet each gets a full nfs_congestion_kb budget, so the effective limit on a server grows with the number of mounts. Move the state into a struct nfs_write_congestion embedded in struct nfs_client, so that every mount sharing a client shares the budget. This also gives pNFS data server clients a place for their own state, which a later patch uses. The accounting itself is unchanged: folios are still counted at writeback start and end against the inode's nfs_server->nfs_client. The congested flag becomes a bit in the new flags word, and waiters are now only woken when the flag is actually cleared rather than on every completion below the OFF threshold. Since the accounting still looks up NFS_SERVER(inode)->nfs_client at both ends, a migration that switches the server to a different client while folios are under writeback leaves both counts off by the folios in flight. The next patch records the charged client with each WRITE and removes that window. Signed-off-by: Jeff Layton --- fs/nfs/client.c | 4 +--- fs/nfs/write.c | 46 ++++++++++++++++++++++++++++------------------ include/linux/nfs_fs_sb.h | 16 +++++++++++++--- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 43e2acb2af14..3de07a9dd075 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -175,6 +175,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) INIT_LIST_HEAD(&clp->cl_superblocks); clp->cl_rpcclient = ERR_PTR(-EINVAL); + init_waitqueue_head(&clp->cl_wcong.wait); clp->cl_flags = cl_init->init_flags; clp->cl_proto = cl_init->proto; @@ -1111,9 +1112,6 @@ struct nfs_server *nfs_alloc_server(void) server->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED; - init_waitqueue_head(&server->write_congestion_wait); - atomic_long_set(&server->writeback, 0); - atomic64_set(&server->owner_ctr, 0); pnfs_init_server(server); diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 354ef195995a..475742f2afbb 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -283,32 +283,43 @@ int nfs_congestion_kb; #define NFS_CONGESTION_OFF_THRESH \ (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2)) +static bool nfs_write_congested(struct nfs_client *clp) +{ + return test_bit(NFS_WCONG_CONGESTED, &clp->cl_wcong.flags); +} + +static long nfs_write_inflight(struct nfs_client *clp) +{ + return atomic_long_read(&clp->cl_wcong.inflight); +} + static void nfs_folio_set_writeback(struct folio *folio) { - struct nfs_server *nfss = NFS_SERVER(folio->mapping->host); + struct nfs_client *clp = NFS_SERVER(folio->mapping->host)->nfs_client; + struct nfs_write_congestion *wcong = &clp->cl_wcong; long writeback; folio_start_writeback(folio); - writeback = atomic_long_inc_return(&nfss->writeback); + writeback = atomic_long_inc_return(&wcong->inflight); if (writeback > NFS_CONGESTION_ON_THRESH && - !xchg(&nfss->write_congested, 1)) - trace_nfs_write_congestion_on(nfss->nfs_client, writeback, + !test_and_set_bit(NFS_WCONG_CONGESTED, &wcong->flags)) + trace_nfs_write_congestion_on(clp, writeback, NFS_CONGESTION_ON_THRESH); } static void nfs_folio_end_writeback(struct folio *folio) { - struct nfs_server *nfss = NFS_SERVER(folio->mapping->host); + struct nfs_client *clp = NFS_SERVER(folio->mapping->host)->nfs_client; + struct nfs_write_congestion *wcong = &clp->cl_wcong; long writeback; folio_end_writeback_no_dropbehind(folio); - writeback = atomic_long_dec_return(&nfss->writeback); - if (writeback < NFS_CONGESTION_OFF_THRESH) { - if (xchg(&nfss->write_congested, 0)) - trace_nfs_write_congestion_off(nfss->nfs_client, - writeback, - NFS_CONGESTION_OFF_THRESH); - wake_up_all(&nfss->write_congestion_wait); + writeback = atomic_long_dec_return(&wcong->inflight); + if (writeback < NFS_CONGESTION_OFF_THRESH && + test_and_clear_bit(NFS_WCONG_CONGESTED, &wcong->flags)) { + trace_nfs_write_congestion_off(clp, writeback, + NFS_CONGESTION_OFF_THRESH); + wake_up_all(&wcong->wait); } } @@ -666,19 +677,18 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) struct nfs_pageio_descriptor pgio; struct nfs_io_completion *ioc = NULL; unsigned int mntflags = NFS_SERVER(inode)->flags; - struct nfs_server *nfss = NFS_SERVER(inode); + struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; int priority = 0; int err; trace_nfs_writepages(inode, wbc->range_start, wbc->range_end - wbc->range_start); /* Wait with writeback until write congestion eases */ - if (wbc->sync_mode == WB_SYNC_NONE && nfss->write_congested) { - trace_nfs_write_congestion_wait(nfss->nfs_client, - atomic_long_read(&nfss->writeback), + if (wbc->sync_mode == WB_SYNC_NONE && nfs_write_congested(clp)) { + trace_nfs_write_congestion_wait(clp, nfs_write_inflight(clp), NFS_CONGESTION_OFF_THRESH); - err = wait_event_killable(nfss->write_congestion_wait, - nfss->write_congested == 0); + err = wait_event_killable(clp->cl_wcong.wait, + !nfs_write_congested(clp)); if (err) goto out_err; } diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index df3fae763e41..c46604f2f4f2 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -23,6 +23,17 @@ struct nfs4_minor_version_ops; struct nfs41_server_scope; struct nfs41_impl_id; +/* + * Write congestion state, kept per nfs_client so that all mounts sharing + * a client, and all users of a pNFS data server, share one budget. + */ +struct nfs_write_congestion { + atomic_long_t inflight; /* folios under writeback */ + unsigned long flags; +#define NFS_WCONG_CONGESTED 0 /* writers should wait */ + wait_queue_head_t wait; /* wait until congestion eases */ +}; + /* * The nfs_client identifies our client state to the server. */ @@ -69,6 +80,8 @@ struct nfs_client { const char * cl_principal; /* used for machine cred */ struct xprtsec_parms cl_xprtsec; /* xprt security policy */ + struct nfs_write_congestion cl_wcong; /* write congestion control */ + #if IS_ENABLED(CONFIG_NFS_V4) struct list_head cl_ds_clients; /* auth flavor data servers */ u64 cl_clientid; /* constant */ @@ -153,9 +166,6 @@ struct nfs_server { struct rpc_clnt * client_acl; /* ACL RPC client handle */ struct nlm_host *nlm_host; /* NLM client handle */ struct nfs_iostats __percpu *io_stats; /* I/O statistics */ - wait_queue_head_t write_congestion_wait; /* wait until write congestion eases */ - atomic_long_t writeback; /* number of writeback pages */ - unsigned int write_congested;/* flag set when writeback gets too high */ unsigned int flags; /* various flags */ /* The following are for internal use only. Also see uapi/linux/nfs_mount.h */ -- 2.56.1