diff mbox series

[7/7] block: Initialize BIO I/O priority early

Message ID 20181119035131.11255-8-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series Improve I/O priority handling | expand

Commit Message

Damien Le Moal Nov. 19, 2018, 3:51 a.m. UTC
For the synchronous I/O path case (read(), write() etc system calls), a
BIO I/O priority is not initialized until the execution of
blk_init_request_from_bio() when the BIO is submitted and a request
initialized for the BIO execution. This is due to the ki_ioprio field of
the struct kiocb defined on stack being always initialized to
IOPRIO_CLASS_NONE, regardless of the calling process I/O context ioprio
value set with ioprio_set(). This late initialization can result in the
BIO being merged to pending requests even when the I/O priorities
differ.

Fix this by initializing the ki_iopriority field of on stack struct
kiocb using the get_current_ioprio() helper, ensuring that all BIOs
allocated and submitted for the system call execution see the correct
intended I/O priority early. With this, since a BIO I/O priority is
always set to the intended effective value for both the sync and async
path, blk_init_request_from_bio() can be simplified.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/blk-core.c   | 5 +----
 include/linux/fs.h | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

Comments

Christoph Hellwig Nov. 19, 2018, 8:19 a.m. UTC | #1
On Mon, Nov 19, 2018 at 12:51:31PM +0900, Damien Le Moal wrote:
> For the synchronous I/O path case (read(), write() etc system calls), a
> BIO I/O priority is not initialized until the execution of
> blk_init_request_from_bio() when the BIO is submitted and a request
> initialized for the BIO execution. This is due to the ki_ioprio field of
> the struct kiocb defined on stack being always initialized to
> IOPRIO_CLASS_NONE, regardless of the calling process I/O context ioprio
> value set with ioprio_set(). This late initialization can result in the
> BIO being merged to pending requests even when the I/O priorities
> differ.
> 
> Fix this by initializing the ki_iopriority field of on stack struct
> kiocb using the get_current_ioprio() helper, ensuring that all BIOs
> allocated and submitted for the system call execution see the correct
> intended I/O priority early. With this, since a BIO I/O priority is
> always set to the intended effective value for both the sync and async
> path, blk_init_request_from_bio() can be simplified.
> 
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Adam Manzanares Nov. 19, 2018, 7:11 p.m. UTC | #2
On Mon, 2018-11-19 at 12:51 +0900, Damien Le Moal wrote:
> For the synchronous I/O path case (read(), write() etc system calls),
> a
> BIO I/O priority is not initialized until the execution of
> blk_init_request_from_bio() when the BIO is submitted and a request
> initialized for the BIO execution. This is due to the ki_ioprio field
> of
> the struct kiocb defined on stack being always initialized to
> IOPRIO_CLASS_NONE, regardless of the calling process I/O context
> ioprio
> value set with ioprio_set(). This late initialization can result in
> the
> BIO being merged to pending requests even when the I/O priorities
> differ.
> 
> Fix this by initializing the ki_iopriority field of on stack struct
> kiocb using the get_current_ioprio() helper, ensuring that all BIOs
> allocated and submitted for the system call execution see the correct
> intended I/O priority early. With this, since a BIO I/O priority is
> always set to the intended effective value for both the sync and
> async
> path, blk_init_request_from_bio() can be simplified.
> 
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>

Nice cleanup, looks good. Thanks Damien.

Reviewed-by: Adam Manzanares <adam.manzanares@wdc.com>


> ---
>  block/blk-core.c   | 5 +----
>  include/linux/fs.h | 2 +-
>  2 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/block/blk-core.c b/block/blk-core.c
> index dde30b08aa14..04f5be473638 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -814,10 +814,7 @@ void blk_init_request_from_bio(struct request
> *req, struct bio *bio)
>  		req->cmd_flags |= REQ_FAILFAST_MASK;
>  
>  	req->__sector = bio->bi_iter.bi_sector;
> -	if (ioprio_valid(bio_prio(bio)))
> -		req->ioprio = bio_prio(bio);
> -	else
> -		req->ioprio = get_current_ioprio();
> +	req->ioprio = bio_prio(bio);
>  	req->write_hint = bio->bi_write_hint;
>  	blk_rq_bio_prep(req->q, req, bio);
>  }
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index c95c0807471f..a1ab233e6469 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2021,7 +2021,7 @@ static inline void init_sync_kiocb(struct kiocb
> *kiocb, struct file *filp)
>  		.ki_filp = filp,
>  		.ki_flags = iocb_flags(filp),
>  		.ki_hint = ki_hint_validate(file_write_hint(filp)),
> -		.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0),
> +		.ki_ioprio = get_current_ioprio(),
>  	};
>  }
>
diff mbox series

Patch

diff --git a/block/blk-core.c b/block/blk-core.c
index dde30b08aa14..04f5be473638 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -814,10 +814,7 @@  void blk_init_request_from_bio(struct request *req, struct bio *bio)
 		req->cmd_flags |= REQ_FAILFAST_MASK;
 
 	req->__sector = bio->bi_iter.bi_sector;
-	if (ioprio_valid(bio_prio(bio)))
-		req->ioprio = bio_prio(bio);
-	else
-		req->ioprio = get_current_ioprio();
+	req->ioprio = bio_prio(bio);
 	req->write_hint = bio->bi_write_hint;
 	blk_rq_bio_prep(req->q, req, bio);
 }
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c95c0807471f..a1ab233e6469 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2021,7 +2021,7 @@  static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
 		.ki_filp = filp,
 		.ki_flags = iocb_flags(filp),
 		.ki_hint = ki_hint_validate(file_write_hint(filp)),
-		.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0),
+		.ki_ioprio = get_current_ioprio(),
 	};
 }