Skip to contentSkip to conversation

blk-mq: fix selecting software ctx for request

PATCH Ming Lei 1 participant 2 messages Feb 3, 2020 2 messages not in the archive Block layer

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ming Lei

author
#1 lore raw
Quoted 10 lines · Hillf Danton

Select the current cpu if it's mapped to hardware to make helpers like blk_mq_rq_cpu() return correct value.

---

block/blk-mq.c struct request *blk_mq_alloc_request_hct · line 460

Quoted 8 lines
block/blk-mq.c +4 -1
@@ -454,7 +454,10 @@ struct request *blk_mq_alloc_request_hct
 		blk_queue_exit(q);
 		return ERR_PTR(-EXDEV);
 	}
-	cpu = cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask);
+	cpu = raw_smp_processor_id();
+	if (!cpumask_test_cpu(cpu, alloc_data.hctx->cpumask))
+		cpu = cpumask_first_and(alloc_data.hctx->cpumask,
+						cpu_online_mask);

How can you know if there is any online CPU available for this hctx?

block/blk-mq.c struct request *blk_mq_alloc_request_hct · line 463

Quoted 4 lines
block/blk-mq.c +0 -0
 	alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
 
 	rq = blk_mq_get_request(q, NULL, &alloc_data);

It is really one NVMe specific issue, see the following discussion:

https://lore.kernel.org/linux-block/[email protected]/#r

Thanks,
Ming

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#3 lore raw
Quoted 26 lines · Hillf Danton

Hi Ming

Quoted 8 lines · On Mon, 3 Feb 2020 17:16:02 +0800 Ming Lei wrote:
Quoted 7 lines · Hillf Danton

Select the current cpu if it's mapped to hardware to make helpers like blk_mq_rq_cpu() return correct value.

---

Quoted 13 lines

block/blk-mq.c struct request *blk_mq_alloc_request_hct · line 460

Quoted 11 lines
block/blk-mq.c +4 -1
@@ -454,7 +454,10 @@ struct request *blk_mq_alloc_request_hct
 		blk_queue_exit(q);
 		return ERR_PTR(-EXDEV);
 	}
-	cpu = cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask);
+	cpu = raw_smp_processor_id();
+	if (!cpumask_test_cpu(cpu, alloc_data.hctx->cpumask))
+		cpu = cpumask_first_and(alloc_data.hctx->cpumask,
+						cpu_online_mask);

How can you know if there is any online CPU available for this hctx?

Quoted 1 line

I don't except for the current cpu.

The current CPU may not belong to hctx->cpumask for blk_mq_alloc_request_hctx(), that is why I think this API is very weird.

Thanks,
Ming