Skip to content

Commit 43cc668

Browse files
mwwunderkeithbusch
authored andcommitted
nvmet-tcp: set SO_PRIORITY for accepted sockets
Enable ability to associate all sockets related to NVMf TCP traffic to a priority group that will perform optimized network processing for this traffic class. Maintain initial default behavior of using priority of zero. Signed-off-by: Kiran Patil <[email protected]> Signed-off-by: Mark Wunderlich <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 9912ade commit 43cc668

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

drivers/nvme/target/tcp.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919

2020
#define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE)
2121

22+
/* Define the socket priority to use for connections were it is desirable
23+
* that the NIC consider performing optimized packet processing or filtering.
24+
* A non-zero value being sufficient to indicate general consideration of any
25+
* possible optimization. Making it a module param allows for alternative
26+
* values that may be unique for some NIC implementations.
27+
*/
28+
static int so_priority;
29+
module_param(so_priority, int, 0644);
30+
MODULE_PARM_DESC(so_priority, "nvmet tcp socket optimize priority");
31+
2232
#define NVMET_TCP_RECV_BUDGET 8
2333
#define NVMET_TCP_SEND_BUDGET 8
2434
#define NVMET_TCP_IO_WORK_BUDGET 64
@@ -1433,6 +1443,13 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)
14331443
if (ret)
14341444
return ret;
14351445

1446+
if (so_priority > 0) {
1447+
ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY,
1448+
(char *)&so_priority, sizeof(so_priority));
1449+
if (ret)
1450+
return ret;
1451+
}
1452+
14361453
/* Set socket type of service */
14371454
if (inet->rcv_tos > 0) {
14381455
int tos = inet->rcv_tos;
@@ -1622,6 +1639,15 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
16221639
goto err_sock;
16231640
}
16241641

1642+
if (so_priority > 0) {
1643+
ret = kernel_setsockopt(port->sock, SOL_SOCKET, SO_PRIORITY,
1644+
(char *)&so_priority, sizeof(so_priority));
1645+
if (ret) {
1646+
pr_err("failed to set SO_PRIORITY sock opt %d\n", ret);
1647+
goto err_sock;
1648+
}
1649+
}
1650+
16251651
ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr,
16261652
sizeof(port->addr));
16271653
if (ret) {

0 commit comments

Comments
 (0)