@@ -80,9 +80,7 @@ static int smb_direct_max_fragmented_recv_size = 1024 * 1024;
80
80
/* The maximum single-message size which can be received */
81
81
static int smb_direct_max_receive_size = 8192 ;
82
82
83
- static int smb_direct_max_read_write_size = 524224 ;
84
-
85
- static int smb_direct_max_outstanding_rw_ops = 8 ;
83
+ static int smb_direct_max_read_write_size = 8 * 1024 * 1024 ;
86
84
87
85
static LIST_HEAD (smb_direct_device_list );
88
86
static DEFINE_RWLOCK (smb_direct_device_lock );
@@ -147,10 +145,12 @@ struct smb_direct_transport {
147
145
atomic_t send_credits ;
148
146
spinlock_t lock_new_recv_credits ;
149
147
int new_recv_credits ;
150
- atomic_t rw_avail_ops ;
148
+ int max_rw_credits ;
149
+ int pages_per_rw_credit ;
150
+ atomic_t rw_credits ;
151
151
152
152
wait_queue_head_t wait_send_credits ;
153
- wait_queue_head_t wait_rw_avail_ops ;
153
+ wait_queue_head_t wait_rw_credits ;
154
154
155
155
mempool_t * sendmsg_mempool ;
156
156
struct kmem_cache * sendmsg_cache ;
@@ -377,7 +377,7 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id)
377
377
t -> reassembly_queue_length = 0 ;
378
378
init_waitqueue_head (& t -> wait_reassembly_queue );
379
379
init_waitqueue_head (& t -> wait_send_credits );
380
- init_waitqueue_head (& t -> wait_rw_avail_ops );
380
+ init_waitqueue_head (& t -> wait_rw_credits );
381
381
382
382
spin_lock_init (& t -> receive_credit_lock );
383
383
spin_lock_init (& t -> recvmsg_queue_lock );
@@ -983,18 +983,19 @@ static int smb_direct_flush_send_list(struct smb_direct_transport *t,
983
983
}
984
984
985
985
static int wait_for_credits (struct smb_direct_transport * t ,
986
- wait_queue_head_t * waitq , atomic_t * credits )
986
+ wait_queue_head_t * waitq , atomic_t * total_credits ,
987
+ int needed )
987
988
{
988
989
int ret ;
989
990
990
991
do {
991
- if (atomic_dec_return ( credits ) >= 0 )
992
+ if (atomic_sub_return ( needed , total_credits ) >= 0 )
992
993
return 0 ;
993
994
994
- atomic_inc ( credits );
995
+ atomic_add ( needed , total_credits );
995
996
ret = wait_event_interruptible (* waitq ,
996
- atomic_read (credits ) > 0 ||
997
- t -> status != SMB_DIRECT_CS_CONNECTED );
997
+ atomic_read (total_credits ) >= needed ||
998
+ t -> status != SMB_DIRECT_CS_CONNECTED );
998
999
999
1000
if (t -> status != SMB_DIRECT_CS_CONNECTED )
1000
1001
return - ENOTCONN ;
@@ -1015,7 +1016,19 @@ static int wait_for_send_credits(struct smb_direct_transport *t,
1015
1016
return ret ;
1016
1017
}
1017
1018
1018
- return wait_for_credits (t , & t -> wait_send_credits , & t -> send_credits );
1019
+ return wait_for_credits (t , & t -> wait_send_credits , & t -> send_credits , 1 );
1020
+ }
1021
+
1022
+ static int wait_for_rw_credits (struct smb_direct_transport * t , int credits )
1023
+ {
1024
+ return wait_for_credits (t , & t -> wait_rw_credits , & t -> rw_credits , credits );
1025
+ }
1026
+
1027
+ static int calc_rw_credits (struct smb_direct_transport * t ,
1028
+ char * buf , unsigned int len )
1029
+ {
1030
+ return DIV_ROUND_UP (get_buf_page_count (buf , len ),
1031
+ t -> pages_per_rw_credit );
1019
1032
}
1020
1033
1021
1034
static int smb_direct_create_header (struct smb_direct_transport * t ,
@@ -1331,8 +1344,8 @@ static void read_write_done(struct ib_cq *cq, struct ib_wc *wc,
1331
1344
smb_direct_disconnect_rdma_connection (t );
1332
1345
}
1333
1346
1334
- if (atomic_inc_return (& t -> rw_avail_ops ) > 0 )
1335
- wake_up (& t -> wait_rw_avail_ops );
1347
+ if (atomic_inc_return (& t -> rw_credits ) > 0 )
1348
+ wake_up (& t -> wait_rw_credits );
1336
1349
1337
1350
rdma_rw_ctx_destroy (& msg -> rw_ctx , t -> qp , t -> qp -> port ,
1338
1351
msg -> sg_list , msg -> sgt .nents , dir );
@@ -1363,16 +1376,18 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
1363
1376
struct ib_send_wr * first_wr = NULL ;
1364
1377
u32 remote_key = le32_to_cpu (desc [0 ].token );
1365
1378
u64 remote_offset = le64_to_cpu (desc [0 ].offset );
1379
+ int credits_needed ;
1366
1380
1367
- ret = wait_for_credits (t , & t -> wait_rw_avail_ops , & t -> rw_avail_ops );
1381
+ credits_needed = calc_rw_credits (t , buf , buf_len );
1382
+ ret = wait_for_rw_credits (t , credits_needed );
1368
1383
if (ret < 0 )
1369
1384
return ret ;
1370
1385
1371
1386
/* TODO: mempool */
1372
1387
msg = kmalloc (offsetof(struct smb_direct_rdma_rw_msg , sg_list ) +
1373
1388
sizeof (struct scatterlist ) * SG_CHUNK_SIZE , GFP_KERNEL );
1374
1389
if (!msg ) {
1375
- atomic_inc ( & t -> rw_avail_ops );
1390
+ atomic_add ( credits_needed , & t -> rw_credits );
1376
1391
return - ENOMEM ;
1377
1392
}
1378
1393
@@ -1381,7 +1396,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
1381
1396
get_buf_page_count (buf , buf_len ),
1382
1397
msg -> sg_list , SG_CHUNK_SIZE );
1383
1398
if (ret ) {
1384
- atomic_inc ( & t -> rw_avail_ops );
1399
+ atomic_add ( credits_needed , & t -> rw_credits );
1385
1400
kfree (msg );
1386
1401
return - ENOMEM ;
1387
1402
}
@@ -1417,7 +1432,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
1417
1432
return 0 ;
1418
1433
1419
1434
err :
1420
- atomic_inc ( & t -> rw_avail_ops );
1435
+ atomic_add ( credits_needed , & t -> rw_credits );
1421
1436
if (first_wr )
1422
1437
rdma_rw_ctx_destroy (& msg -> rw_ctx , t -> qp , t -> qp -> port ,
1423
1438
msg -> sg_list , msg -> sgt .nents ,
@@ -1642,11 +1657,19 @@ static int smb_direct_prepare_negotiation(struct smb_direct_transport *t)
1642
1657
return ret ;
1643
1658
}
1644
1659
1660
+ static unsigned int smb_direct_get_max_fr_pages (struct smb_direct_transport * t )
1661
+ {
1662
+ return min_t (unsigned int ,
1663
+ t -> cm_id -> device -> attrs .max_fast_reg_page_list_len ,
1664
+ 256 );
1665
+ }
1666
+
1645
1667
static int smb_direct_init_params (struct smb_direct_transport * t ,
1646
1668
struct ib_qp_cap * cap )
1647
1669
{
1648
1670
struct ib_device * device = t -> cm_id -> device ;
1649
- int max_send_sges , max_pages , max_rw_wrs , max_send_wrs ;
1671
+ int max_send_sges , max_rw_wrs , max_send_wrs ;
1672
+ unsigned int max_sge_per_wr , wrs_per_credit ;
1650
1673
1651
1674
/* need 2 more sge. because a SMB_DIRECT header will be mapped,
1652
1675
* and maybe a send buffer could be not page aligned.
@@ -1658,25 +1681,31 @@ static int smb_direct_init_params(struct smb_direct_transport *t,
1658
1681
return - EINVAL ;
1659
1682
}
1660
1683
1661
- /*
1662
- * allow smb_direct_max_outstanding_rw_ops of in-flight RDMA
1663
- * read/writes. HCA guarantees at least max_send_sge of sges for
1664
- * a RDMA read/write work request, and if memory registration is used,
1665
- * we need reg_mr, local_inv wrs for each read/write.
1684
+ /* Calculate the number of work requests for RDMA R/W.
1685
+ * The maximum number of pages which can be registered
1686
+ * with one Memory region can be transferred with one
1687
+ * R/W credit. And at least 4 work requests for each credit
1688
+ * are needed for MR registration, RDMA R/W, local & remote
1689
+ * MR invalidation.
1666
1690
*/
1667
1691
t -> max_rdma_rw_size = smb_direct_max_read_write_size ;
1668
- max_pages = DIV_ROUND_UP (t -> max_rdma_rw_size , PAGE_SIZE ) + 1 ;
1669
- max_rw_wrs = DIV_ROUND_UP (max_pages , SMB_DIRECT_MAX_SEND_SGES );
1670
- max_rw_wrs += rdma_rw_mr_factor (device , t -> cm_id -> port_num ,
1671
- max_pages ) * 2 ;
1672
- max_rw_wrs *= smb_direct_max_outstanding_rw_ops ;
1692
+ t -> pages_per_rw_credit = smb_direct_get_max_fr_pages (t );
1693
+ t -> max_rw_credits = DIV_ROUND_UP (t -> max_rdma_rw_size ,
1694
+ (t -> pages_per_rw_credit - 1 ) *
1695
+ PAGE_SIZE );
1696
+
1697
+ max_sge_per_wr = min_t (unsigned int , device -> attrs .max_send_sge ,
1698
+ device -> attrs .max_sge_rd );
1699
+ wrs_per_credit = max_t (unsigned int , 4 ,
1700
+ DIV_ROUND_UP (t -> pages_per_rw_credit ,
1701
+ max_sge_per_wr ) + 1 );
1702
+ max_rw_wrs = t -> max_rw_credits * wrs_per_credit ;
1673
1703
1674
1704
max_send_wrs = smb_direct_send_credit_target + max_rw_wrs ;
1675
1705
if (max_send_wrs > device -> attrs .max_cqe ||
1676
1706
max_send_wrs > device -> attrs .max_qp_wr ) {
1677
- pr_err ("consider lowering send_credit_target = %d, or max_outstanding_rw_ops = %d\n" ,
1678
- smb_direct_send_credit_target ,
1679
- smb_direct_max_outstanding_rw_ops );
1707
+ pr_err ("consider lowering send_credit_target = %d\n" ,
1708
+ smb_direct_send_credit_target );
1680
1709
pr_err ("Possible CQE overrun, device reporting max_cqe %d max_qp_wr %d\n" ,
1681
1710
device -> attrs .max_cqe , device -> attrs .max_qp_wr );
1682
1711
return - EINVAL ;
@@ -1711,20 +1740,18 @@ static int smb_direct_init_params(struct smb_direct_transport *t,
1711
1740
1712
1741
t -> send_credit_target = smb_direct_send_credit_target ;
1713
1742
atomic_set (& t -> send_credits , 0 );
1714
- atomic_set (& t -> rw_avail_ops , smb_direct_max_outstanding_rw_ops );
1743
+ atomic_set (& t -> rw_credits , t -> max_rw_credits );
1715
1744
1716
1745
t -> max_send_size = smb_direct_max_send_size ;
1717
1746
t -> max_recv_size = smb_direct_max_receive_size ;
1718
1747
t -> max_fragmented_recv_size = smb_direct_max_fragmented_recv_size ;
1719
1748
1720
1749
cap -> max_send_wr = max_send_wrs ;
1721
1750
cap -> max_recv_wr = t -> recv_credit_max ;
1722
- cap -> max_send_sge = SMB_DIRECT_MAX_SEND_SGES ;
1751
+ cap -> max_send_sge = max_sge_per_wr ;
1723
1752
cap -> max_recv_sge = SMB_DIRECT_MAX_RECV_SGES ;
1724
1753
cap -> max_inline_data = 0 ;
1725
- cap -> max_rdma_ctxs =
1726
- rdma_rw_mr_factor (device , t -> cm_id -> port_num , max_pages ) *
1727
- smb_direct_max_outstanding_rw_ops ;
1754
+ cap -> max_rdma_ctxs = t -> max_rw_credits ;
1728
1755
return 0 ;
1729
1756
}
1730
1757
@@ -1817,7 +1844,8 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
1817
1844
}
1818
1845
1819
1846
t -> send_cq = ib_alloc_cq (t -> cm_id -> device , t ,
1820
- t -> send_credit_target , 0 , IB_POLL_WORKQUEUE );
1847
+ smb_direct_send_credit_target + cap -> max_rdma_ctxs ,
1848
+ 0 , IB_POLL_WORKQUEUE );
1821
1849
if (IS_ERR (t -> send_cq )) {
1822
1850
pr_err ("Can't create RDMA send CQ\n" );
1823
1851
ret = PTR_ERR (t -> send_cq );
@@ -1826,8 +1854,7 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
1826
1854
}
1827
1855
1828
1856
t -> recv_cq = ib_alloc_cq (t -> cm_id -> device , t ,
1829
- cap -> max_send_wr + cap -> max_rdma_ctxs ,
1830
- 0 , IB_POLL_WORKQUEUE );
1857
+ t -> recv_credit_max , 0 , IB_POLL_WORKQUEUE );
1831
1858
if (IS_ERR (t -> recv_cq )) {
1832
1859
pr_err ("Can't create RDMA recv CQ\n" );
1833
1860
ret = PTR_ERR (t -> recv_cq );
@@ -1856,17 +1883,12 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
1856
1883
1857
1884
pages_per_rw = DIV_ROUND_UP (t -> max_rdma_rw_size , PAGE_SIZE ) + 1 ;
1858
1885
if (pages_per_rw > t -> cm_id -> device -> attrs .max_sgl_rd ) {
1859
- int pages_per_mr , mr_count ;
1860
-
1861
- pages_per_mr = min_t (int , pages_per_rw ,
1862
- t -> cm_id -> device -> attrs .max_fast_reg_page_list_len );
1863
- mr_count = DIV_ROUND_UP (pages_per_rw , pages_per_mr ) *
1864
- atomic_read (& t -> rw_avail_ops );
1865
- ret = ib_mr_pool_init (t -> qp , & t -> qp -> rdma_mrs , mr_count ,
1866
- IB_MR_TYPE_MEM_REG , pages_per_mr , 0 );
1886
+ ret = ib_mr_pool_init (t -> qp , & t -> qp -> rdma_mrs ,
1887
+ t -> max_rw_credits , IB_MR_TYPE_MEM_REG ,
1888
+ t -> pages_per_rw_credit , 0 );
1867
1889
if (ret ) {
1868
1890
pr_err ("failed to init mr pool count %d pages %d\n" ,
1869
- mr_count , pages_per_mr );
1891
+ t -> max_rw_credits , t -> pages_per_rw_credit );
1870
1892
goto err ;
1871
1893
}
1872
1894
}
0 commit comments