random simple block cleanups
cover random simple block cleanups
Several simple cleanups/optimisations splitted out from the optimisation series.
Pavel Begunkov (3):
block: optimise boundary blkdev_read_iter's checks
block: clean up blk_mq_submit_bio() merging
block: convert fops.c magic constants to SHIFT_SECTOR
block/blk-mq-sched.c | 2 +- block/blk-mq-sched.h | 12 +----------- block/blk-mq.c | 15 +++++++-------- block/fops.c | 37 +++++++++++++++++++++---------------- 4 files changed, 30 insertions(+), 36 deletions(-)
Signature · 1 line
2.33.1
PATCH 1/3 block: optimise boundary blkdev_read_iter's checks
Combine pos and len checks and mark unlikely. Also, don't reexpand if it's not truncated.
--- block/fops.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
block/fops.c +11 -8
@@ -503,17 +503,20 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)size_t shorted =0 ;ssize_t ret; -if (pos >= size) -return 0 ; - - size -= pos; -if (iov_iter_count (to) > size) { - shorted =iov_iter_count (to) - size; -iov_iter_truncate (to, size); +if (unlikely (pos +iov_iter_count (to) > size)) { +if (pos >= size) +return 0 ; + size -= pos; +if (iov_iter_count (to) > size) { + shorted =iov_iter_count (to) - size; +iov_iter_truncate (to, size); + } } ret =generic_file_read_iter (iocb, to); -iov_iter_reexpand (to,iov_iter_count (to) + shorted); + +if (unlikely (shorted)) +iov_iter_reexpand (to,iov_iter_count (to) + shorted);return ret; }
Signature · 1 line
2.33.1
PATCH 2/3 block: clean up blk_mq_submit_bio() merging
In reply to Pavel BegunkovCombine blk_mq_sched_bio_merge() and blk_attempt_plug_merge() under a common if, so we don't check it twice.
--- block/blk-mq-sched.c | 2 +- block/blk-mq-sched.h | 12 +----------- block/blk-mq.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 20 deletions(-)
block/blk-mq-sched.c +1 -1
@@ -361,7 +361,7 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx) } } -bool __blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio, +bool blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio,unsigned int nr_segs) {struct elevator_queue *e = q->elevator;
block/blk-mq-sched.h +1 -11
@@ -12,7 +12,7 @@ void blk_mq_sched_assign_ioc(struct request *rq);bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio,unsigned int nr_segs,struct request **merged_request); -bool __blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio, +bool blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio,unsigned int nr_segs);bool blk_mq_sched_try_insert_merge (struct request_queue *q,struct request *rq,struct list_head *free);
@@ -42,16 +42,6 @@ static inline bool bio_mergeable(struct bio *bio)return !(bio->bi_opf &REQ_NOMERGE_FLAGS ); } -static inline bool -blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio, -unsigned int nr_segs) -{ -if (blk_queue_nomerges (q) || !bio_mergeable (bio)) -return false; - -return __blk_mq_sched_bio_merge (q, bio, nr_segs); -} -static inline bool blk_mq_sched_allow_merge (struct request_queue *q,struct request *rq,struct bio *bio)
block/blk-mq.c +7 -8
@@ -2481,7 +2481,6 @@ void blk_mq_submit_bio(struct bio *bio) {struct request_queue *q =bdev_get_queue (bio->bi_bdev);const int is_sync =op_is_sync (bio->bi_opf); -const int is_flush_fua =op_is_flush (bio->bi_opf);struct request *rq;struct blk_plug *plug;bool same_queue_rq = false;
@@ -2495,12 +2494,12 @@ void blk_mq_submit_bio(struct bio *bio)if (!bio_integrity_prep (bio)) goto queue_exit; -if (!is_flush_fua && !blk_queue_nomerges (q) && -blk_attempt_plug_merge (q, bio, nr_segs, &same_queue_rq)) - goto queue_exit; - -if (blk_mq_sched_bio_merge (q, bio, nr_segs)) - goto queue_exit; +if (!blk_queue_nomerges (q) &&bio_mergeable (bio)) { +if (blk_attempt_plug_merge (q, bio, nr_segs, &same_queue_rq)) + goto queue_exit; +if (blk_mq_sched_bio_merge (q, bio, nr_segs)) + goto queue_exit; + }rq_qos_throttle (q, bio);
@@ -2543,7 +2542,7 @@ void blk_mq_submit_bio(struct bio *bio)return ; } -if (is_flush_fua &&blk_insert_flush (rq)) +if (op_is_flush (bio->bi_opf) &&blk_insert_flush (rq))return ; if (plug && (q->nr_hw_queues == 1 ||
Signature · 1 line
2.33.1
PATCH 3/3 block: convert fops.c magic constants to SHIFT_SECTOR
In reply to Pavel BegunkovDon't use shifting by a magic number 9 but replace with a more descriptive SHIFT_SECTOR.
--- block/fops.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
block/fops.c +10 -8
@@ -76,7 +76,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,bio_init (&bio, vecs, nr_pages);bio_set_dev (&bio, bdev); - bio.bi_iter.bi_sector = pos >>9 ; + bio.bi_iter.bi_sector = pos >>SECTOR_SHIFT ; bio.bi_write_hint = iocb->ki_hint; bio.bi_private = current; bio.bi_end_io = blkdev_bio_end_io_simple;
@@ -225,7 +225,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,for (;;) {bio_set_dev (bio, bdev); - bio->bi_iter.bi_sector = pos >>9 ; + bio->bi_iter.bi_sector = pos >>SECTOR_SHIFT ; bio->bi_write_hint = iocb->ki_hint; bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io;
@@ -565,16 +565,18 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,switch (mode) {case FALLOC_FL_ZERO_RANGE :case FALLOC_FL_ZERO_RANGE |FALLOC_FL_KEEP_SIZE : - error =blkdev_issue_zeroout (bdev, start >>9 , len >>9 , -GFP_KERNEL ,BLKDEV_ZERO_NOUNMAP ); + error =blkdev_issue_zeroout (bdev, start >>SECTOR_SHIFT , + len >>SECTOR_SHIFT ,GFP_KERNEL , +BLKDEV_ZERO_NOUNMAP );break ;case FALLOC_FL_PUNCH_HOLE |FALLOC_FL_KEEP_SIZE : - error =blkdev_issue_zeroout (bdev, start >>9 , len >>9 , -GFP_KERNEL ,BLKDEV_ZERO_NOFALLBACK ); + error =blkdev_issue_zeroout (bdev, start >>SECTOR_SHIFT , + len >>SECTOR_SHIFT ,GFP_KERNEL , +BLKDEV_ZERO_NOFALLBACK );break ;case FALLOC_FL_PUNCH_HOLE |FALLOC_FL_KEEP_SIZE |FALLOC_FL_NO_HIDE_STALE : - error =blkdev_issue_discard (bdev, start >>9 , len >>9 , -GFP_KERNEL ,0 ); + error =blkdev_issue_discard (bdev, start >>SECTOR_SHIFT , + len >>SECTOR_SHIFT ,GFP_KERNEL ,0 );break ;default : error = -EOPNOTSUPP ;
Signature · 1 line
2.33.1
Re: [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
In reply to Pavel BegunkovQuoted 2 lines · Pavel Begunkov
Combine
blk_mq_sched_bio_merge()andblk_attempt_plug_merge()under a common if, so we don't check it twice.
Forgot to add that it's v2 with changes from Christoph's review.
Signature · 1 line
Pavel Begunkov
Re: [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
In reply to Pavel BegunkovLooks good,
Re: [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR
In reply to Pavel BegunkovQuoted 4 lines · Pavel Begunkov
Don't use shifting by a magic number 9 but replace with a more descriptive
SHIFT_SECTOR.Signed-off-by Pavel Begunkov <[email protected]>
Looks good,
Although I wonder if two new local variables in blkdev_fallocate wouldn't be even better..
Re: [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>
Great, thanks!
Signature · 1 line
Pavel Begunkov
Quoted 9 lines · Pavel Begunkov
Several simple cleanups/optimisations splitted out from the optimisation series.
Pavel Begunkov (3):
block: optimise boundary blkdev_read_iter's checks
block: clean upblk_mq_submit_bio()merging
block: convertfops.cmagic constants toSHIFT_SECTOR[...]
Applied, thanks!
[1/3] block: optimise boundary blkdev_read_iter's checks
commit: 6450fe1f668f410fe2ab69c79a52a0929a4a8296
[2/3] block: clean up blk_mq_submit_bio() merging
commit: 179ae84f7ef5225e03cd29cb9a75f6e90d2d7388
[3/3] block: convert fops.c magic constants to SHIFT_SECTOR
commit: 6549a874fb65e7ad4885d066ec314191cc137b52Best regards,
Signature · 1 line
Jens Axboe