Skip to contentSkip to conversation

NFSv4/pnfs: Keep data server connections across deviceid eviction

PATCH In review Benjamin Coddington 2 participants 4 messages Sep 18 – Nov 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover NFSv4/pnfs: Keep data server connections across deviceid eviction

This applies on top of the flexfiles striping series:

[PATCH v4 00/24] NFS: flexfiles device notifications and caching for wide striped layouts
https://lore.kernel.org/linux-nfs/[email protected]

and uses the hashed, address-keyed data server cache that series adds.

A metadata server that does not support deviceid notifications makes the client set NFS_DEVICEID_NOCACHE, and a NOCACHE deviceid node is freed as soon as the last layout referring to it is returned. That takes the data server's nfs_client and every transport underneath it along with it:

nfs4_put_deviceid_node()

    ff_layout_free_deviceid_node()
      nfs4_pnfs_ds_put()
        destroy_ds()
          nfs_put_client()
            rpc_shutdown_client()

The next I/O rebuilds all of it: a synchronous connect and NULL ping inline in pg_init(), plus the remaining nconnect-1 transports reconnecting lazily as RPCs land on them. I have a report of a wide stripe at nconnect=16 spending upwards of ten seconds on this before I/O can proceed, and paying it again on every layout cycle.

Keep the nfs4_pnfs_ds hashed once its last user goes away, and reap it later if nothing claims it.

Benjamin Coddington (2):
NFSv4/pnfs: Give the data server cache its own reference NFSv4/pnfs: Let unused data server connections linger

 fs/nfs/pnfs.c     |   4 +-
 fs/nfs/pnfs.h     |   4 ++
 fs/nfs/pnfs_nfs.c | 110 +++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 112 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 NFSv4/pnfs: Give the data server cache its own reference

Prepare the DS cache to allow data servers to outlive their layout references. Take a reference for the cache itself. An entry is created with a count of two, one for the caller and one for the cache, so a count of one now means it is still hashed with no users left.

Entries are still torn down at exactly the same point as before; only the bookkeeping changes.

Assisted-by Claude:claude-opus-5
---
 fs/nfs/pnfs_nfs.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
fs/nfs/pnfs_nfs.c +11 -4
index 7adb6f941cf2..6d6a4d05d13e 100644
@@ -713,11 +713,18 @@ void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds)
 {
 	struct nfs_net *nn = net_generic(ds->ds_net, nfs_net_id);
 
-	if (refcount_dec_and_lock(&ds->ds_count, &nn->nfs4_data_server_lock)) {
-		hlist_del_init(&ds->ds_node);
+	spin_lock(&nn->nfs4_data_server_lock);
+	refcount_dec(&ds->ds_count);
+	if (refcount_read(&ds->ds_count) > 1) {
 		spin_unlock(&nn->nfs4_data_server_lock);
-		destroy_ds(ds);
+		return;
 	}
+	hlist_del_init(&ds->ds_node);
+	spin_unlock(&nn->nfs4_data_server_lock);
+
+	/* The cache's reference is the last one */
+	if (refcount_dec_and_test(&ds->ds_count))
+		destroy_ds(ds);
 }
 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_put);
 
@@ -803,7 +810,7 @@ nfs4_pnfs_ds_add(const struct net *net, struct list_head *dsaddrs, u32 version,
 		INIT_LIST_HEAD(&ds->ds_addrs);
 		list_splice_init(dsaddrs, &ds->ds_addrs);
 		ds->ds_remotestr = remotestr;
-		refcount_set(&ds->ds_count, 1);
+		refcount_set(&ds->ds_count, 2);
 		INIT_HLIST_NODE(&ds->ds_node);
 		ds->ds_net = net;
 		ds->ds_clp = NULL;
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 NFSv4/pnfs: Let unused data server connections linger

In reply to Benjamin Coddington

A metadata server that does not support deviceid notifications makes the client set NFS_DEVICEID_NOCACHE, and a NOCACHE deviceid node is freed as soon as the last layout referring to it is returned.

The next IO will then do a synchronous connect and NULL ping inline in pg_init(), plus the remaining nconnect-1 transports reconnecting lazily as RPCs land on them. With a wide stripe and a large nconnect this introduces a hefty penalty for eeach layout cycle.

Allow the transports to linger. Keep the nfs4_pnfs_ds hashed once its last user goes away, and let a per-entry delayed work tear it down if nothing claims it within dataserver_linger seconds.

he linger defaults to 120 seconds and can be set to zero to restore the previous behavior. sunrpc already disconnects an idle transport after five minutes, so an entry that is never claimed again holds objects and slot tables rather than open connections.

Assisted-by Claude:claude-opus-5
---
 fs/nfs/pnfs.c     |  4 +-
 fs/nfs/pnfs.h     |  4 ++
 fs/nfs/pnfs_nfs.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 101 insertions(+), 2 deletions(-)
fs/nfs/pnfs.c +3 -1
index ade314de1738..b7a7fab68498 100644
@@ -111,8 +111,10 @@ unset_pnfs_layoutdriver(struct nfs_server *nfss)
 		if (nfss->pnfs_curr_ld->clear_layoutdriver)
 			nfss->pnfs_curr_ld->clear_layoutdriver(nfss);
 		/* Decrement the MDS count. Purge the deviceid cache if zero */
-		if (atomic_dec_and_test(&nfss->nfs_client->cl_mds_count))
+		if (atomic_dec_and_test(&nfss->nfs_client->cl_mds_count)) {
 			nfs4_deviceid_purge_client(nfss->nfs_client);
+			nfs4_pnfs_ds_reap_net(nfss->nfs_client->cl_net);
+		}
 		module_put(nfss->pnfs_curr_ld->owner);
 	}
 	nfss->pnfs_curr_ld = NULL;
fs/nfs/pnfs.h +4 -0
index 5cde5db63d29..5ce1a0746e09 100644
@@ -58,6 +58,7 @@ struct nfs4_pnfs_ds_addr {
 
 struct nfs4_pnfs_ds {
 	struct hlist_node	ds_node;  /* nfs_net nfs4_data_server_cache */
+	struct hlist_node	ds_tmpnode; /* for batched disposal */
 	char			*ds_remotestr;	/* comma sep list of addrs */
 	struct list_head	ds_addrs;
 	const struct net	*ds_net;
@@ -66,6 +67,8 @@ struct nfs4_pnfs_ds {
 	u32			ds_version;	/* cache key, with ds_addrs */
 	unsigned long		ds_state;
 #define NFS4DS_CONNECTING	0	/* ds is establishing connection */
+	unsigned long		ds_idle;	/* jiffies of the last put */
+	struct delayed_work	ds_reaper;
 };
 
 struct pnfs_layout_segment {
@@ -498,6 +501,7 @@ int pnfs_generic_commit_pagelist(struct inode *inode,
 int pnfs_generic_scan_commit_lists(struct nfs_commit_info *cinfo, int max);
 void pnfs_generic_write_commit_done(struct rpc_task *task, void *data);
 void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds);
+void nfs4_pnfs_ds_reap_net(const struct net *net);
 struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(const struct net *net,
 				      struct list_head *dsaddrs,
 				      u32 version, gfp_t gfp_flags);
fs/nfs/pnfs_nfs.c +94 -1

122 lines not on this page · raw message

Signature · 1 line
2.53.0
Tested-by on the v1 series
#3 lore raw
In reply to Benjamin Coddington
Quoted 2 lines · Benjamin Coddington

Keep the nfs4_pnfs_ds hashed once its last user goes away, and reap it later if nothing claims it.

I have been running both patches, on top of your flexfiles striping series, in a 7.3-based kernel on ten NFSv4.2 clients since September:
flexfiles layouts striped across 240 volumes on ten data servers, with nconnect=16 to each data server and dataserver_linger at 3600, on top of other NFS patches. With linger the data server connections stay up across layout returns, so I/O after a layout cycle does not wait for reconnects; with it short they are torn down and rebuilt as you describe. No problems seen with it applied.