Reduce code duplication
Subsystems (2)
v2 cover Reduce code duplication
Hello Jens,
This series contains three patches intended to reduce code duplication and two patches that simplify / optimize I/O priority handling. Please consider these patches for kernel v4.12.
Thanks,
Bart.
Changes compared to v1:
- Converted ternary operators into an if/then/else-sequence.
- Used EXPORT_SYMBOL_GPL() to export block layer internals.
Bart Van Assche (5):
block: Export blk_init_request_from_bio()
null_blk: Use blk_init_request_from_bio() instead of open-coding it
lightnvm: Use blk_init_request_from_bio() instead of open-coding it
block: Inline blk_rq_set_prio()
block: Optimize ioprio_best()
block/blk-core.c | 12 +++++++++--- block/blk-mq.c | 2 +- block/blk.h | 1 - block/ioprio.c | 12 +----------- drivers/block/null_blk.c | 9 +-------- drivers/nvme/host/lightnvm.c | 6 +----- include/linux/blkdev.h | 15 +-------------- 7 files changed, 14 insertions(+), 43 deletions(-)
Signature · 1 line
2.12.2
PATCH v2 1/5 block: Export blk_init_request_from_bio()
Export this function such that it becomes available to block drivers.
--- block/blk-core.c | 5 +++-- block/blk-mq.c | 2 +- block/blk.h | 1 - include/linux/blkdev.h | 1 + 4 files changed, 5 insertions(+), 4 deletions(-)
block/blk-core.c +3 -2
@@ -1628,7 +1628,7 @@ unsigned int blk_plug_queued_count(struct request_queue *q)return ret; } -void init_request_from_bio (struct request *req,struct bio *bio) +void blk_init_request_from_bio (struct request *req,struct bio *bio) {if (bio->bi_opf &REQ_RAHEAD ) req->cmd_flags |=REQ_FAILFAST_MASK ;
@@ -1640,6 +1640,7 @@ void init_request_from_bio(struct request *req, struct bio *bio) req->ioprio =bio_prio (bio);blk_rq_bio_prep (req->q, req, bio); } +EXPORT_SYMBOL_GPL (blk_init_request_from_bio);static blk_qc_t blk_queue_bio (struct request_queue *q,struct bio *bio) {
@@ -1730,7 +1731,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)* We don't worry about that case for efficiency. It won't happen * often, and the elevators are able to handle it. */ -init_request_from_bio (req, bio); +blk_init_request_from_bio (req, bio);if (test_bit (QUEUE_FLAG_SAME_COMP , &q->queue_flags)) req->cpu =raw_smp_processor_id ();
block/blk-mq.c +1 -1
@@ -1424,7 +1424,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)static void blk_mq_bio_to_request (struct request *rq,struct bio *bio) { -init_request_from_bio (rq, bio); +blk_init_request_from_bio (rq, bio);blk_account_io_start (rq, true); }
block/blk.h +0 -1
@@ -60,7 +60,6 @@ void blk_free_flush_queue(struct blk_flush_queue *q);int blk_init_rl (struct request_list *rl,struct request_queue *q,gfp_t gfp_mask);void blk_exit_rl (struct request_list *rl); -void init_request_from_bio (struct request *req,struct bio *bio);void blk_rq_bio_prep (struct request_queue *q,struct request *rq,struct bio *bio);void blk_queue_bypass_start (struct request_queue *q);
include/linux/blkdev.h +1 -0
@@ -924,6 +924,7 @@ extern int blk_register_queue(struct gendisk *disk);extern void blk_unregister_queue (struct gendisk *disk);extern blk_qc_t generic_make_request (struct bio *bio);extern void blk_rq_init (struct request_queue *q,struct request *rq); +extern void blk_init_request_from_bio (struct request *req,struct bio *bio);extern void blk_put_request (struct request *);extern void __blk_put_request (struct request_queue *,struct request *);extern struct request *blk_get_request (struct request_queue *,int ,gfp_t );
Signature · 1 line
2.12.2
Re: [PATCH v2 1/5] block: Export blk_init_request_from_bio()
Quoted 8 lines · Bart Van Assche
Export this function such that it becomes available to block drivers.
Signed-off-by Bart Van Assche <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Cc Matias Bj�rling <[email protected]>Cc Adam Manzanares <[email protected]>---
Looks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH v2 2/5 null_blk: Use blk_init_request_from_bio() instead of open-coding it
In reply to Bart Van AsscheThis patch changes the behavior of the null_blk driver for the LightNVM mode as follows:
* REQ_FAILFAST_MASK is set for read-ahead requests.
* If no I/O priority has been set in the bio, the I/O priority is copied from the I/O context.
* The rq_disk member is initialized if bio->bi_bdev != NULL.
* req->errors is initialized to zero.
--- drivers/block/null_blk.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/block/null_blk.c +1 -8
@@ -443,14 +443,7 @@ static int null_lnvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)if (IS_ERR (rq))return -ENOMEM ; - rq->__sector = bio->bi_iter.bi_sector; - rq->ioprio =bio_prio (bio); - -if (bio_has_data (bio)) - rq->nr_phys_segments =bio_phys_segments (q, bio); - - rq->__data_len = bio->bi_iter.bi_size; - rq->bio = rq->biotail = bio; +blk_init_request_from_bio (rq, bio); rq->end_io_data = rqd;
Signature · 1 line
2.12.2
Re: [PATCH v2 2/5] null_blk: Use blk_init_request_from_bio() instead of open-coding it
Quoted 8 lines · Bart Van Assche
This patch changes the behavior of the
null_blkdriver for the LightNVM mode as follows:
*REQ_FAILFAST_MASKis set for read-ahead requests.
* If no I/O priority has been set in the bio, the I/O priority is copied from the I/O context.
* Therq_diskmember is initialized ifbio->bi_bdev!= NULL.
*req->errorsis initialized to zero.
Quoted 5 lines
Signed-off-by Bart Van Assche <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Cc Matias Bj�rling <[email protected]>Cc Adam Manzanares <[email protected]>---
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH v2 3/5 lightnvm: Use blk_init_request_from_bio() instead of open-coding it
In reply to Bart Van AsscheThis patch changes the behavior of the lightnvm driver as follows:
* REQ_FAILFAST_MASK is set for read-ahead requests.
* If no I/O priority has been set in the bio, the I/O priority is copied from the I/O context.
* The rq_disk member is initialized if bio->bi_bdev != NULL.
* The bio sector offset is copied into req->__sector instead of retaining the value -1 set by blk_mq_alloc_request().
* req->errors is initialized to zero.
--- drivers/nvme/host/lightnvm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/nvme/host/lightnvm.c +1 -5
@@ -511,11 +511,7 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd) rq->cmd_flags &= ~REQ_FAILFAST_DRIVER ;if (bio) { - rq->ioprio =bio_prio (bio); - rq->__data_len = bio->bi_iter.bi_size; - rq->bio = rq->biotail = bio; -if (bio_has_data (bio)) - rq->nr_phys_segments =bio_phys_segments (q, bio); +blk_init_request_from_bio (rq, bio); }else { rq->ioprio =IOPRIO_PRIO_VALUE (IOPRIO_CLASS_BE ,IOPRIO_NORM ); rq->__data_len =0 ;
Signature · 1 line
2.12.2
Re: [PATCH v2 3/5] lightnvm: Use blk_init_request_from_bio() instead of open-coding it
Quoted 9 lines · Bart Van Assche
This patch changes the behavior of the lightnvm driver as follows:
*REQ_FAILFAST_MASKis set for read-ahead requests.
* If no I/O priority has been set in the bio, the I/O priority is copied from the I/O context.
* Therq_diskmember is initialized ifbio->bi_bdev!= NULL.
* The bio sector offset is copied intoreq->__sectorinstead of retaining the value -1 set byblk_mq_alloc_request().
*req->errorsis initialized to zero.
Quoted 5 lines
Signed-off-by Bart Van Assche <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Cc Matias Bj�rling <[email protected]>Cc Adam Manzanares <[email protected]>---
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH v2 4/5 block: Inline blk_rq_set_prio()
In reply to Bart Van AsscheSince only a single caller remains, inline blk_rq_set_prio(). Initialize req->ioprio even if no I/O priority has been set in the bio nor in the I/O context.
--- block/blk-core.c | 7 ++++++- include/linux/blkdev.h | 14 -------------- 2 files changed, 6 insertions(+), 15 deletions(-)
block/blk-core.c +6 -1
@@ -1630,14 +1630,19 @@ unsigned int blk_plug_queued_count(struct request_queue *q)void blk_init_request_from_bio (struct request *req,struct bio *bio) { +struct io_context *ioc =rq_ioc (bio); +if (bio->bi_opf &REQ_RAHEAD ) req->cmd_flags |=REQ_FAILFAST_MASK ; req->errors =0 ; req->__sector = bio->bi_iter.bi_sector; -blk_rq_set_prio (req,rq_ioc (bio));if (ioprio_valid (bio_prio (bio))) req->ioprio =bio_prio (bio); +else if (ioc) + req->ioprio = ioc->ioprio; +else + req->ioprio =IOPRIO_PRIO_VALUE (IOPRIO_CLASS_NONE ,0 );blk_rq_bio_prep (req->q, req, bio); }EXPORT_SYMBOL_GPL (blk_init_request_from_bio);
include/linux/blkdev.h +0 -14
@@ -1088,20 +1088,6 @@ static inline unsigned int blk_rq_count_bios(struct request *rq) }/* -* blk_rq_set_prio - associate a request with prio from ioc -* @rq: request of interest -* @ioc: target iocontext -* -* Assocate request prio with ioc prio so request based drivers -* can leverage priority information. -*/ -static inline void blk_rq_set_prio (struct request *rq,struct io_context *ioc) -{ -if (ioc) - rq->ioprio = ioc->ioprio; -} - -/* * Request issue related functions. */ extern struct request *blk_peek_request (struct request_queue *q);
Signature · 1 line
2.12.2
Re: [PATCH v2 4/5] block: Inline blk_rq_set_prio()
Quoted 10 lines · Bart Van Assche
Since only a single caller remains, inline
blk_rq_set_prio(). Initializereq->ioprioeven if no I/O priority has been set in the bio nor in the I/O context.Signed-off-by Bart Van Assche <[email protected]>Reviewed-by Adam Manzanares <[email protected]>Tested-by Adam Manzanares <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Cc Matias Bj�rling <[email protected]>---
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH v2 5/5 block: Optimize ioprio_best()
In reply to Bart Van AsscheSince ioprio_best() translates IOPRIO_CLASS_NONE into IOPRIO_CLASS_BE and since lower numerical priority values represent a higher priority a simple numerical comparison is sufficient.
--- block/ioprio.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
block/ioprio.c +1 -11
@@ -163,22 +163,12 @@ static int get_task_ioprio(struct task_struct *p)int ioprio_best (unsigned short aprio,unsigned short bprio) { -unsigned short aclass; -unsigned short bclass; -if (!ioprio_valid (aprio)) aprio =IOPRIO_PRIO_VALUE (IOPRIO_CLASS_BE ,IOPRIO_NORM );if (!ioprio_valid (bprio)) bprio =IOPRIO_PRIO_VALUE (IOPRIO_CLASS_BE ,IOPRIO_NORM ); - aclass =IOPRIO_PRIO_CLASS (aprio); - bclass =IOPRIO_PRIO_CLASS (bprio); -if (aclass == bclass) -return min (aprio, bprio); -if (aclass > bclass) -return bprio; -else -return aprio; +return min (aprio, bprio); }SYSCALL_DEFINE2 (ioprio_get, int, which, int, who)
Signature · 1 line
2.12.2
Quoted 5 lines · Bart Van Assche
Hello Jens,
This series contains three patches intended to reduce code duplication and two patches that simplify / optimize I/O priority handling. Please consider these patches for kernel v4.12.
Applied, thanks Bart.
Signature · 1 line
Jens Axboe