mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs
@ 2024-03-13 12:38 Li Feng
  2024-03-13 12:38 ` [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq Li Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Li Feng @ 2024-03-13 12:38 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	open list:NVM EXPRESS DRIVER, open list
  Cc: Anton.Gavriliuk, Li Feng

Make the workqueue userspace visible for easy viewing and configuration.

Signed-off-by: Li Feng <fengli@smartx.com>
---
 drivers/nvme/host/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index a6d596e05602..2ec1186db0a3 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -2800,7 +2800,7 @@ static int __init nvme_tcp_init_module(void)
 	BUILD_BUG_ON(sizeof(struct nvme_tcp_term_pdu) != 24);
 
 	nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq",
-			WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
+			WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS, 0);
 	if (!nvme_tcp_wq)
 		return -ENOMEM;
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq
  2024-03-13 12:38 [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Li Feng
@ 2024-03-13 12:38 ` Li Feng
  2024-03-13 21:07   ` Anton Gavriliuk
  2024-03-17  7:31   ` Sagi Grimberg
  2024-03-17  7:30 ` [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Sagi Grimberg
  2024-03-18 20:41 ` Keith Busch
  2 siblings, 2 replies; 7+ messages in thread
From: Li Feng @ 2024-03-13 12:38 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	open list:NVM EXPRESS DRIVER, open list
  Cc: Anton.Gavriliuk, Li Feng

The default nvme_tcp_wq will use all CPUs to process tasks. Sometimes it is
necessary to set CPU affinity to improve performance.

A new module parameter wq_unbound is added here. If set to true, users can
configure cpu affinity through
/sys/devices/virtual/workqueue/nvme_tcp_wq/cpumask.

Signed-off-by: Li Feng <fengli@smartx.com>
---
 drivers/nvme/host/tcp.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 2ec1186db0a3..34a882b2ec53 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -36,6 +36,14 @@ static int so_priority;
 module_param(so_priority, int, 0644);
 MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");
 
+/*
+ * Use the unbound workqueue for nvme_tcp_wq, then we can set the cpu affinity
+ * from sysfs.
+ */
+static bool wq_unbound;
+module_param(wq_unbound, bool, 0644);
+MODULE_PARM_DESC(wq_unbound, "Use unbound workqueue for nvme-tcp IO context (default false)");
+
 /*
  * TLS handshake timeout
  */
@@ -1551,7 +1559,10 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
 	else if (nvme_tcp_poll_queue(queue))
 		n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] -
 				ctrl->io_queues[HCTX_TYPE_READ] - 1;
-	queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
+	if (wq_unbound)
+		queue->io_cpu = WORK_CPU_UNBOUND;
+	else
+		queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
 }
 
 static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid)
@@ -2790,6 +2801,8 @@ static struct nvmf_transport_ops nvme_tcp_transport = {
 
 static int __init nvme_tcp_init_module(void)
 {
+	unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS;
+
 	BUILD_BUG_ON(sizeof(struct nvme_tcp_hdr) != 8);
 	BUILD_BUG_ON(sizeof(struct nvme_tcp_cmd_pdu) != 72);
 	BUILD_BUG_ON(sizeof(struct nvme_tcp_data_pdu) != 24);
@@ -2799,8 +2812,10 @@ static int __init nvme_tcp_init_module(void)
 	BUILD_BUG_ON(sizeof(struct nvme_tcp_icresp_pdu) != 128);
 	BUILD_BUG_ON(sizeof(struct nvme_tcp_term_pdu) != 24);
 
-	nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq",
-			WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS, 0);
+	if (wq_unbound)
+		wq_flags |= WQ_UNBOUND;
+
+	nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq", wq_flags, 0);
 	if (!nvme_tcp_wq)
 		return -ENOMEM;
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq
  2024-03-13 12:38 ` [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq Li Feng
@ 2024-03-13 21:07   ` Anton Gavriliuk
  2024-03-17  7:31   ` Sagi Grimberg
  1 sibling, 0 replies; 7+ messages in thread
From: Anton Gavriliuk @ 2024-03-13 21:07 UTC (permalink / raw)
  To: Li Feng, Keith Busch, Jens Axboe, Christoph Hellwig,
	Sagi Grimberg, open list:NVM EXPRESS DRIVER, open list

Thanks, it works.

Will it be added by default to the 6.9 mainline ?

Anton

-----Original Message-----
From: Li Feng <fengli@smartx.com>
Sent: Wednesday, March 13, 2024 2:38 PM
To: Keith Busch <kbusch@kernel.org>; Jens Axboe <axboe@kernel.dk>; Christoph Hellwig <hch@lst.de>; Sagi Grimberg <sagi@grimberg.me>; open list:NVM EXPRESS DRIVER <linux-nvme@lists.infradead.org>; open list <linux-kernel@vger.kernel.org>
Cc: Anton Gavriliuk <Anton.Gavriliuk@hpe.ua>; Li Feng <fengli@smartx.com>
Subject: [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq

The default nvme_tcp_wq will use all CPUs to process tasks. Sometimes it is necessary to set CPU affinity to improve performance.

A new module parameter wq_unbound is added here. If set to true, users can configure cpu affinity through /sys/devices/virtual/workqueue/nvme_tcp_wq/cpumask.

Signed-off-by: Li Feng <fengli@smartx.com>
---
 drivers/nvme/host/tcp.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 2ec1186db0a3..34a882b2ec53 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -36,6 +36,14 @@ static int so_priority;  module_param(so_priority, int, 0644);  MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");

+/*
+ * Use the unbound workqueue for nvme_tcp_wq, then we can set the cpu
+affinity
+ * from sysfs.
+ */
+static bool wq_unbound;
+module_param(wq_unbound, bool, 0644);
+MODULE_PARM_DESC(wq_unbound, "Use unbound workqueue for nvme-tcp IO
+context (default false)");
+
 /*
  * TLS handshake timeout
  */
@@ -1551,7 +1559,10 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
        else if (nvme_tcp_poll_queue(queue))
                n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] -
                                ctrl->io_queues[HCTX_TYPE_READ] - 1;
-       queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
+       if (wq_unbound)
+               queue->io_cpu = WORK_CPU_UNBOUND;
+       else
+               queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
 }

 static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid) @@ -2790,6 +2801,8 @@ static struct nvmf_transport_ops nvme_tcp_transport = {

 static int __init nvme_tcp_init_module(void)  {
+       unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS;
+
        BUILD_BUG_ON(sizeof(struct nvme_tcp_hdr) != 8);
        BUILD_BUG_ON(sizeof(struct nvme_tcp_cmd_pdu) != 72);
        BUILD_BUG_ON(sizeof(struct nvme_tcp_data_pdu) != 24); @@ -2799,8 +2812,10 @@ static int __init nvme_tcp_init_module(void)
        BUILD_BUG_ON(sizeof(struct nvme_tcp_icresp_pdu) != 128);
        BUILD_BUG_ON(sizeof(struct nvme_tcp_term_pdu) != 24);

-       nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq",
-                       WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS, 0);
+       if (wq_unbound)
+               wq_flags |= WQ_UNBOUND;
+
+       nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq", wq_flags, 0);
        if (!nvme_tcp_wq)
                return -ENOMEM;

--
2.44.0

Anton

-----Original Message-----
From: Li Feng <fengli@smartx.com>
Sent: Wednesday, March 13, 2024 2:38 PM
To: Keith Busch <kbusch@kernel.org>; Jens Axboe <axboe@kernel.dk>; Christoph Hellwig <hch@lst.de>; Sagi Grimberg <sagi@grimberg.me>; open list:NVM EXPRESS DRIVER <linux-nvme@lists.infradead.org>; open list <linux-kernel@vger.kernel.org>
Cc: Anton Gavriliuk <Anton.Gavriliuk@hpe.ua>; Li Feng <fengli@smartx.com>
Subject: [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq

The default nvme_tcp_wq will use all CPUs to process tasks. Sometimes it is necessary to set CPU affinity to improve performance.

A new module parameter wq_unbound is added here. If set to true, users can configure cpu affinity through /sys/devices/virtual/workqueue/nvme_tcp_wq/cpumask.

Signed-off-by: Li Feng <fengli@smartx.com>
---
 drivers/nvme/host/tcp.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 2ec1186db0a3..34a882b2ec53 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -36,6 +36,14 @@ static int so_priority;  module_param(so_priority, int, 0644);  MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");

+/*
+ * Use the unbound workqueue for nvme_tcp_wq, then we can set the cpu
+affinity
+ * from sysfs.
+ */
+static bool wq_unbound;
+module_param(wq_unbound, bool, 0644);
+MODULE_PARM_DESC(wq_unbound, "Use unbound workqueue for nvme-tcp IO
+context (default false)");
+
 /*
  * TLS handshake timeout
  */
@@ -1551,7 +1559,10 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
        else if (nvme_tcp_poll_queue(queue))
                n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] -
                                ctrl->io_queues[HCTX_TYPE_READ] - 1;
-       queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
+       if (wq_unbound)
+               queue->io_cpu = WORK_CPU_UNBOUND;
+       else
+               queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
 }

 static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid) @@ -2790,6 +2801,8 @@ static struct nvmf_transport_ops nvme_tcp_transport = {

 static int __init nvme_tcp_init_module(void)  {
+       unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS;
+
        BUILD_BUG_ON(sizeof(struct nvme_tcp_hdr) != 8);
        BUILD_BUG_ON(sizeof(struct nvme_tcp_cmd_pdu) != 72);
        BUILD_BUG_ON(sizeof(struct nvme_tcp_data_pdu) != 24); @@ -2799,8 +2812,10 @@ static int __init nvme_tcp_init_module(void)
        BUILD_BUG_ON(sizeof(struct nvme_tcp_icresp_pdu) != 128);
        BUILD_BUG_ON(sizeof(struct nvme_tcp_term_pdu) != 24);

-       nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq",
-                       WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS, 0);
+       if (wq_unbound)
+               wq_flags |= WQ_UNBOUND;
+
+       nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq", wq_flags, 0);
        if (!nvme_tcp_wq)
                return -ENOMEM;

--
2.44.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs
  2024-03-13 12:38 [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Li Feng
  2024-03-13 12:38 ` [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq Li Feng
@ 2024-03-17  7:30 ` Sagi Grimberg
  2024-03-18 20:41 ` Keith Busch
  2 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2024-03-17  7:30 UTC (permalink / raw)
  To: Li Feng, Keith Busch, Jens Axboe, Christoph Hellwig,
	open list:NVM EXPRESS DRIVER, open list
  Cc: Anton.Gavriliuk

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq
  2024-03-13 12:38 ` [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq Li Feng
  2024-03-13 21:07   ` Anton Gavriliuk
@ 2024-03-17  7:31   ` Sagi Grimberg
  2024-03-18  8:56     ` Li Feng
  1 sibling, 1 reply; 7+ messages in thread
From: Sagi Grimberg @ 2024-03-17  7:31 UTC (permalink / raw)
  To: Li Feng, Keith Busch, Jens Axboe, Christoph Hellwig,
	open list:NVM EXPRESS DRIVER, open list
  Cc: Anton.Gavriliuk

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

Does this get you the functionality you want Li?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq
  2024-03-17  7:31   ` Sagi Grimberg
@ 2024-03-18  8:56     ` Li Feng
  0 siblings, 0 replies; 7+ messages in thread
From: Li Feng @ 2024-03-18  8:56 UTC (permalink / raw)
  To: Sagi Grimberg
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig,
	open list:NVM EXPRESS DRIVER, linux-kernel, Anton Gavriliuk



> On Mar 17, 2024, at 15:31, Sagi Grimberg <sagi@grimberg.me> wrote:
> 
> Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
> 
> Does this get you the functionality you want Li?

Yes, it meets my performance needs.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs
  2024-03-13 12:38 [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Li Feng
  2024-03-13 12:38 ` [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq Li Feng
  2024-03-17  7:30 ` [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Sagi Grimberg
@ 2024-03-18 20:41 ` Keith Busch
  2 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2024-03-18 20:41 UTC (permalink / raw)
  To: Li Feng
  Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	open list:NVM EXPRESS DRIVER, open list, Anton.Gavriliuk

On Wed, Mar 13, 2024 at 08:38:09PM +0800, Li Feng wrote:
> Make the workqueue userspace visible for easy viewing and configuration.

Thanks, applied to nvme-6.9.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-18 20:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-13 12:38 [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Li Feng
2024-03-13 12:38 ` [PATCH v2 2/2] nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq Li Feng
2024-03-13 21:07   ` Anton Gavriliuk
2024-03-17  7:31   ` Sagi Grimberg
2024-03-18  8:56     ` Li Feng
2024-03-17  7:30 ` [PATCH v2 1/2] nvme-tcp: Export the nvme_tcp_wq to sysfs Sagi Grimberg
2024-03-18 20:41 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®