From: Hannes Reinecke <hare@suse.de>
To: Li Feng <fengli@smartx.com>, Keith Busch <kbusch@kernel.org>,
Jens Axboe <axboe@fb.com>, 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: lifeng1519@gmail.com
Subject: Re: [PATCH v2] nvme/tcp: Add support to set the tcp worker cpu affinity
Date: Fri, 14 Apr 2023 10:36:41 +0200 [thread overview]
Message-ID: <94d6a76c-8ad1-bda1-6336-e9f5fa3a6168@suse.de> (raw)
In-Reply-To: <20230413132941.2489795-1-fengli@smartx.com>
On 4/13/23 15:29, Li Feng wrote:
> The default worker affinity policy is using all online cpus, e.g. from 0
> to N-1. However, some cpus are busy for other jobs, then the nvme-tcp will
> have a bad performance.
>
> This patch adds a module parameter to set the cpu affinity for the nvme-tcp
> socket worker threads. The parameter is a comma separated list of CPU
> numbers. The list is parsed and the resulting cpumask is used to set the
> affinity of the socket worker threads. If the list is empty or the
> parsing fails, the default affinity is used.
>
> Signed-off-by: Li Feng <fengli@smartx.com>
> ---
>
> V2 - Fix missing static reported by lkp
>
> drivers/nvme/host/tcp.c | 54 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index 49c9e7bc9116..47748de5159b 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -31,6 +31,18 @@ static int so_priority;
> module_param(so_priority, int, 0644);
> MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");
>
> +/* Support for specifying the CPU affinity for the nvme-tcp socket worker
> + * threads. This is a comma separated list of CPU numbers. The list is
> + * parsed and the resulting cpumask is used to set the affinity of the
> + * socket worker threads. If the list is empty or the parsing fails, the
> + * default affinity is used.
> + */
> +static char *cpu_affinity_list;
> +module_param(cpu_affinity_list, charp, 0644);
> +MODULE_PARM_DESC(cpu_affinity_list, "nvme tcp socket worker cpu affinity list");
> +
> +static struct cpumask cpu_affinity_mask;
> +
> #ifdef CONFIG_DEBUG_LOCK_ALLOC
> /* lockdep can detect a circular dependency of the form
> * sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock
> @@ -1483,6 +1495,41 @@ static bool nvme_tcp_poll_queue(struct nvme_tcp_queue *queue)
> ctrl->io_queues[HCTX_TYPE_POLL];
> }
>
> +static ssize_t update_cpu_affinity(const char *buf)
> +{
> + cpumask_var_t new_value;
> + cpumask_var_t dst_value;
> + int err = 0;
> +
> + if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
> + return -ENOMEM;
> +
> + err = bitmap_parselist(buf, cpumask_bits(new_value), nr_cpumask_bits);
> + if (err)
> + goto free_new_cpumask;
> +
> + if (!zalloc_cpumask_var(&dst_value, GFP_KERNEL)) {
> + err = -ENOMEM;
> + goto free_new_cpumask;
> + }
> +
> + /*
> + * If the new_value does not have any intersection with the cpu_online_mask,
> + * the dst_value will be empty, then keep the cpu_affinity_mask as cpu_online_mask.
> + */
> + if (cpumask_and(dst_value, new_value, cpu_online_mask))
> + cpu_affinity_mask = *dst_value;
> +
> + free_cpumask_var(dst_value);
> +
> +free_new_cpumask:
> + free_cpumask_var(new_value);
> + if (err)
> + pr_err("failed to update cpu affinity mask, bad affinity list [%s], err %d\n",
> + buf, err);
> + return err;
> +}
> +
> static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
> {
> struct nvme_tcp_ctrl *ctrl = queue->ctrl;
> @@ -1496,7 +1543,12 @@ 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 (!cpu_affinity_list || update_cpu_affinity(cpu_affinity_list) != 0) {
> + // Set the default cpu_affinity_mask to cpu_online_mask
> + cpu_affinity_mask = *cpu_online_mask;
> + }
> + queue->io_cpu = cpumask_next_wrap(n - 1, &cpu_affinity_mask, -1, false);
> }
>
> static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid)
I am not in favour of this.
NVMe-over-Fabrics has _virtual_ queues, which really have no
relationship to the underlying hardware.
So trying to be clever here by tacking queues to CPUs sort of works if
you have one subsystem to talk to, but if you have several where each
exposes a _different_ number of queues you end up with a quite
suboptimal setting (ie you rely on the resulting cpu sets to overlap,
but there is no guarantee that they do).
Rather leave it to the hardware to sort things out, and rely on the
blk-mq CPU mapping to get I/O aligned to CPUs.
Cheers,
Hannes
next prev parent reply other threads:[~2023-04-14 8:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 6:23 [PATCH] " Li Feng
2023-04-13 6:33 ` Li Feng
2023-04-13 12:53 ` kernel test robot
2023-04-17 13:45 ` Sagi Grimberg
2023-04-18 3:39 ` Li Feng
2023-04-19 9:32 ` Sagi Grimberg
2023-04-25 8:32 ` Li Feng
2023-04-26 11:31 ` Hannes Reinecke
2023-04-27 12:21 ` Sagi Grimberg
2023-04-27 14:36 ` Ming Lei
2023-04-27 12:11 ` Sagi Grimberg
2023-04-18 3:58 ` Chaitanya Kulkarni
2023-04-18 4:21 ` Li Feng
2023-04-18 9:20 ` Li Feng
2023-04-13 13:29 ` [PATCH v2] " Li Feng
2023-04-14 8:36 ` Hannes Reinecke [this message]
2023-04-14 9:35 ` Li Feng
2023-04-15 20:21 ` Chaitanya Kulkarni
2023-04-15 21:06 ` David Laight
2023-04-17 3:31 ` Li Feng
2023-04-17 6:27 ` Hannes Reinecke
2023-04-17 8:32 ` Li Feng
2023-04-17 7:37 ` Ming Lei
2023-04-17 7:50 ` Li Feng
2023-04-17 8:05 ` Ming Lei
2023-04-17 13:33 ` Sagi Grimberg
2023-04-18 3:29 ` Li Feng
2023-04-18 4:33 ` Ming Lei
2023-04-18 9:32 ` Sagi Grimberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94d6a76c-8ad1-bda1-6336-e9f5fa3a6168@suse.de \
--to=hare@suse.de \
--cc=axboe@fb.com \
--cc=fengli@smartx.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=lifeng1519@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®