From: Ming Lei <ming.lei@redhat.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
Stefan Haberland <sth@linux.vnet.ibm.com>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] blk-mq: only run mapped hw queues in blk_mq_run_hw_queues()
Date: Fri, 6 Apr 2018 16:41:15 +0800 [thread overview]
Message-ID: <20180406084106.GA8940@ming.t460p> (raw)
In-Reply-To: <3a72f42f-db90-6092-5e1b-0579d2095daa@de.ibm.com>
On Thu, Apr 05, 2018 at 07:39:56PM +0200, Christian Borntraeger wrote:
>
>
> On 04/05/2018 06:11 PM, Ming Lei wrote:
> >>
> >> Could you please apply the following patch and provide the dmesg boot log?
> >
> > And please post out the 'lscpu' log together from the test machine too.
>
> attached.
>
> As I said before this seems to go way with CONFIG_NR_CPUS=64 or smaller.
> We have 282 nr_cpu_ids here (max 141CPUs on that z13 with SMT2) but only 8 Cores
> == 16 threads.
OK, thanks!
The most weird thing is that hctx->next_cpu is computed as 512 since
nr_cpu_id is 282, and hctx->next_cpu should have pointed to one of
possible CPU.
Looks like it is a s390 specific issue, since I can setup one queue
which has same mapping with yours:
- nr_cpu_id is 282
- CPU 0~15 is online
- 64 queues null_blk
- still run all hw queues in .complete handler
But can't reproduce this issue at all.
So please test the following patch, which may tell us why hctx->next_cpu
is computed wrong:
---
diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 9f8cffc8a701..638ab5c11b3c 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -14,13 +14,12 @@
#include "blk.h"
#include "blk-mq.h"
+/*
+ * Given there isn't CPU hotplug handler in blk-mq, map all CPUs to
+ * queues even it isn't present yet.
+ */
static int cpu_to_queue_index(unsigned int nr_queues, const int cpu)
{
- /*
- * Non present CPU will be mapped to queue index 0.
- */
- if (!cpu_present(cpu))
- return 0;
return cpu % nr_queues;
}
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 90838e998f66..9b130e4b87df 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1343,6 +1343,13 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
hctx_unlock(hctx, srcu_idx);
}
+static void check_next_cpu(int next_cpu, const char *str1, const char *str2)
+{
+ if (next_cpu > nr_cpu_ids)
+ printk_ratelimited("wrong next_cpu %d, %s, %s\n",
+ next_cpu, str1, str2);
+}
+
/*
* It'd be great if the workqueue API had a way to pass
* in a mask and had some smarts for more clever placement.
@@ -1352,26 +1359,29 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
{
bool tried = false;
+ int next_cpu = hctx->next_cpu;
if (hctx->queue->nr_hw_queues == 1)
return WORK_CPU_UNBOUND;
if (--hctx->next_cpu_batch <= 0) {
- int next_cpu;
select_cpu:
- next_cpu = cpumask_next_and(hctx->next_cpu, hctx->cpumask,
+ next_cpu = cpumask_next_and(next_cpu, hctx->cpumask,
cpu_online_mask);
- if (next_cpu >= nr_cpu_ids)
+ check_next_cpu(next_cpu, __func__, "next_and");
+ if (next_cpu >= nr_cpu_ids) {
next_cpu = cpumask_first_and(hctx->cpumask,cpu_online_mask);
+ check_next_cpu(next_cpu, __func__, "first_and");
+ }
/*
* No online CPU is found, so have to make sure hctx->next_cpu
* is set correctly for not breaking workqueue.
*/
- if (next_cpu >= nr_cpu_ids)
- hctx->next_cpu = cpumask_first(hctx->cpumask);
- else
- hctx->next_cpu = next_cpu;
+ if (next_cpu >= nr_cpu_ids) {
+ next_cpu = cpumask_first(hctx->cpumask);
+ check_next_cpu(next_cpu, __func__, "first");
+ }
hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
}
@@ -1379,7 +1389,7 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
* Do unbound schedule if we can't find a online CPU for this hctx,
* and it should only happen in the path of handling CPU DEAD.
*/
- if (!cpu_online(hctx->next_cpu)) {
+ if (!cpu_online(next_cpu)) {
if (!tried) {
tried = true;
goto select_cpu;
@@ -1392,7 +1402,9 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
hctx->next_cpu_batch = 1;
return WORK_CPU_UNBOUND;
}
- return hctx->next_cpu;
+
+ hctx->next_cpu = next_cpu;
+ return next_cpu;
}
static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async,
@@ -2408,6 +2420,8 @@ static void blk_mq_map_swqueue(struct request_queue *q)
mutex_unlock(&q->sysfs_lock);
queue_for_each_hw_ctx(q, hctx, i) {
+ int next_cpu;
+
/*
* If no software queues are mapped to this hardware queue,
* disable it and free the request entries.
@@ -2437,8 +2451,10 @@ static void blk_mq_map_swqueue(struct request_queue *q)
/*
* Initialize batch roundrobin counts
*/
- hctx->next_cpu = cpumask_first_and(hctx->cpumask,
+ next_cpu = cpumask_first_and(hctx->cpumask,
cpu_online_mask);
+ check_next_cpu(next_cpu, __func__, "first_and");
+ hctx->next_cpu = next_cpu;
hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
}
}
Thanks,
Ming
next prev parent reply other threads:[~2018-04-06 8:41 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-28 1:20 [PATCH] blk-mq: only run mapped hw queues in blk_mq_run_hw_queues() Ming Lei
2018-03-28 3:22 ` Jens Axboe
2018-03-28 7:45 ` Christian Borntraeger
2018-03-28 14:38 ` Jens Axboe
2018-03-28 14:53 ` Jens Axboe
2018-03-28 15:38 ` Christian Borntraeger
2018-03-28 15:26 ` Ming Lei
2018-03-28 15:36 ` Christian Borntraeger
2018-03-28 15:44 ` Christian Borntraeger
2018-03-29 2:00 ` Ming Lei
2018-03-29 7:23 ` Christian Borntraeger
2018-03-29 9:09 ` Christian Borntraeger
2018-03-29 9:40 ` Ming Lei
2018-03-29 10:10 ` Christian Borntraeger
2018-03-29 10:48 ` Ming Lei
2018-03-29 10:49 ` Christian Borntraeger
2018-03-29 11:43 ` Ming Lei
2018-03-29 11:49 ` Christian Borntraeger
2018-03-30 2:53 ` Ming Lei
2018-04-04 8:18 ` Christian Borntraeger
2018-04-05 16:05 ` Ming Lei
2018-04-05 16:11 ` Ming Lei
2018-04-05 17:39 ` Christian Borntraeger
2018-04-05 17:43 ` Christian Borntraeger
2018-04-06 8:41 ` Ming Lei [this message]
2018-04-06 8:51 ` Christian Borntraeger
2018-04-06 8:53 ` Christian Borntraeger
2018-04-06 9:23 ` Ming Lei
2018-04-06 10:19 ` Christian Borntraeger
2018-04-06 13:41 ` Ming Lei
2018-04-06 14:26 ` Christian Borntraeger
2018-04-06 14:58 ` Ming Lei
2018-04-06 15:11 ` Christian Borntraeger
2018-04-06 15:40 ` Ming Lei
2018-04-06 11:37 ` Christian Borntraeger
2018-04-06 8:35 ` Christian Borntraeger
2018-03-29 9:52 ` Ming Lei
2018-03-29 10:11 ` Christian Borntraeger
2018-03-29 10:12 ` Christian Borntraeger
2018-03-29 10:13 ` Ming Lei
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=20180406084106.GA8940@ming.t460p \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=borntraeger@de.ibm.com \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=sth@linux.vnet.ibm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.