Skip to contentSkip to conversation

cifs: avoid redundant calls to disable multichannel

PATCH In review [email protected] 1 participant 6 messages Feb 1, 2024 – Feb 6, 2024

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

PATCH 1/5 cifs: avoid redundant calls to disable multichannel

From: Shyam Prasad N <[email protected]>

When the server reports query network interface info call as unsupported following a tree connect, it means that multichannel is unsupported, even if the server capabilities report otherwise.

When this happens, cifs_chan_skip_or_disable is called to disable multichannel on the client. However, we only need to call this when multichannel is currently setup.

Fixes f591062bdbf4 ("cifs: handle servers that still advertise multichannel after disabling")
---
 fs/smb/client/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2pdu.c +1 -1
index 3110aabc32c5..75713559e69f 100644
@@ -419,7 +419,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 		rc = SMB3_request_interfaces(xid, tcon, false);
 		free_xid(xid);
 
-		if (rc == -EOPNOTSUPP) {
+		if (rc == -EOPNOTSUPP && ses->chan_count > 1) {
 			/*
 			 * some servers like Azure SMB server do not advertise
 			 * that multichannel has been disabled with server
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/5 cifs: change tcon status when need_reconnect is set on it

From: Shyam Prasad N <[email protected]>

When a tcon is marked for need_reconnect, the intention is to have it reconnected.

This change adjusts tcon->status in cifs_tree_connect when need_reconnect is set. Also, this change has a minor correction in resetting need_reconnect on success. It makes sure that it is done with tc_lock held.

---
 fs/smb/client/connect.c | 5 +++++
 fs/smb/client/dfs.c     | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
fs/smb/client/connect.c +5 -0
index c5cf88de32b7..28cacdd90bbf 100644
@@ -4230,6 +4230,11 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
 
 	/* only send once per connect */
 	spin_lock(&tcon->tc_lock);
+
+	/* if tcon is marked for needing reconnect, update state */
+	if (tcon->need_reconnect)
+		tcon->status = TID_NEED_TCON;
+
 	if (tcon->status == TID_GOOD) {
 		spin_unlock(&tcon->tc_lock);
 		return 0;
fs/smb/client/dfs.c +6 -1
index a8a1d386da65..449c59830039 100644
@@ -565,6 +565,11 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
 
 	/* only send once per connect */
 	spin_lock(&tcon->tc_lock);
+
+	/* if tcon is marked for needing reconnect, update state */
+	if (tcon->need_reconnect)
+		tcon->status = TID_NEED_TCON;
+
 	if (tcon->status == TID_GOOD) {
 		spin_unlock(&tcon->tc_lock);
 		return 0;
@@ -625,8 +630,8 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
 		spin_lock(&tcon->tc_lock);
 		if (tcon->status == TID_IN_TCON)
 			tcon->status = TID_GOOD;
-		spin_unlock(&tcon->tc_lock);
 		tcon->need_reconnect = false;
+		spin_unlock(&tcon->tc_lock);
 	}
 
 	return rc;
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/5 cifs: do not search for channel if server is terminating

In reply to [email protected]

From: Shyam Prasad N <[email protected]>

In order to scale down the channels, the following sequence of operations happen:
1. server struct is marked for terminate
2. the channel is deallocated in the ses->chans array
3. at a later point the cifsd thread actually terminates the server

Between 2 and 3, there can be calls to find the channel for a server struct. When that happens, there can be an ugly warning that's logged. But this is expected.

So this change does two things:
1. in cifs_ses_get_chan_index, if server->terminate is set, return
2. always make sure server->terminate is set with chan_lock held

---
 fs/smb/client/sess.c    | 4 ++++
 fs/smb/client/smb2pdu.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/sess.c +4 -0
index cde81042bebd..3d2548c35c9d 100644
@@ -75,6 +75,10 @@ cifs_ses_get_chan_index(struct cifs_ses *ses,
 {
 	unsigned int i;
 
+	/* if the channel is waiting for termination */
+	if (server->terminate)
+		return CIFS_INVAL_CHAN_INDEX;
+
 	for (i = 0; i < ses->chan_count; i++) {
 		if (ses->chans[i].server == server)
 			return i;
fs/smb/client/smb2pdu.c +1 -1
index 75713559e69f..cf5665f6f220 100644
@@ -178,6 +178,7 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,
 		}
 
 		ses->chans[chan_index].server = NULL;
+		server->terminate = true;
 		spin_unlock(&ses->chan_lock);
 
 		/*
@@ -188,7 +189,6 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,
 		 */
 		cifs_put_tcp_session(server, from_reconnect);
 
-		server->terminate = true;
 		cifs_signal_cifsd_for_reconnect(server, false);
 
 		/* mark primary server as needing reconnect */
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/5 cifs: failure to add channel on iface should bump up weight

In reply to [email protected]

From: Shyam Prasad N <[email protected]>

After the interface selection policy change to do a weighted round robin, each iface maintains a weight_fulfilled. When the weight_fulfilled reaches the total weight for the iface, we know that the weights can be reset and ifaces can be allocated from scratch again.

During channel allocation failures on a particular channel, weight_fulfilled is not incremented. If a few interfaces are inactive, we could end up in a situation where the active interfaces are all allocated for the total_weight, and inactive ones are all that remain. This can cause a situation where no more channels can be allocated further.

This change fixes it by increasing weight_fulfilled, even when channel allocation failure happens. This could mean that if there are temporary failures in channel allocation, the iface weights may not strictly be adhered to. But that's still okay.

Fixes a6d8fb54a515 ("cifs: distribute channels across interfaces based on speed")
---
 fs/smb/client/sess.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/sess.c +2 -0
index 3d2548c35c9d..ed4bd88dd528 100644
@@ -273,6 +273,8 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
 					 &iface->sockaddr,
 					 rc);
 				kref_put(&iface->refcount, release_iface);
+				/* failure to add chan should increase weight */
+				iface->weight_fulfilled++;
 				continue;
 			}
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH 5/5 cifs: enforce nosharesock when multichannel is used

In reply to [email protected]

From: Shyam Prasad N <[email protected]>

In the current architecture, multiple sessions can share the primary channel, but secondary channels for each session is not shared.

This can create two problems when primary channel is shared among several sessions. For one, there could be uneven utilization of channels due to this skew.

Another major issue is how a cifsd thread can get to the channel for a secondary channel. The process is already cumbersome. We also need to find the right session for the server struct.

To avoid both the problems, this change marks even the primary channel as nosharesock. Secondary channels are marked as nosharesock anyway.

We can remove this when we fix the mchan architecture to share all channels.

---
 fs/smb/client/fs_context.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/fs_context.c +2 -0
index 82eafe0815dc..e7543574ea9e 100644
@@ -1043,6 +1043,8 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 			ctx->max_channels = 1;
 		} else {
 			ctx->multichannel = true;
+			/* enforce nosharesock */
+			ctx->nosharesock = true;
 			/* if number of channels not specified, default to 2 */
 			if (ctx->max_channels < 2)
 				ctx->max_channels = 2;
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 5/5] cifs: enforce nosharesock when multichannel is used

Quoted 42 lines · On Thu, Feb 1, 2024 at 4:45 PM <[email protected]> wrote:

From: Shyam Prasad N <[email protected]>

In the current architecture, multiple sessions can share the primary channel, but secondary channels for each session is not shared.

This can create two problems when primary channel is shared among several sessions. For one, there could be uneven utilization of channels due to this skew.

Another major issue is how a cifsd thread can get to the channel for a secondary channel. The process is already cumbersome. We also need to find the right session for the server struct.

To avoid both the problems, this change marks even the primary channel as nosharesock. Secondary channels are marked as nosharesock anyway.

We can remove this when we fix the mchan architecture to share all channels.

---
 fs/smb/client/fs_context.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/fs_context.c +2 -1
index 82eafe0815dc..e7543574ea9e 100644
@@ -1043,6 +1043,8 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
                        ctx->max_channels = 1;
                } else {
                        ctx->multichannel = true;
+                       /* enforce nosharesock */
+                       ctx->nosharesock = true;
                        /* if number of channels not specified, default to 2 */
                        if (ctx->max_channels < 2)
                                ctx->max_channels = 2;
--
Quoted 2 lines

2.34.1

This was discussed offline with Steve. And we decided it's best not to use this one.
This patch may unnecessarily increase socket utilization for mounts that could otherwise have shared the sessions.

Our multichannel implementation makes it difficult to solve this problem. I'll send another patch for now to work around the problem in another way. (the cumbersome method as mentioned above)
However, please note that the perf skew problem can still happen with that change. Maybe we can address that in the next kernel version.

Signature · 2 lines
Regards,
Shyam