Patch "cifs: use the least loaded channel for sending requests" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    cifs: use the least loaded channel for sending requests

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     cifs-use-the-least-loaded-channel-for-sending-reques.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 1ca440f0b69adedd5cb156439fe8c9b6c99fdcfd
Author: Shyam Prasad N <sprasad@xxxxxxxxxxxxx>
Date:   Mon Dec 19 05:40:44 2022 +0000

    cifs: use the least loaded channel for sending requests
    
    [ Upstream commit ea90708d3cf3d0d92c02afe445ad463fb3c6bf10 ]
    
    Till now, we've used a simple round robin approach to
    distribute the requests between the channels. This does
    not work well if the channels consume the requests at
    different speeds, even if the advertised speeds are the
    same.
    
    This change will allow the client to pick the channel
    with least number of requests currently in-flight. This
    will disregard the link speed, and select a channel
    based on the current load of the channels.
    
    For cases when all the channels are equally loaded,
    fall back to the old round robin method.
    
    Signed-off-by: Shyam Prasad N <sprasad@xxxxxxxxxxxxx>
    Reviewed-by: Paulo Alcantara (SUSE) <pc@xxxxxx>
    Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx>
    Stable-dep-of: 8094a600245e ("smb3: missing lock when picking channel")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
index 338b34c99b2de..da2bef3b7ac27 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -1045,15 +1045,40 @@ cifs_cancelled_callback(struct mid_q_entry *mid)
 struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses)
 {
 	uint index = 0;
+	unsigned int min_in_flight = UINT_MAX, max_in_flight = 0;
+	struct TCP_Server_Info *server = NULL;
+	int i;
 
 	if (!ses)
 		return NULL;
 
-	/* round robin */
-	index = (uint)atomic_inc_return(&ses->chan_seq);
-
 	spin_lock(&ses->chan_lock);
-	index %= ses->chan_count;
+	for (i = 0; i < ses->chan_count; i++) {
+		server = ses->chans[i].server;
+		if (!server)
+			continue;
+
+		/*
+		 * strictly speaking, we should pick up req_lock to read
+		 * server->in_flight. But it shouldn't matter much here if we
+		 * race while reading this data. The worst that can happen is
+		 * that we could use a channel that's not least loaded. Avoiding
+		 * taking the lock could help reduce wait time, which is
+		 * important for this function
+		 */
+		if (server->in_flight < min_in_flight) {
+			min_in_flight = server->in_flight;
+			index = i;
+		}
+		if (server->in_flight > max_in_flight)
+			max_in_flight = server->in_flight;
+	}
+
+	/* if all channels are equally loaded, fall back to round-robin */
+	if (min_in_flight == max_in_flight) {
+		index = (uint)atomic_inc_return(&ses->chan_seq);
+		index %= ses->chan_count;
+	}
 	spin_unlock(&ses->chan_lock);
 
 	return ses->chans[index].server;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux