Two loop driver patches
cover Two loop driver patches
Hi Jens,
The two patches in this patch series are what I came up with while testing Android software. Please consider these patches for inclusion in the upstream kernel.
Thanks,
Bart.
Bart Van Assche (2):
loop: Prevent that an I/O scheduler is assigned
loop: Add the default_queue_depth kernel module parameter
drivers/block/loop.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
PATCH 1/2 loop: Prevent that an I/O scheduler is assigned
Loop devices have a single hardware queue. Hence, the block layer function elevator_get_default() selects the mq-deadline scheduler for loop devices. Using the mq-deadline scheduler or any other I/O scheduler for loop devices incurs unnecessary overhead. Make the loop driver pass the flag BLK_MQ_F_NOSCHED to the block layer core such that no I/O scheduler can be associated with block devices. This approach has an advantage compared to letting udevd change the loop I/O scheduler to none, namely that synchronize_rcu() does not get called.
It is intentional that the flag BLK_MQ_F_SHOULD_MERGE is preserved.
This patch reduces the Android boot time on my test setup with 0.5 seconds.
--- drivers/block/loop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/loop.c +2 -1
@@ -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 ; lo->tag_set.driver_data = lo; err =blk_mq_alloc_tag_set (&lo->tag_set);
Re: [PATCH 1/2] loop: Prevent that an I/O scheduler is assigned
Quoted 9 lines · Bart Van Assche
Loop devices have a single hardware queue. Hence, the block layer function
elevator_get_default()selects the mq-deadline scheduler for loop devices. Using the mq-deadline scheduler or any other I/O scheduler for loop devices incurs unnecessary overhead. Make the loop driver pass the flagBLK_MQ_F_NOSCHEDto the block layer core such that no I/O scheduler can be associated with block devices. This approach has an advantage compared to letting udevd change the loop I/O scheduler to none, namely thatsynchronize_rcu()does not get called.
Quoted 3 lines
It is intentional that the flag
BLK_MQ_F_SHOULD_MERGEis preserved.This patch reduces the Android boot time on my test setup with 0.5 seconds.
Can you investigate why none reduces Android boot time? Or reproduce & understand it by a fio simulation on your setting?
Quoted 16 lines
Cc Ming Lei <[email protected]>Cc Tetsuo Handa <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Martijn Coenen <[email protected]>Cc Jaegeuk Kim <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/block/loop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/block/loop.c +0
-0
drivers/block/loop.c static int loop_add(int i) · line 2337
Quoted 6 lines
drivers/block/loop.c +2
-1@@ -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 ;
Loop directio needs io merge, so it isn't good to set NO_SCHED unconditionally, see:
40326d8a33d5 ("block/loop: allow request merge for directio mode")
Thanks,
Ming
Re: [PATCH 1/2] loop: Prevent that an I/O scheduler is assigned
Quoted 10 lines · Ming Lei
Quoted 9 lines · Bart Van Assche
Loop devices have a single hardware queue. Hence, the block layer function
elevator_get_default()selects the mq-deadline scheduler for loop devices. Using the mq-deadline scheduler or any other I/O scheduler for loop devices incurs unnecessary overhead. Make the loop driver pass the flagBLK_MQ_F_NOSCHEDto the block layer core such that no I/O scheduler can be associated with block devices. This approach has an advantage compared to letting udevd change the loop I/O scheduler to none, namely thatsynchronize_rcu()does not get called.
Quoted 6 lines
Quoted 3 lines
It is intentional that the flag
BLK_MQ_F_SHOULD_MERGEis preserved.This patch reduces the Android boot time on my test setup with 0.5 seconds.
Can you investigate why none reduces Android boot time? Or reproduce & understand it by a fio simulation on your setting?
Hi Ming,
The software process called apexd creates multiple loop devices while the device is booting. Using BLK_MQ_F_NO_SCHED is faster than letting apexd change the I/O scheduler from mq-deadline into 'none' since the latter involves calling synchronize_rcu() once per loop device.
Quoted 15 lines
drivers/block/loop.c static int loop_add(int i) · line 2337
Quoted 11 lines
drivers/block/loop.c +2
-1@@ -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 ;Loop directio needs io merge, so it isn't good to set
NO_SCHEDunconditionally, see:
Quoted 1 line
40326d8a33d5("block/loop: allow request merge for directio mode")
Setting BLK_MQ_F_NO_SCHED only for buffered I/O mode could be tricky since the loop driver creates a request queue before the I/O mode is configured. Anyway, I will look into this.
Bart.
Re: [PATCH 1/2] loop: Prevent that an I/O scheduler is assigned
Quoted 18 lines · Bart Van Assche
Quoted 10 lines · Ming Lei
Quoted 9 lines · Bart Van Assche
Loop devices have a single hardware queue. Hence, the block layer function
elevator_get_default()selects the mq-deadline scheduler for loop devices. Using the mq-deadline scheduler or any other I/O scheduler for loop devices incurs unnecessary overhead. Make the loop driver pass the flagBLK_MQ_F_NOSCHEDto the block layer core such that no I/O scheduler can be associated with block devices. This approach has an advantage compared to letting udevd change the loop I/O scheduler to none, namely thatsynchronize_rcu()does not get called.Quoted 6 lines
Quoted 3 lines
It is intentional that the flag
BLK_MQ_F_SHOULD_MERGEis preserved.This patch reduces the Android boot time on my test setup with 0.5 seconds.
Can you investigate why none reduces Android boot time? Or reproduce & understand it by a fio simulation on your setting?
Quoted 6 lines
Hi Ming,
The software process called apexd creates multiple loop devices while the device is booting. Using
BLK_MQ_F_NO_SCHEDis faster than letting apexd change the I/O scheduler from mq-deadline into 'none' since the latter involves callingsynchronize_rcu()once per loop device.
OK, but why does apexd switch to none during booting? Does none perform better than deadline during booting in the Android setting?
Thanks,
Ming
PATCH 2/2 loop: Add the default_queue_depth kernel module parameter
In reply to Bart Van AsscheRecent versions of Android use the zram driver on top of the loop driver. There is a mismatch between the default loop driver queue depth (128) and the queue depth of the storage device in my test setup (32). That mismatch results in write latencies that are higher than necessary. Address this issue by making the default loop driver queue depth configurable. Compared to configuring the queue depth by writing into the nr_requests sysfs attribute, this approach does not involve calling synchronize_rcu() to modify the queue depth.
--- drivers/block/loop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/block/loop.c +4 -1
@@ -2098,6 +2098,9 @@ module_param(max_loop, int, 0444);MODULE_PARM_DESC (max_loop,"Maximum number of loop devices" );module_param (max_part, int,0444 );MODULE_PARM_DESC (max_part,"Maximum number of partitions per loop device" ); +static uint32_t default_queue_depth =128 ; +module_param (default_queue_depth, uint,0644 ); +MODULE_PARM_DESC (default_queue_depth,"Default loop device queue depth" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_BLOCKDEV_MAJOR (LOOP_MAJOR );
@@ -2330,7 +2333,7 @@ static int loop_add(int i) err = -ENOMEM ; lo->tag_set.ops = &loop_mq_ops; lo->tag_set.nr_hw_queues =1 ; - lo->tag_set.queue_depth =128 ; + lo->tag_set.queue_depth =max (default_queue_depth,2U ); 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 |
Re: [PATCH 2/2] loop: Add the default_queue_depth kernel module parameter
Quoted 35 lines · Bart Van Assche
Recent versions of Android use the zram driver on top of the loop driver. There is a mismatch between the default loop driver queue depth (128) and the queue depth of the storage device in my test setup (32). That mismatch results in write latencies that are higher than necessary. Address this issue by making the default loop driver queue depth configurable. Compared to configuring the queue depth by writing into the
nr_requestssysfs attribute, this approach does not involve callingsynchronize_rcu()to modify the queue depth.Cc Ming Lei <[email protected]>Cc Tetsuo Handa <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Martijn Coenen <[email protected]>Cc Jaegeuk Kim <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/block/loop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/block/loop.c +3
-0@@ -2098,6 +2098,9 @@ module_param(max_loop, int, 0444);MODULE_PARM_DESC (max_loop,"Maximum number of loop devices" );module_param (max_part, int,0444 );MODULE_PARM_DESC (max_part,"Maximum number of partitions per loop device" ); +static uint32_t default_queue_depth =128 ; +module_param (default_queue_depth, uint,0644 ); +MODULE_PARM_DESC (default_queue_depth,"Default loop device queue depth" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_BLOCKDEV_MAJOR (LOOP_MAJOR );
drivers/block/loop.c static int loop_add(int i) · line 2339
Quoted 8 lines
drivers/block/loop.c +1
-1@@ -2330,7 +2333,7 @@ static int loop_add(int i) err = -ENOMEM ; lo->tag_set.ops = &loop_mq_ops; lo->tag_set.nr_hw_queues =1 ; - lo->tag_set.queue_depth =128 ; + lo->tag_set.queue_depth =max (default_queue_depth,2U ); 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 |
Looks fine:
Signature · 1 line
Ming