All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] random simple block cleanups
@ 2021-10-20 19:00 Pavel Begunkov
  2021-10-20 19:00 ` [PATCH 1/3] block: optimise boundary blkdev_read_iter's checks Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Pavel Begunkov @ 2021-10-20 19:00 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe, 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 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(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] block: optimise boundary blkdev_read_iter's checks
  2021-10-20 19:00 [PATCH 0/3] random simple block cleanups Pavel Begunkov
@ 2021-10-20 19:00 ` Pavel Begunkov
  2021-10-20 19:00 ` [PATCH 2/3] block: clean up blk_mq_submit_bio() merging Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Pavel Begunkov @ 2021-10-20 19:00 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe, Pavel Begunkov, Christoph Hellwig

Combine pos and len checks and mark unlikely. Also, don't reexpand if
it's not truncated.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 block/fops.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/block/fops.c b/block/fops.c
index 21d25ee0e4bf..8f733c919ed1 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -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;
 }
 
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
  2021-10-20 19:00 [PATCH 0/3] random simple block cleanups Pavel Begunkov
  2021-10-20 19:00 ` [PATCH 1/3] block: optimise boundary blkdev_read_iter's checks Pavel Begunkov
@ 2021-10-20 19:00 ` Pavel Begunkov
  2021-10-20 19:04   ` Pavel Begunkov
  2021-10-21  8:30   ` Christoph Hellwig
  2021-10-20 19:00 ` [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR Pavel Begunkov
  2021-10-21 14:27 ` [PATCH 0/3] random simple block cleanups Jens Axboe
  3 siblings, 2 replies; 9+ messages in thread
From: Pavel Begunkov @ 2021-10-20 19:00 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe, Pavel Begunkov

Combine blk_mq_sched_bio_merge() and blk_attempt_plug_merge() under a
common if, so we don't check it twice.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 block/blk-mq-sched.c |  2 +-
 block/blk-mq-sched.h | 12 +-----------
 block/blk-mq.c       | 15 +++++++--------
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index e85b7556b096..5b259fdea794 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -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;
diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h
index 98836106b25f..25d1034952b6 100644
--- a/block/blk-mq-sched.h
+++ b/block/blk-mq-sched.h
@@ -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)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a71aeed7b987..f159d007a015 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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 ||
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR
  2021-10-20 19:00 [PATCH 0/3] random simple block cleanups Pavel Begunkov
  2021-10-20 19:00 ` [PATCH 1/3] block: optimise boundary blkdev_read_iter's checks Pavel Begunkov
  2021-10-20 19:00 ` [PATCH 2/3] block: clean up blk_mq_submit_bio() merging Pavel Begunkov
@ 2021-10-20 19:00 ` Pavel Begunkov
  2021-10-21  8:31   ` Christoph Hellwig
  2021-10-21 14:27 ` [PATCH 0/3] random simple block cleanups Jens Axboe
  3 siblings, 1 reply; 9+ messages in thread
From: Pavel Begunkov @ 2021-10-20 19:00 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe, Pavel Begunkov

Don't use shifting by a magic number 9 but replace with a more
descriptive SHIFT_SECTOR.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 block/fops.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/block/fops.c b/block/fops.c
index 8f733c919ed1..396537598e3e 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -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;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
  2021-10-20 19:00 ` [PATCH 2/3] block: clean up blk_mq_submit_bio() merging Pavel Begunkov
@ 2021-10-20 19:04   ` Pavel Begunkov
  2021-10-21  8:30   ` Christoph Hellwig
  1 sibling, 0 replies; 9+ messages in thread
From: Pavel Begunkov @ 2021-10-20 19:04 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe

On 10/20/21 20:00, Pavel Begunkov wrote:
> Combine blk_mq_sched_bio_merge() and blk_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.

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
  2021-10-20 19:00 ` [PATCH 2/3] block: clean up blk_mq_submit_bio() merging Pavel Begunkov
  2021-10-20 19:04   ` Pavel Begunkov
@ 2021-10-21  8:30   ` Christoph Hellwig
  2021-10-21 13:32     ` Pavel Begunkov
  1 sibling, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2021-10-21  8:30 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: linux-block, Jens Axboe

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR
  2021-10-20 19:00 ` [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR Pavel Begunkov
@ 2021-10-21  8:31   ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-10-21  8:31 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: linux-block, Jens Axboe

On Wed, Oct 20, 2021 at 08:00:50PM +0100, Pavel Begunkov wrote:
> Don't use shifting by a magic number 9 but replace with a more
> descriptive SHIFT_SECTOR.
> 
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

Although I wonder if two new local variables in blkdev_fallocate
wouldn't be even better..

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] block: clean up blk_mq_submit_bio() merging
  2021-10-21  8:30   ` Christoph Hellwig
@ 2021-10-21 13:32     ` Pavel Begunkov
  0 siblings, 0 replies; 9+ messages in thread
From: Pavel Begunkov @ 2021-10-21 13:32 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-block, Jens Axboe

On 10/21/21 09:30, Christoph Hellwig wrote:
> Looks good,
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Great, thanks!

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] random simple block cleanups
  2021-10-20 19:00 [PATCH 0/3] random simple block cleanups Pavel Begunkov
                   ` (2 preceding siblings ...)
  2021-10-20 19:00 ` [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR Pavel Begunkov
@ 2021-10-21 14:27 ` Jens Axboe
  3 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2021-10-21 14:27 UTC (permalink / raw)
  To: linux-block, Pavel Begunkov

On Wed, 20 Oct 2021 20:00:47 +0100, Pavel Begunkov wrote:
> 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
> 
> [...]

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: 6549a874fb65e7ad4885d066ec314191cc137b52

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-10-21 14:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 19:00 [PATCH 0/3] random simple block cleanups Pavel Begunkov
2021-10-20 19:00 ` [PATCH 1/3] block: optimise boundary blkdev_read_iter's checks Pavel Begunkov
2021-10-20 19:00 ` [PATCH 2/3] block: clean up blk_mq_submit_bio() merging Pavel Begunkov
2021-10-20 19:04   ` Pavel Begunkov
2021-10-21  8:30   ` Christoph Hellwig
2021-10-21 13:32     ` Pavel Begunkov
2021-10-20 19:00 ` [PATCH 3/3] block: convert fops.c magic constants to SHIFT_SECTOR Pavel Begunkov
2021-10-21  8:31   ` Christoph Hellwig
2021-10-21 14:27 ` [PATCH 0/3] random simple block cleanups Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.