[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240806-isolcpus-io-queues-v3-10-da0eecfeaf8b@suse.de>
Date: Tue, 06 Aug 2024 14:06:42 +0200
From: Daniel Wagner <dwagner@...e.de>
To: Jens Axboe <axboe@...nel.dk>, Keith Busch <kbusch@...nel.org>,
Sagi Grimberg <sagi@...mberg.me>, Thomas Gleixner <tglx@...utronix.de>,
Christoph Hellwig <hch@....de>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
John Garry <john.g.garry@...cle.com>, "Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
Kashyap Desai <kashyap.desai@...adcom.com>,
Sumit Saxena <sumit.saxena@...adcom.com>,
Shivasharan S <shivasharan.srikanteshwara@...adcom.com>,
Chandrakanth patil <chandrakanth.patil@...adcom.com>,
Sathya Prakash Veerichetty <sathya.prakash@...adcom.com>,
Suganath Prabu Subramani <suganath-prabu.subramani@...adcom.com>,
Nilesh Javali <njavali@...vell.com>, GR-QLogic-Storage-Upstream@...vell.com,
Jonathan Corbet <corbet@....net>
Cc: Frederic Weisbecker <frederic@...nel.org>, Mel Gorman <mgorman@...e.de>,
Hannes Reinecke <hare@...e.de>,
Sridhar Balaraman <sbalaraman@...allelwireless.com>,
"brookxu.cn" <brookxu.cn@...il.com>, Ming Lei <ming.lei@...hat.com>,
linux-kernel@...r.kernel.org, linux-block@...r.kernel.org,
linux-nvme@...ts.infradead.org, linux-scsi@...r.kernel.org,
virtualization@...ts.linux.dev, megaraidlinux.pdl@...adcom.com,
mpi3mr-linuxdrv.pdl@...adcom.com, MPT-FusionLinux.pdl@...adcom.com,
storagedev@...rochip.com, linux-doc@...r.kernel.org,
Daniel Wagner <dwagner@...e.de>
Subject: [PATCH v3 10/15] blk-mq: add number of queue calc helper
Multiqueue devices should only allocate queues for the housekeeping CPUs
when isolcpus=io_queue is set. This avoids that the isolated CPUs get
disturbed with OS workload.
Add two variants of helpers which calculates the correct number of
queues which should be used. The need for two variants is necessary
because some drivers calculate their max number of queues based on the
possible CPU mask, others based on the online CPU mask.
Signed-off-by: Daniel Wagner <dwagner@...e.de>
---
block/blk-mq-cpumap.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/blk-mq.h | 2 ++
2 files changed, 47 insertions(+)
diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 7037a2dc485f..c1277763aeeb 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -11,10 +11,55 @@
#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"
+static unsigned int blk_mq_num_queues(const struct cpumask *mask,
+ unsigned int max_queues)
+{
+ unsigned int num;
+
+ if (housekeeping_enabled(HK_TYPE_IO_QUEUE))
+ mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+
+ num = cpumask_weight(mask);
+ return min_not_zero(num, max_queues);
+}
+
+/**
+ * blk_mq_num_possible_queues - Calc nr of queues for multiqueue devices
+ * @max_queues: The maximal number of queues the hardware/driver
+ * supports. If max_queues is 0, the argument is
+ * ignored.
+ *
+ * Calculate the number of queues which should be used for a multiqueue
+ * device based on the number of possible cpu. The helper is considering
+ * isolcpus settings.
+ */
+unsigned int blk_mq_num_possible_queues(unsigned int max_queues)
+{
+ return blk_mq_num_queues(cpu_possible_mask, max_queues);
+}
+EXPORT_SYMBOL_GPL(blk_mq_num_possible_queues);
+
+/**
+ * blk_mq_num_online_queues - Calc nr of queues for multiqueue devices
+ * @max_queues: The maximal number of queues the hardware/driver
+ * supports. If max_queues is 0, the argument is
+ * ignored.
+ *
+ * Calculate the number of queues which should be used for a multiqueue
+ * device based on the number of online cpus. The helper is considering
+ * isolcpus settings.
+ */
+unsigned int blk_mq_num_online_queues(unsigned int max_queues)
+{
+ return blk_mq_num_queues(cpu_online_mask, max_queues);
+}
+EXPORT_SYMBOL_GPL(blk_mq_num_online_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 cfc96d6a3136..bcd5ef712af7 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -931,6 +931,8 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
typedef const struct cpumask *(get_queue_affinty_fn)(void *dev_data,
int dev_off, int queue_idx);
+unsigned int blk_mq_num_possible_queues(unsigned int max_queues);
+unsigned int blk_mq_num_online_queues(unsigned int max_queues);
void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
void blk_mq_dev_map_queues(struct blk_mq_queue_map *qmap,
void *dev_data, int dev_off,
--
2.46.0
Powered by blists - more mailing lists