Skip to contentSkip to conversation

virtio-blk: add num_io_queues module parameter

PATCH Superseded Max Gurtovoy 4 participants 21 messages Aug 31, 2021 – Sep 13, 2021

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 virtio-blk: add num_io_queues module parameter

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

---

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 | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +19 -1
index 4b49df2dfd23..9332fc4e9b31 100644
@@ -24,6 +24,22 @@
 /* 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_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+		 "Number of IO virt queues to use for blk device. Should > 0");
+
 static int major;
 static DEFINE_IDA(vd_index_ida);
 
@@ -501,7 +517,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_io_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
reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Max Gurtovoy
Quoted 44 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +16 -0
index 4b49df2dfd23..9332fc4e9b31 100644
@@ -24,6 +24,22 @@
 /* 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_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+		 "Number of IO virt queues to use for blk device. Should > 0");
+
 static int major;
 static DEFINE_IDA(vd_index_ida);
 

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

Quoted 7 lines
drivers/block/virtio_blk.c +3 -1
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

#3 lore raw
Quoted 57 lines · Stefan Hajnoczi
Quoted 44 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +16 -0
index 4b49df2dfd23..9332fc4e9b31 100644
@@ -24,6 +24,22 @@
 /* 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_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+		 "Number of IO virt queues to use for blk device. Should > 0");
+
 static int major;
 static DEFINE_IDA(vd_index_ida);
 

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

Quoted 7 lines
drivers/block/virtio_blk.c +3 -1
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:
+static unsigned int num_io_request_queues; +module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644); +MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");

#4 lore raw
Quoted 59 lines · Michael S. Tsirkin
Quoted 56 lines · Stefan Hajnoczi
Quoted 44 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
  1 file changed, 19 insertions(+), 1 deletion(-)
drivers/block/virtio_blk.c +16 -0
index 4b49df2dfd23..9332fc4e9b31 100644
@@ -24,6 +24,22 @@
  /* 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_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+		 "Number of IO virt queues to use for blk device. Should > 0");
+
  static int major;
  static DEFINE_IDA(vd_index_ida);
 

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

Quoted 7 lines
drivers/block/virtio_blk.c +3 -1
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#5 lore raw
Quoted 20 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
  1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
  /* 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);
+}

Hmm which tree is this for?

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 41

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

better:

+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");

Quoted 29 lines
Quoted 16 lines
Quoted 14 lines

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

Quoted 10 lines
drivers/block/virtio_blk.c +4 -1
+
  static int major;
  static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#6 lore raw
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
   1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
   /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/block/virtio_blk.c line 41

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

better:

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 16 lines

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

Quoted 12 lines
drivers/block/virtio_blk.c +4 -1
+
   static int major;
   static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#7 lore raw
Quoted 56 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
   1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
   /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/block/virtio_blk.c line 41

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

better:

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 19 lines
Quoted 17 lines

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

Quoted 13 lines
drivers/block/virtio_blk.c +4 -1
+
   static int major;
   static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

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

#8 lore raw
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
    1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
    /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 15 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 40

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

better:

(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");
Quoted 7 lines
Quoted 1 line

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 16 lines

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

Quoted 12 lines
drivers/block/virtio_blk.c +4 -1
+
    static int major;
    static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#9 lore raw
Quoted 66 lines · Max Gurtovoy
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
    1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
    /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 15 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 40

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

better:

(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");
Quoted 7 lines
Quoted 1 line

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

Quoted 8 lines

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 16 lines

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

Quoted 12 lines
drivers/block/virtio_blk.c +4 -1
+
    static int major;
    static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#10 lore raw
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
     1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
     /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 40

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

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 17 lines
Quoted 15 lines

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

Quoted 11 lines
drivers/block/virtio_blk.c +4 -1
+
     static int major;
     static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#11 lore raw
Quoted 72 lines · Max Gurtovoy
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
     1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
     /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 40

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

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

So your description is not reflecting the code.

We can do:

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 16 lines

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

Quoted 12 lines
drivers/block/virtio_blk.c +4 -1
+
     static int major;
     static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#12 lore raw
Quoted 76 lines · Michael S. Tsirkin
Quoted 75 lines · Max Gurtovoy
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
      1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
      /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 40

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

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

Quoted 8 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
Quoted 14 lines

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

Quoted 10 lines
drivers/block/virtio_blk.c +4 -1
+
      static int major;
      static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#13 lore raw
Quoted 81 lines · Max Gurtovoy
Quoted 79 lines · Michael S. Tsirkin
Quoted 78 lines · Max Gurtovoy
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

---

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 | 20 +++++++++++++++++++-
      1 file changed, 19 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/block/virtio_blk.c +0 -0
index 4b49df2dfd23..9332fc4e9b31 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/block/virtio_blk.c line 30

Quoted 8 lines
drivers/block/virtio_blk.c +5 -0
@@ -24,6 +24,22 @@
      /* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/block/virtio_blk.c line 40

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

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

Quoted 8 lines
Quoted 5 lines

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

Quoted 31 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
Quoted 14 lines

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

Quoted 10 lines
drivers/block/virtio_blk.c +4 -1
+
      static int major;
      static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+			num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#14 lore raw
Quoted 86 lines · Michael S. Tsirkin
Quoted 85 lines · Max Gurtovoy
Quoted 84 lines · Michael S. Tsirkin
Quoted 71 lines · Max Gurtovoy
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Max Gurtovoy

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

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

@@ -24,6 +24,22 @@
/* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

So your description is not reflecting the code.

We can do:

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Quoted 8 lines
Quoted 3 lines

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

Quoted 31 lines
Quoted 31 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
Quoted 14 lines
Quoted 10 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);

If you respin, please consider calling them request queues. That's the terminology from the VIRTIO spec and it's nice to keep it consistent. But the purpose of num_io_queues is clear, so:

Quoted 1 line

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#15 lore raw
Quoted 97 lines · Max Gurtovoy
Quoted 86 lines · Michael S. Tsirkin
Quoted 85 lines · Max Gurtovoy
Quoted 84 lines · Michael S. Tsirkin
Quoted 71 lines · Max Gurtovoy
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Stefan Hajnoczi

On Tue, Aug 31, 2021 at 04:50:35PM +0300, Max Gurtovoy wrote:
Sometimes a user would like to control the amount of IO queues to be
created for a block device. For example, for limiting the memory
footprint of virtio-blk devices.

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

@@ -24,6 +24,22 @@
/* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

So your description is not reflecting the code.

We can do:

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Quoted 8 lines
Quoted 3 lines

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

Quoted 4 lines

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

OK and the second distinction is that it's a limit on the number, not the actual number. It's never more than what's provided by the hypervisor.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
Quoted 15 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);
If you respin, please consider calling them request queues. That's the
terminology from the VIRTIO spec and it's nice to keep it consistent.
But the purpose of num_io_queues is clear, so:

Reviewed-by: Stefan Hajnoczi <[email protected]>

I did this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#16 lore raw
Quoted 96 lines · Michael S. Tsirkin
Quoted 95 lines · Max Gurtovoy
Quoted 94 lines · Michael S. Tsirkin
Quoted 80 lines · Max Gurtovoy
Quoted 79 lines · Michael S. Tsirkin
Quoted 78 lines · Max Gurtovoy
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy
Quoted 18 lines · Michael S. Tsirkin

On Thu, Sep 02, 2021 at 02:45:52PM +0100, Stefan Hajnoczi wrote:
On Tue, Aug 31, 2021 at 04:50:35PM +0300, Max Gurtovoy wrote:
Sometimes a user would like to control the amount of IO queues to be
created for a block device. For example, for limiting the memory
footprint of virtio-blk devices.

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c

Quoted 8 lines
Quoted 8 lines

@@ -24,6 +24,22 @@
/* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines
Quoted 10 lines

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

Quoted 8 lines
Quoted 5 lines

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

Quoted 7 lines
Quoted 4 lines

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

OK and the second distinction is that it's a limit on the number, not the actual number. It's never more than what's provided by the hypervisor.

MODULE_PARM_DESC(num_io_request_queues, "Maximal number of request virt queues to use for blk device. 0 value means no limitation");

is that ok ?

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 20 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);
If you respin, please consider calling them request queues. That's the
terminology from the VIRTIO spec and it's nice to keep it consistent.
But the purpose of num_io_queues is clear, so:

Reviewed-by: Stefan Hajnoczi <[email protected]>
I did this:
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");

The parameter is writable and can be changed and then new devices might be probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in V3 of this patch (and maybe enable value of 0 as mentioned above).

#17 lore raw
Quoted 102 lines · Max Gurtovoy
Quoted 100 lines · Michael S. Tsirkin
Quoted 99 lines · Max Gurtovoy
Quoted 86 lines · Michael S. Tsirkin
Quoted 85 lines · Max Gurtovoy
Quoted 84 lines · Michael S. Tsirkin
Quoted 71 lines · Max Gurtovoy
Quoted 70 lines · Michael S. Tsirkin
Quoted 69 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Max Gurtovoy

On 9/5/2021 7:02 PM, Michael S. Tsirkin wrote:
On Thu, Sep 02, 2021 at 02:45:52PM +0100, Stefan Hajnoczi wrote:
On Tue, Aug 31, 2021 at 04:50:35PM +0300, Max Gurtovoy wrote:
Sometimes a user would like to control the amount of IO queues to be
created for a block device. For example, for limiting the memory
footprint of virtio-blk devices.

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

Quoted 13 lines
Quoted 12 lines

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -24,6 +24,22 @@
/* 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);
+}

Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines
Quoted 10 lines

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");

better:

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+MODULE_PARM_DESC(num_io_request_queues,
+                "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

So your description is not reflecting the code.

We can do:

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Quoted 8 lines
Quoted 3 lines

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

Quoted 7 lines
Quoted 3 lines

OK and the second distinction is that it's a limit on the number, not the actual number. It's never more than what's provided by the hypervisor.

MODULE_PARM_DESC(num_io_request_queues, "Maximal number of request virt queues to use for blk device. 0 value means no limitation");

is that ok ?

Looks ok. And then do we need to limit this to nr_cpu_ids? Setting a value that's too high seems harmless ...

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);
If you respin, please consider calling them request queues. That's the
terminology from the VIRTIO spec and it's nice to keep it consistent.
But the purpose of num_io_queues is clear, so:

Reviewed-by: Stefan Hajnoczi <[email protected]>
I did this:
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");
The parameter is writable and can be changed and then new devices might be
probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and
say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in
V3 of this patch (and maybe enable value of 0 as mentioned above).

#18 lore raw
Quoted 105 lines · Michael S. Tsirkin
Quoted 104 lines · Max Gurtovoy
Quoted 103 lines · Michael S. Tsirkin
Quoted 90 lines · Max Gurtovoy
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Max Gurtovoy
Quoted 76 lines · Michael S. Tsirkin
Quoted 75 lines · Max Gurtovoy
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy
Quoted 33 lines · Michael S. Tsirkin

On Mon, Sep 06, 2021 at 01:31:32AM +0300, Max Gurtovoy wrote:
On 9/5/2021 7:02 PM, Michael S. Tsirkin wrote:
On Thu, Sep 02, 2021 at 02:45:52PM +0100, Stefan Hajnoczi wrote:
On Tue, Aug 31, 2021 at 04:50:35PM +0300, Max Gurtovoy wrote:
Sometimes a user would like to control the amount of IO queues to be
created for a block device. For example, for limiting the memory
footprint of virtio-blk devices.

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -24,6 +24,22 @@
/* 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);
+}
Hmm which tree is this for?

I've mentioned in the note that it apply on branch for-5.15/drivers. But now you can apply it on linus/master as well.

Quoted 12 lines

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");
better:

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");

You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

Quoted 8 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

Quoted 9 lines
Quoted 5 lines

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

OK and the second distinction is that it's a limit on the number, not the actual number. It's never more than what's provided by the hypervisor.

Quoted 6 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Maximal number of request virt queues to use for blk device. 0 value means no limitation");

is that ok ?

Looks ok. And then do we need to limit this to nr_cpu_ids? Setting a value that's too high seems harmless ...

why would you want that ?

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);
If you respin, please consider calling them request queues. That's the
terminology from the VIRTIO spec and it's nice to keep it consistent.
But the purpose of num_io_queues is clear, so:

Reviewed-by: Stefan Hajnoczi <[email protected]>
I did this:
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");
The parameter is writable and can be changed and then new devices might be
probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and
say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in
V3 of this patch (and maybe enable value of 0 as mentioned above).

#19 lore raw
Quoted 107 lines · Max Gurtovoy
Quoted 105 lines · Michael S. Tsirkin
Quoted 104 lines · Max Gurtovoy
Quoted 103 lines · Michael S. Tsirkin
Quoted 90 lines · Max Gurtovoy
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Max Gurtovoy
Quoted 76 lines · Michael S. Tsirkin
Quoted 75 lines · Max Gurtovoy
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Max Gurtovoy

On 9/6/2021 2:20 PM, Michael S. Tsirkin wrote:
On Mon, Sep 06, 2021 at 01:31:32AM +0300, Max Gurtovoy wrote:
On 9/5/2021 7:02 PM, Michael S. Tsirkin wrote:
On Thu, Sep 02, 2021 at 02:45:52PM +0100, Stefan Hajnoczi wrote:
On Tue, Aug 31, 2021 at 04:50:35PM +0300, Max Gurtovoy wrote:
Sometimes a user would like to control the amount of IO queues to be
created for a block device. For example, for limiting the memory
footprint of virtio-blk devices.

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -24,6 +24,22 @@
/* 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);
+}
Hmm which tree is this for?
I've mentioned in the note that it apply on branch for-5.15/drivers. But now
you can apply it on linus/master as well.

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");
better:

Quoted 8 lines
Quoted 3 lines

+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");
You proposed it and I replied on it bellow.

Can't say I understand 100% what you are saying. Want to send a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t" reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

Quoted 8 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

Quoted 9 lines
Quoted 5 lines

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

OK and the second distinction is that it's a limit on the number, not the actual number. It's never more than what's provided by the hypervisor.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Maximal number of request virt queues to use for blk device. 0 value means no limitation");

is that ok ?

Looks ok. And then do we need to limit this to nr_cpu_ids? Setting a value that's too high seems harmless ...

why would you want that ?

So one can write a script that keeps working even when hypervisor changes the # of CPU IDs.

It's also consistent with other parameters, e.g.:

clocksource.verify_n_cpus= [KNL]
Limit the number of CPUs checked for clocksources marked with CLOCK_SOURCE_VERIFY_PERCPU that are marked unstable due to excessive skew. A negative value says to check all CPUs, while zero says not to check any. Values larger than nr_cpu_ids are silently truncated to nr_cpu_ids.

^^^^^^^^^^^^

The actual CPUs are chosen randomly, with no replacement if the same CPU is chosen twice.

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);
If you respin, please consider calling them request queues. That's the
terminology from the VIRTIO spec and it's nice to keep it consistent.
But the purpose of num_io_queues is clear, so:

Reviewed-by: Stefan Hajnoczi <[email protected]>
I did this:
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");
The parameter is writable and can be changed and then new devices might be
probed with new value.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

It can't be zero in the code. we can change param_set_uint_minmax args and
say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in
V3 of this patch (and maybe enable value of 0 as mentioned above).

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

#20 lore raw
Quoted 126 lines · Michael S. Tsirkin
Quoted 106 lines · Max Gurtovoy
Quoted 105 lines · Michael S. Tsirkin
Quoted 104 lines · Max Gurtovoy
Quoted 103 lines · Michael S. Tsirkin
Quoted 90 lines · Max Gurtovoy
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Max Gurtovoy
Quoted 76 lines · Michael S. Tsirkin
Quoted 75 lines · Max Gurtovoy
Quoted 66 lines · Michael S. Tsirkin
Quoted 65 lines · Max Gurtovoy
Quoted 59 lines · Michael S. Tsirkin

On Mon, Sep 06, 2021 at 02:59:40PM +0300, Max Gurtovoy wrote:
On 9/6/2021 2:20 PM, Michael S. Tsirkin wrote:
On Mon, Sep 06, 2021 at 01:31:32AM +0300, Max Gurtovoy wrote:
On 9/5/2021 7:02 PM, Michael S. Tsirkin wrote:
On Thu, Sep 02, 2021 at 02:45:52PM +0100, Stefan Hajnoczi wrote:
On Tue, Aug 31, 2021 at 04:50:35PM +0300, Max Gurtovoy wrote:
Sometimes a user would like to control the amount of IO queues to be
created for a block device. For example, for limiting the memory
footprint of virtio-blk devices.

Signed-off-by: Max Gurtovoy <[email protected]>
---

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 | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 4b49df2dfd23..9332fc4e9b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -24,6 +24,22 @@
/* 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);
+}
Hmm which tree is this for?
I've mentioned in the note that it apply on branch for-5.15/drivers. But now
you can apply it on linus/master as well.

+
+static const struct kernel_param_ops queue_count_ops = {
+ .set = virtblk_queue_count_set,
+ .get = param_get_uint,
+};
+
+static unsigned int num_io_queues;
+module_param_cb(num_io_queues, &queue_count_ops, &num_io_queues, 0644);
+MODULE_PARM_DESC(num_io_queues,
+ "Number of IO virt queues to use for blk device. Should > 0");
better:

+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");
You proposed it and I replied on it bellow.
Can't say I understand 100% what you are saying. Want to send
a description that does make sense to you but
also reflects reality? 0 is the default so
"should > 0" besides being ungrammatical does not seem t"
reflect what it does ...

if you "modprobe virtio_blk" the previous behavior will happen.

You can't "modprobe virtio_blk num_io_request_queues=0" since the minimal value is 1.

Quoted 6 lines
Quoted 5 lines

So your description is not reflecting the code.

We can do:

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue");

What's the default value? We should document that.

default value for static global variables is 0.

Quoted 8 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. Minimum value is 1 queue. Default and Maximum value is equal to the total number of CPUs");

So it says it's the # of cpus but yoiu inspect it with sysfs and it's actually 0. Let's say that's confusing at the least. why not just let users set it to 0 and document that?

Setting it by the user to 0 makes no sense.

We can say "if not set, the value equals to the total number of CPUs".

Quoted 9 lines
Quoted 5 lines

the value is 0. it seems to mean "no limit". the actual # of queues is then te smaller between # of cpus and # of hardware queues. I see no reason not to allow user to set that especially if it was originally the value then user changed it
and is trying to change it back.

I fine with that.

MODULE_PARM_DESC(num_io_request_queues, "Number of request virt queues to use for blk device. 0 value means no limitation");

OK and the second distinction is that it's a limit on the number, not the actual number. It's never more than what's provided by the hypervisor.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

MODULE_PARM_DESC(num_io_request_queues, "Maximal number of request virt queues to use for blk device. 0 value means no limitation");

is that ok ?

Looks ok. And then do we need to limit this to nr_cpu_ids? Setting a value that's too high seems harmless ...

why would you want that ?

So one can write a script that keeps working even when hypervisor changes the # of CPU IDs.

It's also consistent with other parameters, e.g.:

clocksource.verify_n_cpus= [KNL]
Limit the number of CPUs checked for clocksources marked with CLOCK_SOURCE_VERIFY_PERCPU that are marked unstable due to excessive skew. A negative value says to check all CPUs, while zero says not to check any. Values larger than nr_cpu_ids are silently truncated to nr_cpu_ids.

Quoted 4 lines

^^^^^^^^^^^^

The actual CPUs are chosen randomly, with no replacement if the same CPU is chosen twice.

I don't understand how this example is relevant. It's not a blk-mq device that allocate queues for submitting IOs.

There is no sense of creating more queues than the #CPUs in the blk-mq design.

And also no reason setting it to some high value that we'll silently decrease.

Why would anyone write a script with hard coded values of CPUs instead of checking it with some linux tool and then set the module param accordingly ?

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines

The actual value of the created queues can be seen in /sys/block/vda/mq/ as done today.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -501,7 +517,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_io_queues, nr_cpu_ids),
+ num_vqs);
If you respin, please consider calling them request queues. That's the
terminology from the VIRTIO spec and it's nice to keep it consistent.
But the purpose of num_io_queues is clear, so:

Reviewed-by: Stefan Hajnoczi <[email protected]>
I did this:
+static unsigned int num_io_request_queues;
+module_param_cb(num_io_request_queues, &queue_count_ops, &num_io_request_queues, 0644);
+MODULE_PARM_DESC(num_io_request_queues,
+ "Limit number of IO request virt queues to use for each device. 0 for now limit");
The parameter is writable and can be changed and then new devices might be
probed with new value.

It can't be zero in the code. we can change param_set_uint_minmax args and
say that 0 says nr_cpus.

I'm ok with the renaming but I prefer to stick to the description we gave in
V3 of this patch (and maybe enable value of 0 as mentioned above).