linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Change the default loop driver I/O scheduler
@ 2021-08-05 17:41 Bart Van Assche
  2021-08-05 17:41 ` [PATCH v3 1/2] blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bart Van Assche @ 2021-08-05 17:41 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Jaegeuk Kim, Bart Van Assche

Hi Jens,

The two patches in this patch series change the default I/O scheduler of
request queues created by the loop driver from 'mq-deadline' into 'none'.
Please consider these two patches for inclusion in the Linux kernel.

Thanks,

Bart.

Changes compared to v2:
- Dropped the patch that makes the loop driver queue depth configurable via a
  kernel module parameter.
- Added a q->tag_set test in patch 1/2. Although I'm not sure this test is
  still needed after Christoph's latest queue creation rework, it doesn't harm.

Changes compared to v1:
- Introduced BLK_MQ_F_NO_SCHED_BY_DEFAULT and use it in the loop driver.
- Removed BLK_MQ_F_NO_SCHED again from the loop driver.

Bart Van Assche (2):
  blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag
  loop: Select I/O scheduler 'none' from inside add_disk()

 block/elevator.c       | 3 +++
 drivers/block/loop.c   | 3 ++-
 include/linux/blk-mq.h | 6 ++++++
 3 files changed, 11 insertions(+), 1 deletion(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/2] blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag
  2021-08-05 17:41 [PATCH v3 0/2] Change the default loop driver I/O scheduler Bart Van Assche
@ 2021-08-05 17:41 ` Bart Van Assche
  2021-08-05 17:42 ` [PATCH v3 2/2] loop: Select I/O scheduler 'none' from inside add_disk() Bart Van Assche
  2021-08-05 17:49 ` [PATCH v3 0/2] Change the default loop driver I/O scheduler Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2021-08-05 17:41 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Jaegeuk Kim, Bart Van Assche,
	Ming Lei, Tetsuo Handa, Martijn Coenen

elevator_get_default() uses the following algorithm to select an I/O
scheduler from inside add_disk():
- In case of a single hardware queue or if sharing hardware queues across
  multiple request queues (BLK_MQ_F_TAG_HCTX_SHARED), use mq-deadline.
- Otherwise, use 'none'.

This is a good choice for most but not for all block drivers. Make it
possible to override the selection of mq-deadline with a new flag,
namely BLK_MQ_F_NO_SCHED_BY_DEFAULT.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Martijn Coenen <maco@android.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/elevator.c       | 3 +++
 include/linux/blk-mq.h | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/block/elevator.c b/block/elevator.c
index 52ada14cfe45..d0295e68f481 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -630,6 +630,9 @@ static inline bool elv_support_iosched(struct request_queue *q)
  */
 static struct elevator_type *elevator_get_default(struct request_queue *q)
 {
+	if (q->tag_set && q->tag_set->flags & BLK_MQ_F_NO_SCHED_BY_DEFAULT)
+		return NULL;
+
 	if (q->nr_hw_queues != 1 &&
 			!blk_mq_is_sbitmap_shared(q->tag_set->flags))
 		return NULL;
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 1d18447ebebc..22215db36122 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -404,7 +404,13 @@ enum {
 	BLK_MQ_F_STACKING	= 1 << 2,
 	BLK_MQ_F_TAG_HCTX_SHARED = 1 << 3,
 	BLK_MQ_F_BLOCKING	= 1 << 5,
+	/* Do not allow an I/O scheduler to be configured. */
 	BLK_MQ_F_NO_SCHED	= 1 << 6,
+	/*
+	 * Select 'none' during queue registration in case of a single hwq
+	 * or shared hwqs instead of 'mq-deadline'.
+	 */
+	BLK_MQ_F_NO_SCHED_BY_DEFAULT	= 1 << 7,
 	BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
 	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] loop: Select I/O scheduler 'none' from inside add_disk()
  2021-08-05 17:41 [PATCH v3 0/2] Change the default loop driver I/O scheduler Bart Van Assche
  2021-08-05 17:41 ` [PATCH v3 1/2] blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag Bart Van Assche
@ 2021-08-05 17:42 ` Bart Van Assche
  2021-08-05 17:49 ` [PATCH v3 0/2] Change the default loop driver I/O scheduler Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2021-08-05 17:42 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Jaegeuk Kim, Bart Van Assche,
	Ming Lei, Tetsuo Handa, Martijn Coenen

We noticed that the user interface of Android devices becomes very slow
under memory pressure. This is because Android uses the zram driver on top
of the loop driver for swapping, because under memory pressure the swap
code alternates reads and writes quickly, because mq-deadline is the
default scheduler for loop devices and because mq-deadline delays writes by
five seconds for such a workload with default settings. Fix this by making
the kernel select I/O scheduler 'none' from inside add_disk() for loop
devices. This default can be overridden at any time from user space,
e.g. via a udev rule. This approach has an advantage compared to changing
the I/O scheduler from userspace from 'mq-deadline' into 'none', namely
that synchronize_rcu() does not get called.

This patch changes the default I/O scheduler for loop devices from
'mq-deadline' into 'none'.

Additionally, this patch reduces the Android boot time on my test setup
with 0.5 seconds compared to configuring the loop I/O scheduler from user
space.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Martijn Coenen <maco@android.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/block/loop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index f8486d9b75a4..fa1c298a8cfb 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2333,7 +2333,8 @@ static int loop_add(int i)
 	lo->tag_set.queue_depth = 128;
 	lo->tag_set.numa_node = NUMA_NO_NODE;
 	lo->tag_set.cmd_size = sizeof(struct loop_cmd);
-	lo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_STACKING;
+	lo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_STACKING |
+		BLK_MQ_F_NO_SCHED_BY_DEFAULT;
 	lo->tag_set.driver_data = lo;
 
 	err = blk_mq_alloc_tag_set(&lo->tag_set);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 0/2] Change the default loop driver I/O scheduler
  2021-08-05 17:41 [PATCH v3 0/2] Change the default loop driver I/O scheduler Bart Van Assche
  2021-08-05 17:41 ` [PATCH v3 1/2] blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag Bart Van Assche
  2021-08-05 17:42 ` [PATCH v3 2/2] loop: Select I/O scheduler 'none' from inside add_disk() Bart Van Assche
@ 2021-08-05 17:49 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2021-08-05 17:49 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: linux-block, Christoph Hellwig, Jaegeuk Kim

On 8/5/21 11:41 AM, Bart Van Assche wrote:
> Hi Jens,
> 
> The two patches in this patch series change the default I/O scheduler of
> request queues created by the loop driver from 'mq-deadline' into 'none'.
> Please consider these two patches for inclusion in the Linux kernel.

Applied for 5.15, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-05 17:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 17:41 [PATCH v3 0/2] Change the default loop driver I/O scheduler Bart Van Assche
2021-08-05 17:41 ` [PATCH v3 1/2] blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag Bart Van Assche
2021-08-05 17:42 ` [PATCH v3 2/2] loop: Select I/O scheduler 'none' from inside add_disk() Bart Van Assche
2021-08-05 17:49 ` [PATCH v3 0/2] Change the default loop driver I/O scheduler Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).