Skip to content

Commit

Permalink
net/smc: remove locks smc_client_lgr_pending and smc_server_lgr_pending
Browse files Browse the repository at this point in the history
This patch attempts to remove locks named smc_client_lgr_pending and
smc_server_lgr_pending, which aim to serialize the creation of link
group. However, once link group existed already, those locks are
meaningless, worse still, they make incoming connections have to be
queued one after the other.

Now, the creation of link group is no longer generated by competition,
but allocated through following strategy.

1. Try to find a suitable link group, if successd, current connection
is considered as NON first contact connection. ends.

2. Check the number of connections currently waiting for a suitable
link group to be created, if it is not less that the number of link
groups to be created multiplied by (SMC_RMBS_PER_LGR_MAX - 1), then
increase the number of link groups to be created, current connection
is considered as the first contact connection. ends.

3. Increase the number of connections currently waiting, and wait
for woken up.

4. Decrease the number of connections currently waiting, goto 1.

We wake up the connection that was put to sleep in stage 3 through
the SMC link state change event. Once the link moves out of the
SMC_LNK_ACTIVATING state, decrease the number of link groups to
be created, and then wake up at most (SMC_RMBS_PER_LGR_MAX - 1)
connections.

In the iplementation, we introduce the concept of lnk cluster, which is
a collection of links with the same characteristics (see
smcr_lnk_cluster_cmpfn() with more details), which makes it possible to
wake up efficiently in the scenario of N v.s 1.

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
  • Loading branch information
D. Wythe authored and intel-lab-lkp committed Nov 23, 2022
1 parent 49dedf8 commit 292a3d0
Show file tree
Hide file tree
Showing 3 changed files with 476 additions and 34 deletions.
45 changes: 17 additions & 28 deletions net/smc/af_smc.c
Expand Up @@ -53,12 +53,7 @@
#include "smc_tracepoint.h"
#include "smc_sysctl.h"

static DEFINE_MUTEX(smc_server_lgr_pending); /* serialize link group
* creation on server
*/
static DEFINE_MUTEX(smc_client_lgr_pending); /* serialize link group
* creation on client
*/
static DEFINE_MUTEX(smcd_buf_pending); /* serialize SMC-D buf creation */

static struct workqueue_struct *smc_tcp_ls_wq; /* wq for tcp listen work */
struct workqueue_struct *smc_hs_wq; /* wq for handshake work */
Expand Down Expand Up @@ -1197,10 +1192,8 @@ static int smc_connect_rdma(struct smc_sock *smc,
if (reason_code)
return reason_code;

mutex_lock(&smc_client_lgr_pending);
reason_code = smc_conn_create(smc, ini);
if (reason_code) {
mutex_unlock(&smc_client_lgr_pending);
return reason_code;
}

Expand Down Expand Up @@ -1292,7 +1285,6 @@ static int smc_connect_rdma(struct smc_sock *smc,
if (reason_code)
goto connect_abort;
}
mutex_unlock(&smc_client_lgr_pending);

smc_copy_sock_settings_to_clc(smc);
smc->connect_nonblock = 0;
Expand All @@ -1302,7 +1294,6 @@ static int smc_connect_rdma(struct smc_sock *smc,
return 0;
connect_abort:
smc_conn_abort(smc, ini->first_contact_local);
mutex_unlock(&smc_client_lgr_pending);
smc->connect_nonblock = 0;

return reason_code;
Expand Down Expand Up @@ -1348,16 +1339,15 @@ static int smc_connect_ism(struct smc_sock *smc,
}
ini->ism_peer_gid[ini->ism_selected] = aclc->d0.gid;

/* there is only one lgr role for SMC-D; use server lock */
mutex_lock(&smc_server_lgr_pending);
rc = smc_conn_create(smc, ini);
if (rc) {
mutex_unlock(&smc_server_lgr_pending);
return rc;
}

mutex_lock(&smcd_buf_pending);
/* Create send and receive buffers */
rc = smc_buf_create(smc, true);
mutex_unlock(&smcd_buf_pending);
if (rc) {
rc = (rc == -ENOSPC) ? SMC_CLC_DECL_MAX_DMB : SMC_CLC_DECL_MEM;
goto connect_abort;
Expand All @@ -1379,7 +1369,6 @@ static int smc_connect_ism(struct smc_sock *smc,
aclc->hdr.version, eid, NULL);
if (rc)
goto connect_abort;
mutex_unlock(&smc_server_lgr_pending);

smc_copy_sock_settings_to_clc(smc);
smc->connect_nonblock = 0;
Expand All @@ -1389,7 +1378,6 @@ static int smc_connect_ism(struct smc_sock *smc,
return 0;
connect_abort:
smc_conn_abort(smc, ini->first_contact_local);
mutex_unlock(&smc_server_lgr_pending);
smc->connect_nonblock = 0;

return rc;
Expand Down Expand Up @@ -1505,6 +1493,9 @@ static int __smc_connect(struct smc_sock *smc)

SMC_STAT_CLNT_SUCC_INC(sock_net(smc->clcsock->sk), aclc);
smc_connect_ism_vlan_cleanup(smc, ini);
if (ini->first_contact_local)
smc_lgr_decision_maker_on_first_contact_success(smc, ini);

kfree(buf);
kfree(ini);
return 0;
Expand All @@ -1513,6 +1504,8 @@ static int __smc_connect(struct smc_sock *smc)
smc_connect_ism_vlan_cleanup(smc, ini);
kfree(buf);
fallback:
if (ini->first_contact_local)
smc_lgr_decision_maker_on_first_contact_fail(ini);
kfree(ini);
return smc_connect_decline_fallback(smc, rc, version);
}
Expand Down Expand Up @@ -2003,8 +1996,10 @@ static int smc_listen_ism_init(struct smc_sock *new_smc,
if (rc)
return rc;

mutex_lock(&smcd_buf_pending);
/* Create send and receive buffers */
rc = smc_buf_create(new_smc, true);
mutex_unlock(&smcd_buf_pending);
if (rc) {
smc_conn_abort(new_smc, ini->first_contact_local);
return (rc == -ENOSPC) ? SMC_CLC_DECL_MAX_DMB :
Expand Down Expand Up @@ -2381,35 +2376,28 @@ static void smc_listen_work(struct work_struct *work)
if (rc)
goto out_decl;

mutex_lock(&smc_server_lgr_pending);
smc_close_init(new_smc);
smc_rx_init(new_smc);
smc_tx_init(new_smc);

/* determine ISM or RoCE device used for connection */
rc = smc_listen_find_device(new_smc, pclc, ini);
if (rc)
goto out_unlock;
goto out_decl;

/* send SMC Accept CLC message */
accept_version = ini->is_smcd ? ini->smcd_version : ini->smcr_version;
rc = smc_clc_send_accept(new_smc, ini->first_contact_local,
accept_version, ini->negotiated_eid);
if (rc)
goto out_unlock;

/* SMC-D does not need this lock any more */
if (ini->is_smcd)
mutex_unlock(&smc_server_lgr_pending);
goto out_decl;

/* receive SMC Confirm CLC message */
memset(buf, 0, sizeof(*buf));
cclc = (struct smc_clc_msg_accept_confirm *)buf;
rc = smc_clc_wait_msg(new_smc, cclc, sizeof(*buf),
SMC_CLC_CONFIRM, CLC_WAIT_TIME);
if (rc) {
if (!ini->is_smcd)
goto out_unlock;
goto out_decl;
}

Expand All @@ -2418,19 +2406,20 @@ static void smc_listen_work(struct work_struct *work)
rc = smc_listen_rdma_finish(new_smc, cclc,
ini->first_contact_local, ini);
if (rc)
goto out_unlock;
mutex_unlock(&smc_server_lgr_pending);
goto out_decl;
}
smc_conn_leave_rtoken_pending(new_smc, ini);
smc_conn_save_peer_info(new_smc, cclc);
smc_listen_out_connected(new_smc);
SMC_STAT_SERV_SUCC_INC(sock_net(newclcsock->sk), ini);
if (ini->first_contact_local)
smc_lgr_decision_maker_on_first_contact_success(new_smc, ini);
goto out_free;

out_unlock:
mutex_unlock(&smc_server_lgr_pending);
out_decl:
smc_conn_leave_rtoken_pending(new_smc, ini);
if (ini && ini->first_contact_local)
smc_lgr_decision_maker_on_first_contact_fail(ini);
smc_listen_decline(new_smc, rc, ini ? ini->first_contact_local : 0,
proposal_version);
out_free:
Expand Down

0 comments on commit 292a3d0

Please sign in to comment.