Skip to contentSkip to conversation

virtio-blk: add num_request_queues module parameter

PATCH In review Max Gurtovoy 5 participants 17 messages Sep 2, 2021 – Oct 24, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 virtio-blk: add num_request_queues module parameter

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
- renamed num_io_queues to num_request_queues (from Stefan)
- added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
- use param_set_uint_minmax (from Christoph)
- added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
 drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +20 -1
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
 /* The maximum number of sg elements that fit into a virtqueue */
 #define VIRTIO_BLK_MAX_SG_ELEMS 32768
 
+static int virtblk_queue_count_set(const char *val,
+		const struct kernel_param *kp)
+{
+	return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+
+static const struct kernel_param_ops queue_count_ops = {
+	.set = virtblk_queue_count_set,
+	.get = param_get_uint,
+};
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+
 static int major;
 static DEFINE_IDA(vd_index_ida);
 
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
 	if (err)
 		num_vqs = 1;
 
-	num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+	num_vqs = min_t(unsigned int,
+			min_not_zero(num_request_queues, nr_cpu_ids),
+			num_vqs);
 
 	vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
 	if (!vblk->vqs)
Signature · 1 line
2.18.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 53 lines

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
- renamed num_io_queues to num_request_queues (from Stefan)
- added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
- use param_set_uint_minmax (from Christoph)
- added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
 drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +17 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
 /* The maximum number of sg elements that fit into a virtqueue */
 #define VIRTIO_BLK_MAX_SG_ELEMS 32768
 
+static int virtblk_queue_count_set(const char *val,
+               const struct kernel_param *kp)
+{
+       return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+
+static const struct kernel_param_ops queue_count_ops = {
+       .set = virtblk_queue_count_set,
+       .get = param_get_uint,
+};
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+               0644);
+MODULE_PARM_DESC(num_request_queues,
+                "Number of request queues to use for blk device. Should > 0");
+
 static int major;
 static DEFINE_IDA(vd_index_ida);
 
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
        if (err)

drivers/block/virtio_blk.c static int init_vq(struct virtio_blk *vblk)

Quoted 10 lines
drivers/block/virtio_blk.c +3 -2
                num_vqs = 1;
 
-       num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+       num_vqs = min_t(unsigned int,
+                       min_not_zero(num_request_queues, nr_cpu_ids),
+                       num_vqs);
 
        vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
        if (!vblk->vqs)
--
#2 lore raw
In reply to Max Gurtovoy
Quoted 38 lines · Max Gurtovoy

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
- renamed num_io_queues to num_request_queues (from Stefan)
- added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
- use param_set_uint_minmax (from Christoph)
- added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
 drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +7 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
 /* The maximum number of sg elements that fit into a virtqueue */
 #define VIRTIO_BLK_MAX_SG_ELEMS 32768
 
+static int virtblk_queue_count_set(const char *val,
+		const struct kernel_param *kp)
+{
+	return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+
+static const struct kernel_param_ops queue_count_ops = {

drivers/block/virtio_blk.c line 43

Quoted 10 lines
drivers/block/virtio_blk.c +10 -0
+	.set = virtblk_queue_count_set,
+	.get = param_get_uint,
+};
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Thanks

#3 lore raw
Quoted 8 lines · Leon Romanovsky

drivers/block/virtio_blk.c line 43

Quoted 6 lines
drivers/block/virtio_blk.c +6 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

Quoted 4 lines

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Thanks

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

#4 lore raw
Quoted 15 lines · Chaitanya Kulkarni
Quoted 13 lines · Leon Romanovsky
Quoted 8 lines
(quoted diff) +2 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, 

&num_request_queues,
+        0644);
+MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Quoted 10 lines
Quoted 1 line

Thanks

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

You have many ways to overcome this issue.

For example:

# ls -l /sys/block/vda/mq/
drwxr-xr-x 18 root root 0 Sep  5 12:14 0
drwxr-xr-x 18 root root 0 Sep  5 12:14 1
drwxr-xr-x 18 root root 0 Sep  5 12:14 2
drwxr-xr-x 18 root root 0 Sep  5 12:14 3
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/unbind
# echo 8 > /sys/module/virtio_blk/parameters/num_request_queues
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/bind
# ls -l /sys/block/vda/mq/
drwxr-xr-x 10 root root 0 Sep  5 12:17 0
drwxr-xr-x 10 root root 0 Sep  5 12:17 1
drwxr-xr-x 10 root root 0 Sep  5 12:17 2
drwxr-xr-x 10 root root 0 Sep  5 12:17 3
drwxr-xr-x 10 root root 0 Sep  5 12:17 4
drwxr-xr-x 10 root root 0 Sep  5 12:17 5
drwxr-xr-x 10 root root 0 Sep  5 12:17 6
drwxr-xr-x 10 root root 0 Sep  5 12:17 7

-Max.

#5 lore raw
Quoted 38 lines · Max Gurtovoy
Quoted 18 lines · Chaitanya Kulkarni
Quoted 10 lines · Leon Romanovsky
Quoted 8 lines
(quoted diff) +2 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops,

&num_request_queues,
+        0644); +MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

Quoted 4 lines

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Thanks

Quoted 8 lines

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

You have many ways to overcome this issue.

For example:

# ls -l /sys/block/vda/mq/
drwxr-xr-x 18 root root 0 Sep  5 12:14 0
drwxr-xr-x 18 root root 0 Sep  5 12:14 1
drwxr-xr-x 18 root root 0 Sep  5 12:14 2
drwxr-xr-x 18 root root 0 Sep  5 12:14 3
Quoted 3 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/unbind
# echo 8 > /sys/module/virtio_blk/parameters/num_request_queues

This is global to all virtio-blk devices.

Quoted 16 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/bind
# ls -l /sys/block/vda/mq/
drwxr-xr-x 10 root root 0 Sep  5 12:17 0
drwxr-xr-x 10 root root 0 Sep  5 12:17 1
drwxr-xr-x 10 root root 0 Sep  5 12:17 2
drwxr-xr-x 10 root root 0 Sep  5 12:17 3
drwxr-xr-x 10 root root 0 Sep  5 12:17 4
drwxr-xr-x 10 root root 0 Sep  5 12:17 5
drwxr-xr-x 10 root root 0 Sep  5 12:17 6
drwxr-xr-x 10 root root 0 Sep  5 12:17 7

-Max.

#6 lore raw
Quoted 36 lines · Leon Romanovsky
Quoted 35 lines · Max Gurtovoy
Quoted 14 lines · Chaitanya Kulkarni
Quoted 13 lines · Leon Romanovsky
Quoted 8 lines
(quoted diff) +2 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops,

&num_request_queues,
+        0644); +MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Quoted 10 lines
Quoted 1 line

Thanks

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

You have many ways to overcome this issue.

For example:

# ls -l /sys/block/vda/mq/
drwxr-xr-x 18 root root 0 Sep  5 12:14 0
drwxr-xr-x 18 root root 0 Sep  5 12:14 1
drwxr-xr-x 18 root root 0 Sep  5 12:14 2
drwxr-xr-x 18 root root 0 Sep  5 12:14 3
Quoted 4 lines
Quoted 3 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/unbind
# echo 8 > /sys/module/virtio_blk/parameters/num_request_queues

This is global to all virtio-blk devices.

You define a global module param but you bind/unbind a specific device.

Do you have a better way to control it ?

if the device is already probed, it's too late to change the queue_num.

Quoted 16 lines
Quoted 16 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/bind
# ls -l /sys/block/vda/mq/
drwxr-xr-x 10 root root 0 Sep  5 12:17 0
drwxr-xr-x 10 root root 0 Sep  5 12:17 1
drwxr-xr-x 10 root root 0 Sep  5 12:17 2
drwxr-xr-x 10 root root 0 Sep  5 12:17 3
drwxr-xr-x 10 root root 0 Sep  5 12:17 4
drwxr-xr-x 10 root root 0 Sep  5 12:17 5
drwxr-xr-x 10 root root 0 Sep  5 12:17 6
drwxr-xr-x 10 root root 0 Sep  5 12:17 7

-Max.

#7 lore raw
Quoted 38 lines · Max Gurtovoy
Quoted 36 lines · Leon Romanovsky
Quoted 35 lines · Max Gurtovoy
Quoted 14 lines · Chaitanya Kulkarni
Quoted 13 lines · Leon Romanovsky
Quoted 8 lines
(quoted diff) +2 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops,

&num_request_queues,
+        0644); +MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Quoted 10 lines
Quoted 1 line

Thanks

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

You have many ways to overcome this issue.

For example:

# ls -l /sys/block/vda/mq/
drwxr-xr-x 18 root root 0 Sep  5 12:14 0
drwxr-xr-x 18 root root 0 Sep  5 12:14 1
drwxr-xr-x 18 root root 0 Sep  5 12:14 2
drwxr-xr-x 18 root root 0 Sep  5 12:14 3
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/unbind
# echo 8 > /sys/module/virtio_blk/parameters/num_request_queues

This is global to all virtio-blk devices.

You define a global module param but you bind/unbind a specific device.

Do you have a better way to control it ?

One of the possible solutions will be to extend virtio bus to allow setting of such pre-probe parameters. However I don't know if it is really worth doing it,

Quoted 20 lines

if the device is already probed, it's too late to change the queue_num.

Quoted 16 lines
Quoted 16 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/bind
# ls -l /sys/block/vda/mq/
drwxr-xr-x 10 root root 0 Sep  5 12:17 0
drwxr-xr-x 10 root root 0 Sep  5 12:17 1
drwxr-xr-x 10 root root 0 Sep  5 12:17 2
drwxr-xr-x 10 root root 0 Sep  5 12:17 3
drwxr-xr-x 10 root root 0 Sep  5 12:17 4
drwxr-xr-x 10 root root 0 Sep  5 12:17 5
drwxr-xr-x 10 root root 0 Sep  5 12:17 6
drwxr-xr-x 10 root root 0 Sep  5 12:17 7

-Max.

#8 lore raw
Quoted 39 lines · Leon Romanovsky
Quoted 38 lines · Max Gurtovoy
Quoted 37 lines · Leon Romanovsky
Quoted 36 lines · Max Gurtovoy
Quoted 14 lines · Chaitanya Kulkarni
Quoted 13 lines · Leon Romanovsky
Quoted 8 lines
(quoted diff) +2 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops,

&num_request_queues,
+        0644); +MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Quoted 9 lines
Quoted 1 line

Thanks

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

You have many ways to overcome this issue.

For example:

# ls -l /sys/block/vda/mq/
drwxr-xr-x 18 root root 0 Sep  5 12:14 0
drwxr-xr-x 18 root root 0 Sep  5 12:14 1
drwxr-xr-x 18 root root 0 Sep  5 12:14 2
drwxr-xr-x 18 root root 0 Sep  5 12:14 3
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/unbind
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
# echo 8 > /sys/module/virtio_blk/parameters/num_request_queues

This is global to all virtio-blk devices.

You define a global module param but you bind/unbind a specific device.

Do you have a better way to control it ?

One of the possible solutions will be to extend virtio bus to allow setting of such pre-probe parameters. However I don't know if it is really worth doing it,

So lets keep it as it is now.

Thanks.

Quoted 18 lines
Quoted 18 lines

if the device is already probed, it's too late to change the queue_num.

Quoted 15 lines
Quoted 15 lines
# echo virtio0 > /sys/bus/virtio/drivers/virtio_blk/bind
# ls -l /sys/block/vda/mq/
drwxr-xr-x 10 root root 0 Sep  5 12:17 0
drwxr-xr-x 10 root root 0 Sep  5 12:17 1
drwxr-xr-x 10 root root 0 Sep  5 12:17 2
drwxr-xr-x 10 root root 0 Sep  5 12:17 3
drwxr-xr-x 10 root root 0 Sep  5 12:17 4
drwxr-xr-x 10 root root 0 Sep  5 12:17 5
drwxr-xr-x 10 root root 0 Sep  5 12:17 6
drwxr-xr-x 10 root root 0 Sep  5 12:17 7

-Max.

#9 lore raw
In reply to Chaitanya Kulkarni
Quoted 13 lines · Chaitanya Kulkarni
Quoted 11 lines · Leon Romanovsky

drivers/block/virtio_blk.c line 43

Quoted 6 lines
drivers/block/virtio_blk.c +6 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Quoted 8 lines
Quoted 1 line

Thanks

Without looking into the code, that can be done adding a configfs

interface and overriding a global value (module param) when it is set from

configfs.

So why should we do double work instead of providing one working interface from the beginning?

Thanks

Quoted 2 lines

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#10 lore raw
Quoted 19 lines · Leon Romanovsky
Quoted 18 lines · Chaitanya Kulkarni
Quoted 8 lines · Leon Romanovsky

drivers/block/virtio_blk.c line 43

Quoted 6 lines
drivers/block/virtio_blk.c +6 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

Quoted 4 lines

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Thanks

Without looking into the code, that can be done adding a configfs

Quoted 11 lines
Quoted 3 lines

interface and overriding a global value (module param) when it is set from

configfs.

So why should we do double work instead of providing one working interface from the beginning?

Thanks

Quoted 2 lines

The main way to do it is really from the hypervisor. This one is a pretty blunt instrument, Max here says it's useful to reduce memory usage of the driver. If that's the usecase then a global limit seems sufficient.

Signature · 1 line
MST
#11 lore raw
Quoted 32 lines · Michael S. Tsirkin
Quoted 19 lines · Leon Romanovsky
Quoted 18 lines · Chaitanya Kulkarni
Quoted 8 lines · Leon Romanovsky

drivers/block/virtio_blk.c line 43

Quoted 6 lines
drivers/block/virtio_blk.c +6 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+

Won't it limit all virtio block devices to the same limit?

Quoted 4 lines

It is very common to see multiple virtio-blk devices on the same system and they probably need different limits.

Thanks

Without looking into the code, that can be done adding a configfs

Quoted 11 lines
Quoted 3 lines

interface and overriding a global value (module param) when it is set from

configfs.

So why should we do double work instead of providing one working interface from the beginning?

Thanks

Quoted 2 lines
Quoted 4 lines

The main way to do it is really from the hypervisor. This one is a pretty blunt instrument, Max here says it's useful to reduce memory usage of the driver. If that's the usecase then a global limit seems sufficient.

How memory will you reduce? It is worth to write it in the commit message.

Thanks

Quoted 4 lines
Signature · 2 lines
-- 
MST
#12 lore raw
In reply to Max Gurtovoy
Quoted 41 lines · Max Gurtovoy

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
- renamed num_io_queues to num_request_queues (from Stefan)
- added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
- use param_set_uint_minmax (from Christoph)
- added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
 drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +10 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
 /* The maximum number of sg elements that fit into a virtqueue */
 #define VIRTIO_BLK_MAX_SG_ELEMS 32768
 
+static int virtblk_queue_count_set(const char *val,
+		const struct kernel_param *kp)
+{
+	return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+
+static const struct kernel_param_ops queue_count_ops = {
+	.set = virtblk_queue_count_set,
+	.get = param_get_uint,
+};

drivers/block/virtio_blk.c line 46

Quoted 10 lines
drivers/block/virtio_blk.c +7 -0
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+
 static int major;
 static DEFINE_IDA(vd_index_ida);
 

I wasn't happy with the message here so I tweaked it.

Please look at it in linux-next and confirm. Thanks!

Quoted 13 lines
drivers/block/virtio_blk.c +3 -1
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
 	if (err)
 		num_vqs = 1;
 
-	num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+	num_vqs = min_t(unsigned int,
+			min_not_zero(num_request_queues, nr_cpu_ids),
+			num_vqs);
 
 	vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
 	if (!vblk->vqs)
Signature · 1 line
2.18.1
#13 lore raw
Quoted 54 lines · Michael S. Tsirkin
Quoted 41 lines · Max Gurtovoy

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
- renamed num_io_queues to num_request_queues (from Stefan)
- added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
- use param_set_uint_minmax (from Christoph)
- added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
  drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-
  1 file changed, 20 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +10 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
  /* The maximum number of sg elements that fit into a virtqueue */
  #define VIRTIO_BLK_MAX_SG_ELEMS 32768
 
+static int virtblk_queue_count_set(const char *val,
+		const struct kernel_param *kp)
+{
+	return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+
+static const struct kernel_param_ops queue_count_ops = {
+	.set = virtblk_queue_count_set,
+	.get = param_get_uint,
+};

drivers/block/virtio_blk.c line 46

Quoted 10 lines
drivers/block/virtio_blk.c +7 -0
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, &num_request_queues,
+		0644);
+MODULE_PARM_DESC(num_request_queues,
+		 "Number of request queues to use for blk device. Should > 0");
+
  static int major;
  static DEFINE_IDA(vd_index_ida);
 

I wasn't happy with the message here so I tweaked it.

Quoted 1 line

Please look at it in linux-next and confirm. Thanks!

Looks good.

Quoted 15 lines
Quoted 15 lines
drivers/block/virtio_blk.c +3 -1
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
  	if (err)
  		num_vqs = 1;
 
-	num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+	num_vqs = min_t(unsigned int,
+			min_not_zero(num_request_queues, nr_cpu_ids),
+			num_vqs);
 
  	vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
  	if (!vblk->vqs)
Signature · 1 line
2.18.1
#14 lore raw
Quoted 26 lines · Max Gurtovoy
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Max Gurtovoy

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
  - renamed num_io_queues to num_request_queues (from Stefan)
  - added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
  - use param_set_uint_minmax (from Christoph)
  - added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
  drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-

  1 file changed, 20 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
Quoted 8 lines

drivers/block/virtio_blk.c line 32

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
   /* The maximum number of sg elements that fit into a virtqueue */
   #define VIRTIO_BLK_MAX_SG_ELEMS 32768
   +static int virtblk_queue_count_set(const char *val,
+        const struct kernel_param *kp)
+{
+    return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+

BTW, I've noticed in your new message you allow setting 0 so you might want to change the code to

param_set_uint_minmax(val, kp, 0, nr_cpu_ids);

to a case a user will load the module with num_request_queues=0.

Quoted 35 lines
Quoted 17 lines
Quoted 14 lines
drivers/block/virtio_blk.c +11 -0
+static const struct kernel_param_ops queue_count_ops = {
+    .set = virtblk_queue_count_set,
+    .get = param_get_uint,
+};
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops, 
 &num_request_queues,
+        0644);
+MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device. Should > 
 0");
+
   static int major;
Quoted 1 line

  static DEFINE_IDA(vd_index_ida);

I wasn't happy with the message here so I tweaked it.

Quoted 1 line

Please look at it in linux-next and confirm. Thanks!

Looks good.

Quoted 13 lines
Quoted 13 lines
drivers/block/virtio_blk.c +3 -0
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
       if (err)
           num_vqs = 1;
   -    num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+    num_vqs = min_t(unsigned int,
+            min_not_zero(num_request_queues, nr_cpu_ids),
+            num_vqs);
         vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
       if (!vblk->vqs)
Signature · 1 line
2.18.1
#15 lore raw
Quoted 45 lines · Max Gurtovoy
Quoted 26 lines · Max Gurtovoy
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Max Gurtovoy

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
  - renamed num_io_queues to num_request_queues (from Stefan)
  - added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
  - use param_set_uint_minmax (from Christoph)
  - added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
  drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-

  1 file changed, 20 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
Quoted 8 lines

drivers/block/virtio_blk.c line 32

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
   /* The maximum number of sg elements that fit into a virtqueue */
   #define VIRTIO_BLK_MAX_SG_ELEMS 32768
   +static int virtblk_queue_count_set(const char *val,
+        const struct kernel_param *kp)
+{
+    return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+

BTW, I've noticed in your new message you allow setting 0 so you might want to change the code to

Quoted 3 lines

param_set_uint_minmax(val, kp, 0, nr_cpu_ids);

to a case a user will load the module with num_request_queues=0.

Oh. So as written the default forces 1 queue?
Send a patch please!

Quoted 36 lines
Quoted 36 lines
Quoted 17 lines
Quoted 14 lines
drivers/block/virtio_blk.c +11 -0
+static const struct kernel_param_ops queue_count_ops = {
+    .set = virtblk_queue_count_set,
+    .get = param_get_uint,
+};
+
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops,
 &num_request_queues,
+        0644);
+MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device.
 Should > 0");
+
   static int major;
Quoted 1 line

  static DEFINE_IDA(vd_index_ida);

I wasn't happy with the message here so I tweaked it.

Quoted 1 line

Please look at it in linux-next and confirm. Thanks!

Looks good.

Quoted 14 lines
Quoted 14 lines
drivers/block/virtio_blk.c +3 -0
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
       if (err)
           num_vqs = 1;
   -    num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+    num_vqs = min_t(unsigned int,
+            min_not_zero(num_request_queues, nr_cpu_ids),
+            num_vqs);
         vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs),
 GFP_KERNEL);
       if (!vblk->vqs)
Signature · 1 line
2.18.1
#16 lore raw
Quoted 43 lines · Michael S. Tsirkin
Quoted 42 lines · Max Gurtovoy
Quoted 25 lines · Max Gurtovoy
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Max Gurtovoy

Sometimes a user would like to control the amount of request queues to be created for a block device. For example, for limiting the memory footprint of virtio-blk devices.

---

changes from v2:
  - renamed num_io_queues to num_request_queues (from Stefan)
  - added Reviewed-by signatures (from Stefan and Christoph)

changes from v1:
  - use param_set_uint_minmax (from Christoph)
  - added "Should > 0" to module description

Note: This commit apply on top of Jens's branch for-5.15/drivers

---
   drivers/block/virtio_blk.c | 21 ++++++++++++++++++++-
   1 file changed, 20 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..aaa2833a4734 100644
@@ -24,6 +24,23 @@
Quoted 8 lines

drivers/block/virtio_blk.c line 32

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
   /* The maximum number of sg elements that fit into a virtqueue */
   #define VIRTIO_BLK_MAX_SG_ELEMS 32768
   +static int virtblk_queue_count_set(const char *val,
+        const struct kernel_param *kp)
+{
+    return param_set_uint_minmax(val, kp, 1, nr_cpu_ids);
+}
+

BTW, I've noticed in your new message you allow setting 0 so you might want to change the code to

Quoted 5 lines
Quoted 3 lines

param_set_uint_minmax(val, kp, 0, nr_cpu_ids);

to a case a user will load the module with num_request_queues=0.

Oh. So as written the default forces 1 queue?
Send a patch please!

No. The default (if nobody touch this param) is 0 and everything works as today. but the user can't do "modprobe virtio_blk num_request_queues=0".

My comment was right (should be set > 0).

You changed and wrote "0 for no limit." but the user can't set to 0. So if you want the user to change to 0, please change the above code as I mentioned.

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 18 lines
Quoted 6 lines
drivers/block/virtio_blk.c +5 -0
+static const struct kernel_param_ops queue_count_ops = {
+    .set = virtblk_queue_count_set,
+    .get = param_get_uint,
+};
+

drivers/block/virtio_blk.c line 45

Quoted 10 lines
drivers/block/virtio_blk.c +6 -0
+static unsigned int num_request_queues;
+module_param_cb(num_request_queues, &queue_count_ops,
 &num_request_queues,
+        0644);
+MODULE_PARM_DESC(num_request_queues,
+         "Number of request queues to use for blk device.
 Should > 0");
+
   static int major;
   static DEFINE_IDA(vd_index_ida);

I wasn't happy with the message here so I tweaked it.

Quoted 1 line

Please look at it in linux-next and confirm. Thanks!

Looks good.

Quoted 13 lines
Quoted 13 lines
drivers/block/virtio_blk.c +3 -0
@@ -501,7 +518,9 @@ static int init_vq(struct virtio_blk *vblk)
       if (err)
           num_vqs = 1;
   -    num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
+    num_vqs = min_t(unsigned int,
+            min_not_zero(num_request_queues, nr_cpu_ids),
+            num_vqs);
         vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs),
 GFP_KERNEL);
       if (!vblk->vqs)
Signature · 1 line
2.18.1