diff mbox series

[v2,1/3] blk-mq: add blk_mq_num_possible_queues helper

Message ID 20240627-isolcpus-io-queues-v2-1-26a32e3c4f75@suse.de (mailing list archive)
State New, archived
Headers show
Series nvme-pci: honor isolcpus configuration | expand

Commit Message

Daniel Wagner June 27, 2024, 2:10 p.m. UTC
Multi queue devices which use managed IRQs should only allocate queues
for the housekeeping CPUs when isolcpus is set. This avoids that the
isolated CPUs get disturbed with OS workload.

Add a helper which calculates the correct number of queues which should
be used.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 block/blk-mq-cpumap.c  | 20 ++++++++++++++++++++
 include/linux/blk-mq.h |  1 +
 2 files changed, 21 insertions(+)

Comments

Christoph Hellwig June 28, 2024, 6:02 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Hannes Reinecke June 28, 2024, 6:23 a.m. UTC | #2
On 6/27/24 16:10, Daniel Wagner wrote:
> Multi queue devices which use managed IRQs should only allocate queues
> for the housekeeping CPUs when isolcpus is set. This avoids that the
> isolated CPUs get disturbed with OS workload.
> 
> Add a helper which calculates the correct number of queues which should
> be used.
> 
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
>   block/blk-mq-cpumap.c  | 20 ++++++++++++++++++++
>   include/linux/blk-mq.h |  1 +
>   2 files changed, 21 insertions(+)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Sagi Grimberg June 30, 2024, 8:24 a.m. UTC | #3
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
diff mbox series

Patch

diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 9638b25fd521..9717e323f308 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -11,10 +11,30 @@ 
 #include <linux/smp.h>
 #include <linux/cpu.h>
 #include <linux/group_cpus.h>
+#include <linux/sched/isolation.h>
 
 #include "blk.h"
 #include "blk-mq.h"
 
+/**
+ * blk_mq_num_possible_queues - Calc nr of queues for managed devices
+ *
+ * Calculate the number of queues which should be used for a multiqueue
+ * device which uses the managed IRQ API. The helper is considering
+ * isolcpus settings.
+ */
+unsigned int blk_mq_num_possible_queues(void)
+{
+	const struct cpumask *hk_mask;
+
+	hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ);
+	if (!cpumask_empty(hk_mask))
+		return cpumask_weight(hk_mask);
+
+	return num_possible_cpus();
+}
+EXPORT_SYMBOL_GPL(blk_mq_num_possible_queues);
+
 void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
 {
 	const struct cpumask *masks;
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 89ba6b16fe8b..2105cc78ca67 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -900,6 +900,7 @@  void blk_mq_freeze_queue_wait(struct request_queue *q);
 int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
 				     unsigned long timeout);
 
+unsigned int blk_mq_num_possible_queues(void);
 void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
 void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);