All of lore.kernel.org
 help / color / mirror / Atom feed
From: yangerkun <yangerkun@huawei.com>
To: <axboe@kernel.dk>
Cc: <linux-block@vger.kernel.org>, <yangerkun@huawei.com>,
	<yukuai3@huawei.com>
Subject: [RFC PATCH] block: stop wait rcu once we can ensure no io while elevator init
Date: Tue, 20 Jul 2021 14:31:47 +0800	[thread overview]
Message-ID: <20210720063147.966670-1-yangerkun@huawei.com> (raw)

'commit 737eb78e82d5 ("block: Delay default elevator initialization")'
delay elevator init to fix some problem for special device like SMR.
Also, the commit add the logic to ensure no IO can happened while
blk_mq_init_sched. However, blk_mq_freeze_queue/blk_mq_quiesce_queue
will add RCU Grace period which can lead some overhead(about 36 loop
device try to mount which each Grace period around 20ms).

For loop device, no io can happened while add_disk, so it's safe to skip
this step. Add flag QUEUE_FLAG_NO_INIT_IO to identify this case.

Signed-off-by: yangerkun <yangerkun@huawei.com>
---
 block/elevator.c       | 14 ++++++++++----
 drivers/block/loop.c   |  5 +++++
 include/linux/blkdev.h |  2 ++
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/block/elevator.c b/block/elevator.c
index 52ada14cfe45..ddf24afb999e 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -672,6 +672,7 @@ void elevator_init_mq(struct request_queue *q)
 {
 	struct elevator_type *e;
 	int err;
+	bool no_init_io;
 
 	if (!elv_support_iosched(q))
 		return;
@@ -688,13 +689,18 @@ void elevator_init_mq(struct request_queue *q)
 	if (!e)
 		return;
 
-	blk_mq_freeze_queue(q);
-	blk_mq_quiesce_queue(q);
+	no_init_io = blk_queue_no_init_io(q);
+	if (!no_init_io) {
+		blk_mq_freeze_queue(q);
+		blk_mq_quiesce_queue(q);
+	}
 
 	err = blk_mq_init_sched(q, e);
 
-	blk_mq_unquiesce_queue(q);
-	blk_mq_unfreeze_queue(q);
+	if (!no_init_io) {
+		blk_mq_unquiesce_queue(q);
+		blk_mq_unfreeze_queue(q);
+	}
 
 	if (err) {
 		pr_warn("\"%s\" elevator initialization failed, "
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index f37b9e3d833c..4667273bf071 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2326,6 +2326,11 @@ static int loop_add(int i)
 	disk->private_data	= lo;
 	disk->queue		= lo->lo_queue;
 	sprintf(disk->disk_name, "loop%d", i);
+	/*
+	 * There won't be io before add_disk, QUEUE_FLAG_NO_INIT_IO can help
+	 * to save time while elevator_init_mq.
+	 */
+	blk_queue_flag_set(QUEUE_FLAG_NO_INIT_IO, lo->lo_queue);
 	add_disk(disk);
 	mutex_unlock(&loop_ctl_mutex);
 	return i;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 3177181c4326..b070c902d8c9 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -603,6 +603,7 @@ struct request_queue {
 #define QUEUE_FLAG_RQ_ALLOC_TIME 27	/* record rq->alloc_time_ns */
 #define QUEUE_FLAG_HCTX_ACTIVE	28	/* at least one blk-mq hctx is active */
 #define QUEUE_FLAG_NOWAIT       29	/* device supports NOWAIT */
+#define QUEUE_FLAG_NO_INIT_IO	30	/* no IO can happen while elevator_init_mq */
 
 #define QUEUE_FLAG_MQ_DEFAULT	((1 << QUEUE_FLAG_IO_STAT) |		\
 				 (1 << QUEUE_FLAG_SAME_COMP) |		\
@@ -649,6 +650,7 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
 #define blk_queue_fua(q)	test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags)
 #define blk_queue_registered(q)	test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags)
 #define blk_queue_nowait(q)	test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags)
+#define blk_queue_no_init_io(q)	test_bit(QUEUE_FLAG_NO_INIT_IO, &(q)->queue_flags)
 
 extern void blk_set_pm_only(struct request_queue *q);
 extern void blk_clear_pm_only(struct request_queue *q);
-- 
2.31.1


             reply	other threads:[~2021-07-20  6:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20  6:31 yangerkun [this message]
2021-07-20 14:32 ` [RFC PATCH] block: stop wait rcu once we can ensure no io while elevator init yangerkun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210720063147.966670-1-yangerkun@huawei.com \
    --to=yangerkun@huawei.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.