Skip to contentSkip to conversation

Change the default loop driver I/O scheduler

PATCH In review Bart Van Assche 2 participants 4 messages Aug 5, 2021 Block layer

lore
Share & tools
lore
#0 lore raw

v3 cover Change the default loop driver I/O scheduler

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(-)
#1 lore raw

PATCH v3 1/2 blk-mq: Introduce the BLK_MQ_F_NO_SCHED_BY_DEFAULT flag

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 <[email protected]>
Cc Ming Lei <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Martijn Coenen <[email protected]>
Cc Jaegeuk Kim <[email protected]>
---
 block/elevator.c       | 3 +++
 include/linux/blk-mq.h | 6 ++++++
 2 files changed, 9 insertions(+)
block/elevator.c +3 -0
index 52ada14cfe45..d0295e68f481 100644
@@ -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;
include/linux/blk-mq.h +6 -0
index 1d18447ebebc..22215db36122 100644
@@ -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,
 
#2 lore raw

PATCH v3 2/2 loop: Select I/O scheduler 'none' from inside add_disk()

In reply to Bart Van Assche

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 <[email protected]>
Cc Ming Lei <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Martijn Coenen <[email protected]>
Cc Jaegeuk Kim <[email protected]>
---
 drivers/block/loop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/loop.c +2 -1
index f8486d9b75a4..fa1c298a8cfb 100644
@@ -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);
maintainer
#3 lore raw
In reply to Bart Van Assche
Quoted 5 lines · 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.

Applied for 5.15, thanks.

Signature · 1 line
Jens Axboe