Skip to contentSkip to conversation

improve quiesce time for large amount of namespaces

PATCH Superseded Sagi Grimberg 5 participants 19 messages Jul 26, 2020 – Jul 28, 2020

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Sagi Grimberg

author maintainer
#0 lore raw

v3 cover improve quiesce time for large amount of namespaces

This set attempts to improve the quiesce time when using a large set of namespaces, which also improves I/O failover time in a multipath environment.

We improve for both non-blocking hctxs (e.g. pci, fc, rdma) and blocking hctxs (e.g. tcp) by splitting queue auiesce to async call_(s)rcu and async_wait to wait for it to complete.

Changes from v2:
- made blk_mq_quiesce_queue_async operate on both blocking and non-blocking hctxs.
- removed separation between blocking vs. non-blocking queues
- dropeed patch from Chao
- dropped nvme-rdma test patch

Changes from v1:
- trivial typo fixes

Sagi Grimberg (2):
blk-mq: add async quiesce interface
nvme: improve quiesce time for large amount of namespaces

 block/blk-mq.c           | 32 ++++++++++++++++++++++++++++++++
 drivers/nvme/host/core.c |  4 +++-
 include/linux/blk-mq.h   |  4 ++++
 3 files changed, 39 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v3 1/2 blk-mq: add async quiesce interface

Drivers that may have to quiesce a large amount of request queues at once (e.g. controller or adapter reset). These drivers would benefit from an async quiesce interface such that the can trigger quiesce asynchronously and wait for all in parallel.

This leaves the synchronization responsibility to the driver, but adds a convenient interface to quiesce async and wait in a single pass.

---
 block/blk-mq.c         | 32 ++++++++++++++++++++++++++++++++
 include/linux/blk-mq.h |  4 ++++
 2 files changed, 36 insertions(+)
block/blk-mq.c +32 -0
index abcf590f6238..60d137265bd9 100644
@@ -209,6 +209,38 @@ void blk_mq_quiesce_queue_nowait(struct request_queue *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
 
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		wait_for_completion(&hctx->rcu_sync.completion);
+		destroy_rcu_head(&hctx->rcu_sync.head);
+	}
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
 /**
  * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
  * @q: request queue.
include/linux/blk-mq.h +4 -0
index 23230c1d031e..5536e434311a 100644
@@ -5,6 +5,7 @@
 #include <linux/blkdev.h>
 #include <linux/sbitmap.h>
 #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
 
 struct blk_mq_tags;
 struct blk_flush_queue;
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
 	 */
 	struct list_head	hctx_list;
 
+	struct rcu_synchronize	rcu_sync;
 	/**
 	 * @srcu: Sleepable RCU. Use as lock when type of the hardware queue is
 	 * blocking (BLK_MQ_F_BLOCKING). Must be the last member - see also
@@ -532,6 +534,8 @@ int blk_mq_map_queues(struct blk_mq_queue_map *qmap);
 void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);
 
 void blk_mq_quiesce_queue_nowait(struct request_queue *q);
+void blk_mq_quiesce_queue_async(struct request_queue *q);
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q);
 
 unsigned int blk_mq_rq_cpu(struct request *rq);
 
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Hi Sagi,

Quoted 29 lines · Sagi Grimberg

Drivers that may have to quiesce a large amount of request queues at once (e.g. controller or adapter reset). These drivers would benefit from an async quiesce interface such that the can trigger quiesce asynchronously and wait for all in parallel.

This leaves the synchronization responsibility to the driver, but adds a convenient interface to quiesce async and wait in a single pass.

---
 block/blk-mq.c         | 32 ++++++++++++++++++++++++++++++++
 include/linux/blk-mq.h |  4 ++++
 2 files changed, 36 insertions(+)
block/blk-mq.c +7 -0
index abcf590f6238..60d137265bd9 100644
@@ -209,6 +209,38 @@ void blk_mq_quiesce_queue_nowait(struct request_queue *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
 
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 228

Quoted 10 lines
block/blk-mq.c +10 -0
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 31 lines
block/blk-mq.c +15 -0
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		wait_for_completion(&hctx->rcu_sync.completion);
+		destroy_rcu_head(&hctx->rcu_sync.head);
+	}
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
 /**
  * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
  * @q: request queue.
include/linux/blk-mq.h +1 -0
index 23230c1d031e..5536e434311a 100644
@@ -5,6 +5,7 @@
 #include <linux/blkdev.h>
 #include <linux/sbitmap.h>
 #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
 
 struct blk_mq_tags;
 struct blk_flush_queue;

include/linux/blk-mq.h struct blk_mq_hw_ctx { · line 174

Quoted 4 lines
include/linux/blk-mq.h +1 -0
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
 	 */
 	struct list_head	hctx_list;
 
+	struct rcu_synchronize	rcu_sync;

The above struct takes at least 5 words, and I'd suggest to avoid it, and the hctx->srcu should be re-used for waiting BLK_MQ_F_BLOCKING. Meantime !BLK_MQ_F_BLOCKING doesn't need it.

Thanks,
Ming

author maintainer
#3 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 13 lines
Quoted 13 lines
block/blk-mq.c +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 228

Quoted 5 lines
block/blk-mq.c +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Also, having the driver call a single synchronize_rcu isn't great
layering (as quiesce can possibly use a different mechanism in the future). So drivers assumptions like:

        /*
         * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING flag so
         * calling synchronize_rcu() once is enough.
         */
        WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);

        if (!ret)
                synchronize_rcu();

Are not great...

Quoted 34 lines
Quoted 34 lines
block/blk-mq.c +15 -0
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		wait_for_completion(&hctx->rcu_sync.completion);
+		destroy_rcu_head(&hctx->rcu_sync.head);
+	}
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
  /**
   * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
   * @q: request queue.
include/linux/blk-mq.h +1 -0
index 23230c1d031e..5536e434311a 100644
@@ -5,6 +5,7 @@
  #include <linux/blkdev.h>
  #include <linux/sbitmap.h>
  #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
 
  struct blk_mq_tags;
  struct blk_flush_queue;
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
  	 */
  	struct list_head	hctx_list;
 
Quoted 5 lines

include/linux/blk-mq.h struct blk_mq_hw_ctx { · line 174

Quoted 1 line
include/linux/blk-mq.h +1 -0
+	struct rcu_synchronize	rcu_sync;

The above struct takes at least 5 words, and I'd suggest to avoid it, and the hctx->srcu should be re-used for waiting BLK_MQ_F_BLOCKING. Meantime !BLK_MQ_F_BLOCKING doesn't need it.

It is at the end and contains exactly what is needed to synchronize. Not sure what you mean by reuse hctx->srcu?

#4 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 22 lines · Sagi Grimberg
Quoted 13 lines
Quoted 13 lines
block/blk-mq.c +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 228

Quoted 5 lines
block/blk-mq.c +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 2 lines

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Not sure one new interface is needed, and one simple way is to:

1) call blk_mq_quiesce_queue_nowait() for each request queue

2) wait in driver specific way

Or just wondering why nvme doesn't use set->tag_list to retrieve NS, then you may add per-tagset APIs for the waiting.

Quoted 2 lines

Also, having the driver call a single synchronize_rcu isn't great

Too many drivers are using synchronize_rcu():

	$ git grep -n synchronize_rcu ./drivers/ | wc
	    186     524   11384
Quoted 1 line

layering (as quiesce can possibly use a different mechanism in the future).

What is the different mechanism?

Quoted 11 lines

So drivers assumptions like:

        /*
         * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING flag so
         * calling synchronize_rcu() once is enough.
         */
        WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);

        if (!ret)
                synchronize_rcu();
Quoted 1 line

Are not great...

Both rcu read lock/unlock and synchronize_rcu is global interface, then it is reasonable to avoid unnecessary synchronize_rcu().

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
block/blk-mq.c +15 -0
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		wait_for_completion(&hctx->rcu_sync.completion);
+		destroy_rcu_head(&hctx->rcu_sync.head);
+	}
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
  /**
   * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
   * @q: request queue.
include/linux/blk-mq.h +1 -0
index 23230c1d031e..5536e434311a 100644
@@ -5,6 +5,7 @@
  #include <linux/blkdev.h>
  #include <linux/sbitmap.h>
  #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
  struct blk_mq_tags;
Quoted 8 lines

include/linux/blk-mq.h struct blk_mq_hw_ctx { · line 173

Quoted 5 lines
include/linux/blk-mq.h +1 -0
  struct blk_flush_queue;
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
  	 */
  	struct list_head	hctx_list;
+	struct rcu_synchronize	rcu_sync;

The above struct takes at least 5 words, and I'd suggest to avoid it, and the hctx->srcu should be re-used for waiting BLK_MQ_F_BLOCKING. Meantime !BLK_MQ_F_BLOCKING doesn't need it.

Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

Thanks,
Ming

#5 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 7 lines · Ming Lei
Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

To sync srcu together, the extra bytes must be needed, seperate blocking and non blocking queue to two hctx may be a not good choice.

There is two choice: the struct rcu_synchronize is added in hctx or in srcu. Though add rcu_synchronize in srcu has a weakness: the extra bytes is not need if which do not need batch sync srcu, I still think it's better for the SRCU to provide the batch synchronization interface.

We can add check ctrl->tagset->flags to provide same interface both for blocking and non blocking queue. The code for TINY_SRCU:

---
 block/blk-mq.c           | 29 +++++++++++++++++++++++++++++
 drivers/nvme/host/core.c |  9 ++++++++-
 include/linux/blk-mq.h   |  2 ++
 include/linux/srcu.h     |  2 ++
 include/linux/srcutiny.h |  1 +
 kernel/rcu/srcutiny.c    | 16 ++++++++++++++++
 6 files changed, 58 insertions(+), 1 deletion(-)
block/blk-mq.c +29 -0
index 4e0d173beaa3..3117fc3082ff 100644
@@ -235,6 +235,35 @@ void blk_mq_quiesce_queue(struct request_queue *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue);
 
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i)
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			synchronize_srcu_async(hctx->srcu);
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	if (q == NULL) {
+		synchronize_rcu();
+		return;
+	}
+
+	queue_for_each_hw_ctx(q, hctx, i)
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			synchronize_srcu_async_wait(hctx->srcu);
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
 /*
  * blk_mq_unquiesce_queue() - counterpart of blk_mq_quiesce_queue()
  * @q: request queue.
drivers/nvme/host/core.c +8 -1
index a3b1157561f5..f13aa447ab64 100644
@@ -4322,7 +4322,14 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl)
 
 	down_read(&ctrl->namespaces_rwsem);
 	list_for_each_entry(ns, &ctrl->namespaces, list)
-		blk_mq_quiesce_queue(ns->queue);
+		blk_mq_quiesce_queue_async(ns->queue);
+
+	if (ctrl->tagset->flags & BLK_MQ_F_BLOCKING) {
+		list_for_each_entry(ns, &ctrl->namespaces, list)
+			blk_mq_quiesce_queue_async_wait(ns->queue);
+	} else {
+		blk_mq_quiesce_queue_async_wait(NULL);
+	}
 	up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_stop_queues);
include/linux/blk-mq.h +2 -0
index d6fcae17da5a..092470c63558 100644
@@ -515,6 +515,8 @@ void blk_mq_start_hw_queues(struct request_queue *q);
 void blk_mq_start_stopped_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
 void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async);
 void blk_mq_quiesce_queue(struct request_queue *q);
+void blk_mq_quiesce_queue_async(struct request_queue *q);
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q);
 void blk_mq_unquiesce_queue(struct request_queue *q);
 void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
 void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
include/linux/srcu.h +2 -0
index e432cc92c73d..7e006e51ccf9 100644
@@ -60,6 +60,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp);
 int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
 void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp);
 void synchronize_srcu(struct srcu_struct *ssp);
+void synchronize_srcu_async(struct srcu_struct *ssp);
+void synchronize_srcu_async_wait(struct srcu_struct *ssp);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
include/linux/srcutiny.h +1 -0
index 5a5a1941ca15..3d7d871bef61 100644
@@ -23,6 +23,7 @@ struct srcu_struct {
 	struct rcu_head *srcu_cb_head;	/* Pending callbacks: Head. */
 	struct rcu_head **srcu_cb_tail;	/* Pending callbacks: Tail. */
 	struct work_struct srcu_work;	/* For driving grace periods. */
+	struct rcu_synchronize rcu_sync;
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 	struct lockdep_map dep_map;
 #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
kernel/rcu/srcutiny.c +16 -0
index 6208c1dae5c9..6e1468175a45 100644
@@ -190,6 +190,22 @@ void synchronize_srcu(struct srcu_struct *ssp)
 }
 EXPORT_SYMBOL_GPL(synchronize_srcu);
 
+void synchronize_srcu_async(struct srcu_struct *ssp)
+{
+	init_rcu_head(&ssp->rcu_sync.head);
+	init_completion(&ssp->rcu_sync.completion);
+	call_srcu(ssp, &ssp->rcu_sync.head, wakeme_after_rcu_batch);
+
+}
+EXPORT_SYMBOL_GPL(synchronize_srcu_async);
+
+void synchronize_srcu_async_wait(struct srcu_struct *ssp)
+{
+	wait_for_completion(&ssp->rcu_sync.completion);
+	destroy_rcu_head(&ssp->rcu_sync.head);
+}
+EXPORT_SYMBOL_GPL(synchronize_srcu_async_wait);
+
 /* Lockdep diagnostics.  */
 void __init rcu_scheduler_starting(void)
 {
Signature · 1 line
2.16.4
#6 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 11 lines · Chao Leng
Quoted 7 lines · Ming Lei
Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

Quoted 7 lines

To sync srcu together, the extra bytes must be needed, seperate blocking and non blocking queue to two hctx may be a not good choice.

There is two choice: the struct rcu_synchronize is added in hctx or in srcu. Though add rcu_synchronize in srcu has a weakness: the extra bytes is not need if which do not need batch sync srcu, I still think it's better for the SRCU to provide the batch synchronization interface.

The 'struct rcu_synchronize' can be allocated from heap or even stack( if no too many NSs), which is just one shot sync and the API is supposed to be called in slow path. No need to allocate it as long lifetime variable. Especially 'struct srcu_struct' has already been too fat.

Thanks,
Ming

#7 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 20 lines · Ming Lei
Quoted 11 lines · Chao Leng
Quoted 7 lines · Ming Lei
Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

Quoted 7 lines

To sync srcu together, the extra bytes must be needed, seperate blocking and non blocking queue to two hctx may be a not good choice.

There is two choice: the struct rcu_synchronize is added in hctx or in srcu. Though add rcu_synchronize in srcu has a weakness: the extra bytes is not need if which do not need batch sync srcu, I still think it's better for the SRCU to provide the batch synchronization interface.

Quoted 4 lines

The 'struct rcu_synchronize' can be allocated from heap or even stack( if no too many NSs), which is just one shot sync and the API is supposed to be called in slow path. No need to allocate it as long lifetime variable. Especially 'struct srcu_struct' has already been too fat.

Stack is not suitable, stack can not provide so many space for many name space. Heap maybe a choice, but need to add abnormal treat when alloc memory failed, Thus io pause time can not be ensured. So the extra space may must be needed for batch srcu sync.

#8 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 23 lines · Chao Leng
Quoted 20 lines · Ming Lei
Quoted 18 lines · Chao Leng
Quoted 7 lines · Ming Lei
Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

To sync srcu together, the extra bytes must be needed, seperate blocking and non blocking queue to two hctx may be a not good choice.

There is two choice: the struct rcu_synchronize is added in hctx or in srcu. Though add rcu_synchronize in srcu has a weakness: the extra bytes is not need if which do not need batch sync srcu, I still think it's better for the SRCU to provide the batch synchronization interface.

Quoted 6 lines
Quoted 4 lines

The 'struct rcu_synchronize' can be allocated from heap or even stack( if no too many NSs), which is just one shot sync and the API is supposed to be called in slow path. No need to allocate it as long lifetime variable. Especially 'struct srcu_struct' has already been too fat.

Stack is not suitable, stack can not provide so many space for

Stack is fine if number of NS is small, for example, most of times, there is just one NS.

Quoted 3 lines

many name space. Heap maybe a choice, but need to add abnormal treat when alloc memory failed, Thus io pause time can not be ensured. So the extra space may must be needed for batch srcu sync.

In case of allocation failure, you can switch to synchronize_srcu() simply.

Thanks,
Ming

author maintainer
#9 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

Quoted 7 lines

To sync srcu together, the extra bytes must be needed, seperate blocking and non blocking queue to two hctx may be a not good choice.

There is two choice: the struct rcu_synchronize is added in hctx or in srcu. Though add rcu_synchronize in srcu has a weakness: the extra bytes is not need if which do not need batch sync srcu, I still think it's better for the SRCU to provide the batch synchronization interface.

The 'struct rcu_synchronize' can be allocated from heap or even stack( if no too many NSs), which is just one shot sync and the API is supposed to be called in slow path. No need to allocate it as long lifetime variable. Especially 'struct srcu_struct' has already been too fat.

Quoted 4 lines
Quoted 1 line

Stack is not suitable, stack can not provide so many space for

Stack is fine if number of NS is small, for example, most of times, there is just one NS.

I prefer a single code-path, so stack is not good.

Quoted 5 lines
Quoted 3 lines

many name space. Heap maybe a choice, but need to add abnormal treat when alloc memory failed, Thus io pause time can not be ensured. So the extra space may must be needed for batch srcu sync.

In case of allocation failure, you can switch to synchronize_srcu() simply.

that is possible, but I still prefer to support both srcu and rcu hctx in a single interface so I don't need to have different code paths in nvme (or other drivers).

author maintainer
#10 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

In reply to Ming Lei
Quoted 18 lines
Quoted 10 lines · Ming Lei
Quoted 7 lines
Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

Quoted 7 lines

To sync srcu together, the extra bytes must be needed, seperate blocking and non blocking queue to two hctx may be a not good choice.

There is two choice: the struct rcu_synchronize is added in hctx or in srcu. Though add rcu_synchronize in srcu has a weakness: the extra bytes is not need if which do not need batch sync srcu, I still think it's better for the SRCU to provide the batch synchronization interface.

Quoted 4 lines

The 'struct rcu_synchronize' can be allocated from heap or even stack( if no too many NSs), which is just one shot sync and the API is supposed to be called in slow path. No need to allocate it as long lifetime variable. Especially 'struct srcu_struct' has already been too fat.

stack is not possible, and there is zero justification for this to go to every srcu user out there...

author maintainer
#11 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

In reply to Ming Lei
Quoted 25 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
block/blk-mq.c +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 228

Quoted 5 lines
block/blk-mq.c +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 2 lines

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Quoted 8 lines

Not sure one new interface is needed, and one simple way is to:

1) call blk_mq_quiesce_queue_nowait() for each request queue

2) wait in driver specific way

Or just wondering why nvme doesn't use set->tag_list to retrieve NS, then you may add per-tagset APIs for the waiting.

Because it puts assumptions on how quiesce works, which is something I'd like to avoid because I think its cleaner, what do others think? Jens? Christoph?

Quoted 6 lines
Quoted 1 line

Also, having the driver call a single synchronize_rcu isn't great

Too many drivers are using synchronize_rcu():

	$ git grep -n synchronize_rcu ./drivers/ | wc
	    186     524   11384

Wasn't talking about the usage of synchronize_rcu, was referring to the hidden assumption that quiesce is an rcu driven operation.

Quoted 3 lines
Quoted 1 line

layering (as quiesce can possibly use a different mechanism in the future).

What is the different mechanism?

Nothing specific, just said that having drivers assume that quiesce is synchronizing rcu or srcu is not great.

Quoted 8 lines
Quoted 8 lines

So drivers assumptions like:

         /*
          * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING flag so
          * calling synchronize_rcu() once is enough.
          */
         WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);
Quoted 7 lines
Quoted 4 lines
         if (!ret)
                 synchronize_rcu();

Are not great...

Both rcu read lock/unlock and synchronize_rcu is global interface, then it is reasonable to avoid unnecessary synchronize_rcu().

Again, the fact that quiesce translates to synchronize rcu/srcu based on the underlying tagset is implicit.

Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 30 lines
block/blk-mq.c +15 -0
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		wait_for_completion(&hctx->rcu_sync.completion);
+		destroy_rcu_head(&hctx->rcu_sync.head);
+	}
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
   /**
    * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
    * @q: request queue.
include/linux/blk-mq.h +1 -0
index 23230c1d031e..5536e434311a 100644
@@ -5,6 +5,7 @@
   #include <linux/blkdev.h>
   #include <linux/sbitmap.h>
   #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
   struct blk_mq_tags;
   struct blk_flush_queue;

include/linux/blk-mq.h struct blk_mq_hw_ctx { · line 173

Quoted 3 lines
include/linux/blk-mq.h +1 -0
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
   	 */
   	struct list_head	hctx_list;
+	struct rcu_synchronize	rcu_sync;

The above struct takes at least 5 words, and I'd suggest to avoid it, and the hctx->srcu should be re-used for waiting BLK_MQ_F_BLOCKING. Meantime !BLK_MQ_F_BLOCKING doesn't need it.

Quoted 4 lines
Quoted 1 line

It is at the end and contains exactly what is needed to synchronize. Not

The sync is simply single global synchronize_rcu(), and why bother to add extra >=40bytes for each hctx.

We can use the heap for this, but it will slow down the operation. Not sure if this is really meaningful given that it is in the end of the struct...

We cannot use the stack, because we do the wait asynchronously.

Quoted 4 lines
Quoted 1 line

sure what you mean by reuse hctx->srcu?

You already reuses hctx->srcu, but not see reason to add extra rcu_synchronize to each hctx for just simulating one single synchronize_rcu().

That is my preference, I don't want nvme or other drivers to take a different route for blocking vs. non-bloking based on

maintainer
#12 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 29 lines · Sagi Grimberg
Quoted 29 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
block/blk-mq.c +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 228

Quoted 5 lines
block/blk-mq.c +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 2 lines

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Not sure one new interface is needed, and one simple way is to:

1) call blk_mq_quiesce_queue_nowait() for each request queue

Quoted 8 lines
Quoted 4 lines

2) wait in driver specific way

Or just wondering why nvme doesn't use set->tag_list to retrieve NS, then you may add per-tagset APIs for the waiting.

Because it puts assumptions on how quiesce works, which is something I'd like to avoid because I think its cleaner, what do others think? Jens? Christoph?

I'd prefer to have it in a helper, and just have blk_mq_quiesce_queue() call that.

Signature · 1 line
Jens Axboe
author maintainer
#13 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 2 lines

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Not sure one new interface is needed, and one simple way is to:

1) call blk_mq_quiesce_queue_nowait() for each request queue

2) wait in driver specific way

Or just wondering why nvme doesn't use set->tag_list to retrieve NS, then you may add per-tagset APIs for the waiting.

Quoted 6 lines
Quoted 3 lines

Because it puts assumptions on how quiesce works, which is something I'd like to avoid because I think its cleaner, what do others think? Jens? Christoph?

I'd prefer to have it in a helper, and just have blk_mq_quiesce_queue() call that.

I agree with this approach as well.

Jens, this mean that we use the call_rcu mechanism also for non-blocking hctxs, because the caller will call it for multiple request queues (see patch 2) and we don't want to call synchronize_rcu for every request queue serially, we want it to happen in parallel.

Which leaves us with the patchset as it is, just to convert the rcu_synchronize structure to be dynamically allocated on the heap rather than keeping it statically allocated in the hctx.

This is how it looks:
--

block/blk-mq.c +46 -0
index abcf590f6238..d913924117d2 100644
@@ -209,6 +209,52 @@ void blk_mq_quiesce_queue_nowait(struct request_queue *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
 
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+       struct blk_mq_hw_ctx *hctx;
+       unsigned int i;
+       int rcu = false;
+
+       blk_mq_quiesce_queue_nowait(q);
+
+       queue_for_each_hw_ctx(q, hctx, i) {
+               hctx->rcu_sync = kmalloc(sizeof(*hctx->rcu_sync), GFP_KERNEL);
+               if (!hctx->rcu_sync) {
+                       /* fallback to serial rcu sync */
+                       if (hctx->flags & BLK_MQ_F_BLOCKING)
+                               synchronize_srcu(hctx->srcu);
+                       else
+                               rcu = true;
+               } else {
+                       init_completion(&hctx->rcu_sync->completion);
+                       init_rcu_head(&hctx->rcu_sync->head);
+                       if (hctx->flags & BLK_MQ_F_BLOCKING)
+                               call_srcu(hctx->srcu, &hctx->rcu_sync->head,
+                                       wakeme_after_rcu);
+                       else
+                               call_rcu(&hctx->rcu_sync->head,
+                                       wakeme_after_rcu);
+               }
+       }
+       if (rcu)
+               synchronize_rcu();
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+       struct blk_mq_hw_ctx *hctx;
+       unsigned int i;
+
+       queue_for_each_hw_ctx(q, hctx, i) {
+               if (!hctx->rcu_sync)
+                       continue;
+               wait_for_completion(&hctx->rcu_sync->completion);
+               destroy_rcu_head(&hctx->rcu_sync->head);
+       }
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
 /**
  * blk_mq_quiesce_queue() - wait until all ongoing dispatches have 

finished
* @q: request queue.

include/linux/blk-mq.h +2 -0
index 23230c1d031e..7213ce56bb31 100644
@@ -5,6 +5,7 @@
 #include <linux/blkdev.h>
 #include <linux/sbitmap.h>
 #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
 
 struct blk_mq_tags;
 struct blk_flush_queue;
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
         */
        struct list_head        hctx_list;
 
+       struct rcu_synchronize  *rcu_sync;
        /**
         * @srcu: Sleepable RCU. Use as lock when type of the hardware 

queue is
* blocking (BLK_MQ_F_BLOCKING). Must be the last member - see also
@@ -532,6 +534,8 @@ int blk_mq_map_queues(struct blk_mq_queue_map *qmap);
void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int
nr_hw_queues);

void blk_mq_quiesce_queue_nowait(struct request_queue *q);
+void blk_mq_quiesce_queue_async(struct request_queue *q); +void blk_mq_quiesce_queue_async_wait(struct request_queue *q);

unsigned int blk_mq_rq_cpu(struct request *rq);
--

and in nvme:
--

drivers/nvme/host/core.c +3 -1
index 05aa568a60af..e8cc728dee46 100644
@@ -4561,7 +4561,9 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl)
 
        down_read(&ctrl->namespaces_rwsem);
        list_for_each_entry(ns, &ctrl->namespaces, list)
-               blk_mq_quiesce_queue(ns->queue);
+               blk_mq_quiesce_queue_async(ns->queue);
+       list_for_each_entry(ns, &ctrl->namespaces, list)
+               blk_mq_quiesce_queue_async_wait(ns->queue);
        up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_stop_queues);

--

Agreed on this?

maintainer
#14 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 48 lines · Sagi Grimberg
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 2 lines

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Not sure one new interface is needed, and one simple way is to:

1) call blk_mq_quiesce_queue_nowait() for each request queue

2) wait in driver specific way

Or just wondering why nvme doesn't use set->tag_list to retrieve NS, then you may add per-tagset APIs for the waiting.

Quoted 6 lines
Quoted 3 lines

Because it puts assumptions on how quiesce works, which is something I'd like to avoid because I think its cleaner, what do others think? Jens? Christoph?

I'd prefer to have it in a helper, and just have blk_mq_quiesce_queue() call that.

I agree with this approach as well.

Jens, this mean that we use the call_rcu mechanism also for non-blocking hctxs, because the caller will call it for multiple request queues (see patch 2) and we don't want to call synchronize_rcu for every request queue serially, we want it to happen in parallel.

Quoted 5 lines

Which leaves us with the patchset as it is, just to convert the rcu_synchronize structure to be dynamically allocated on the heap rather than keeping it statically allocated in the hctx.

This is how it looks:

OK, so maybe I'm not fully up-to-date on the thread, but why aren't we just having a blk_mq_quiesce_queue_wait() that does something ala:

block/blk-mq.c +17 -12
index 667155f752f7..b4ceaaed2f9c 100644
@@ -209,32 +209,37 @@ void blk_mq_quiesce_queue_nowait(struct request_queue *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
 
-/**
- * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
- * @q: request queue.
- *
- * Note: this function does not prevent that the struct request end_io()
- * callback function is invoked. Once this function is returned, we make
- * sure no dispatch can happen until the queue is unquiesced via
- * blk_mq_unquiesce_queue().
- */
-void blk_mq_quiesce_queue(struct request_queue *q)
+void blk_mq_quiesce_queue_wait(struct request_queue *q)
 {
 	struct blk_mq_hw_ctx *hctx;
 	unsigned int i;
 	bool rcu = false;
 
-	blk_mq_quiesce_queue_nowait(q);
-
 	queue_for_each_hw_ctx(q, hctx, i) {
 		if (hctx->flags & BLK_MQ_F_BLOCKING)
 			synchronize_srcu(hctx->srcu);
 		else
 			rcu = true;
 	}
+
 	if (rcu)
 		synchronize_rcu();
 }
+
+/**
+ * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
+ * @q: request queue.
+ *
+ * Note: this function does not prevent that the struct request end_io()
+ * callback function is invoked. Once this function is returned, we make
+ * sure no dispatch can happen until the queue is unquiesced via
+ * blk_mq_unquiesce_queue().
+ */
+void blk_mq_quiesce_queue(struct request_queue *q)
+{
+	blk_mq_quiesce_queue_nowait(q);
+	blk_mq_quiesce_queue_wait(q);
+}
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue);
 
 /*

Do we care about BLK_MQ_F_BLOCKING runtime at all?

Signature · 1 line
Jens Axboe
maintainer
#15 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 8 lines · Jens Axboe
block/blk-mq.c +1 -2
+void blk_mq_quiesce_queue_wait(struct request_queue *q)
 {
 	struct blk_mq_hw_ctx *hctx;
 	unsigned int i;
 	bool rcu = false;
 
-	blk_mq_quiesce_queue_nowait(q);
-

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 227

Quoted 10 lines
block/blk-mq.c +1 -0
 	queue_for_each_hw_ctx(q, hctx, i) {
 		if (hctx->flags & BLK_MQ_F_BLOCKING)
 			synchronize_srcu(hctx->srcu);
 		else
 			rcu = true;
 	}
+
 	if (rcu)
 		synchronize_rcu();
 }

Either all the hctx's are blocking or none of them are: we don't need to iterate the hctx's to see which sync method to use. We can add at the very beginning (and get rid of 'bool rcu'):

	if (!(q->tag_set->flags & BLK_MQ_F_BLOCKING)) {
		synchronize_rcu();
		return;
	}

But the issue Sagi is trying to address is quiescing a lot request queues sharing a tagset where synchronize_rcu() is too time consuming to do repeatedly. He wants to synchrnoize once for the entire tagset rather than per-request_queue, so I think he needs an API taking a 'struct blk_mq_tag_set' instead of a 'struct request_queue'.

maintainer
#16 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

Quoted 24 lines · Keith Busch
Quoted 8 lines · Jens Axboe
block/blk-mq.c +1 -2
+void blk_mq_quiesce_queue_wait(struct request_queue *q)
 {
 	struct blk_mq_hw_ctx *hctx;
 	unsigned int i;
 	bool rcu = false;
 
-	blk_mq_quiesce_queue_nowait(q);
-

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 227

Quoted 10 lines
block/blk-mq.c +1 -0
 	queue_for_each_hw_ctx(q, hctx, i) {
 		if (hctx->flags & BLK_MQ_F_BLOCKING)
 			synchronize_srcu(hctx->srcu);
 		else
 			rcu = true;
 	}
+
 	if (rcu)
 		synchronize_rcu();
 }

Either all the hctx's are blocking or none of them are: we don't need to iterate the hctx's to see which sync method to use. We can add at the very beginning (and get rid of 'bool rcu'):

Quoted 4 lines
	if (!(q->tag_set->flags & BLK_MQ_F_BLOCKING)) {
		synchronize_rcu();
		return;
	}

Agree, was just copy/pasting the existing code.

Quoted 5 lines

But the issue Sagi is trying to address is quiescing a lot request queues sharing a tagset where synchronize_rcu() is too time consuming to do repeatedly. He wants to synchrnoize once for the entire tagset rather than per-request_queue, so I think he needs an API taking a 'struct blk_mq_tag_set' instead of a 'struct request_queue'.

Gotcha, yeah that won't work for multiple queues obviously.

Are all these queues sharing a tag set? If so, yes that seems like the right abstraction. And the pointer addition is a much better idea than including a full srcu/rcu struct.

Signature · 1 line
Jens Axboe
#17 lore raw

Re: [PATCH v3 1/2] blk-mq: add async quiesce interface

In reply to Sagi Grimberg
Quoted 126 lines · Sagi Grimberg
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
block/blk-mq.c +12 -0
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+	struct blk_mq_hw_ctx *hctx;
+	unsigned int i;
+
+	blk_mq_quiesce_queue_nowait(q);
+
+	queue_for_each_hw_ctx(q, hctx, i) {
+		init_completion(&hctx->rcu_sync.completion);
+		init_rcu_head(&hctx->rcu_sync.head);
+		if (hctx->flags & BLK_MQ_F_BLOCKING)
+			call_srcu(hctx->srcu, &hctx->rcu_sync.head,
Quoted 8 lines

block/blk-mq.c void blk_mq_quiesce_queue_nowait(struct request_queue *q) · line 237

Quoted 5 lines
block/blk-mq.c +5 -0
+				wakeme_after_rcu);
+		else
+			call_rcu(&hctx->rcu_sync.head,
+				wakeme_after_rcu);
+	}

Looks not necessary to do anything in case of !BLK_MQ_F_BLOCKING, and single synchronize_rcu() is OK for all hctx during waiting.

Quoted 2 lines

That's true, but I want a single interface for both. v2 had exactly that, but I decided that this approach is better.

Not sure one new interface is needed, and one simple way is to:

1) call blk_mq_quiesce_queue_nowait() for each request queue

2) wait in driver specific way

Or just wondering why nvme doesn't use set->tag_list to retrieve NS, then you may add per-tagset APIs for the waiting.

Quoted 6 lines
Quoted 3 lines

Because it puts assumptions on how quiesce works, which is something I'd like to avoid because I think its cleaner, what do others think? Jens? Christoph?

I'd prefer to have it in a helper, and just have blk_mq_quiesce_queue() call that.

I agree with this approach as well.

Jens, this mean that we use the call_rcu mechanism also for non-blocking hctxs, because the caller will call it for multiple request queues (see patch 2) and we don't want to call synchronize_rcu for every request queue serially, we want it to happen in parallel.

Which leaves us with the patchset as it is, just to convert the rcu_synchronize structure to be dynamically allocated on the heap rather than keeping it statically allocated in the hctx.

This is how it looks:
--

block/blk-mq.c +46 -0
index abcf590f6238..d913924117d2 100644
@@ -209,6 +209,52 @@ void blk_mq_quiesce_queue_nowait(struct request_queue
 *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
 
+void blk_mq_quiesce_queue_async(struct request_queue *q)
+{
+       struct blk_mq_hw_ctx *hctx;
+       unsigned int i;
+       int rcu = false;
+
+       blk_mq_quiesce_queue_nowait(q);
+
+       queue_for_each_hw_ctx(q, hctx, i) {
+               hctx->rcu_sync = kmalloc(sizeof(*hctx->rcu_sync),
 GFP_KERNEL);
+               if (!hctx->rcu_sync) {
+                       /* fallback to serial rcu sync */
+                       if (hctx->flags & BLK_MQ_F_BLOCKING)
+                               synchronize_srcu(hctx->srcu);
+                       else
+                               rcu = true;
+               } else {
+                       init_completion(&hctx->rcu_sync->completion);
+                       init_rcu_head(&hctx->rcu_sync->head);
+                       if (hctx->flags & BLK_MQ_F_BLOCKING)
+                               call_srcu(hctx->srcu, &hctx->rcu_sync->head,
+                                       wakeme_after_rcu);
+                       else
+                               call_rcu(&hctx->rcu_sync->head,
+                                       wakeme_after_rcu);
+               }
+       }
+       if (rcu)
+               synchronize_rcu();
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async);
+
+void blk_mq_quiesce_queue_async_wait(struct request_queue *q)
+{
+       struct blk_mq_hw_ctx *hctx;
+       unsigned int i;
+
+       queue_for_each_hw_ctx(q, hctx, i) {
+               if (!hctx->rcu_sync)
+                       continue;
+               wait_for_completion(&hctx->rcu_sync->completion);
+               destroy_rcu_head(&hctx->rcu_sync->head);
+       }
+}
+EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_async_wait);
+
 /**

* blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished
* @q: request queue.

include/linux/blk-mq.h +1 -0
index 23230c1d031e..7213ce56bb31 100644
@@ -5,6 +5,7 @@
 #include <linux/blkdev.h>
 #include <linux/sbitmap.h>
 #include <linux/srcu.h>
+#include <linux/rcupdate_wait.h>
 
 struct blk_mq_tags;
 struct blk_flush_queue;

include/linux/blk-mq.h struct blk_mq_hw_ctx { · line 174

Quoted 4 lines
include/linux/blk-mq.h +1 -0
@@ -170,6 +171,7 @@ struct blk_mq_hw_ctx {
         */
        struct list_head        hctx_list;
 
+       struct rcu_synchronize  *rcu_sync;

The above pointer needn't to be added to blk_mq_hw_ctx, and it can be allocated on heap and passed to the waiting helper.

Thanks,
Ming

author maintainer
#18 lore raw

PATCH v3 2/2 nvme: improve quiesce time for large amount of namespaces

In reply to Sagi Grimberg

nvme currently will synchronize queue quiesce for each namespace at once. This can slow down failover time (which first quiesce all ns queues) if we have a large amount of namespaces. Instead, we want to use an async interface and do the namespaces quiesce in parallel rather than serially.

---
 drivers/nvme/host/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +3 -1
index c16bfdff2953..45f1559ee160 100644
@@ -4535,7 +4535,9 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl)
 
 	down_read(&ctrl->namespaces_rwsem);
 	list_for_each_entry(ns, &ctrl->namespaces, list)
-		blk_mq_quiesce_queue(ns->queue);
+		blk_mq_quiesce_queue_async(ns->queue);
+	list_for_each_entry(ns, &ctrl->namespaces, list)
+		blk_mq_quiesce_queue_async_wait(ns->queue);
 	up_read(&ctrl->namespaces_rwsem);
 }
 EXPORT_SYMBOL_GPL(nvme_stop_queues);
Signature · 1 line
2.25.1