diff mbox series

[1/2] md/raid0: Factor out helper for mapping and submitting a bio

Message ID 20230814092720.3931-1-jack@suse.cz (mailing list archive)
State Accepted, archived
Headers show
Series md/raid0: Fix performance regression for large sequential IO | expand

Commit Message

Jan Kara Aug. 14, 2023, 9:27 a.m. UTC
Factor out helper function for mapping and submitting a bio out of
raid0_make_request(). We will use it later for submitting both parts of
a split bio.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 drivers/md/raid0.c | 79 +++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 39 deletions(-)

Comments

Yu Kuai Aug. 15, 2023, 1:33 a.m. UTC | #1
在 2023/08/14 17:27, Jan Kara 写道:
> Factor out helper function for mapping and submitting a bio out of
> raid0_make_request(). We will use it later for submitting both parts of
> a split bio.
> 
LGTM

Reviewed-by: Yu Kuai <yukuai3@huawei.com>

> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>   drivers/md/raid0.c | 79 +++++++++++++++++++++++-----------------------
>   1 file changed, 40 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index d1ac73fcd852..d3c55f2e9b18 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -557,54 +557,21 @@ static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
>   	bio_endio(bio);
>   }
>   
> -static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
> +static void raid0_map_submit_bio(struct mddev *mddev, struct bio *bio)
>   {
>   	struct r0conf *conf = mddev->private;
>   	struct strip_zone *zone;
>   	struct md_rdev *tmp_dev;
> -	sector_t bio_sector;
> -	sector_t sector;
> -	sector_t orig_sector;
> -	unsigned chunk_sects;
> -	unsigned sectors;
> -
> -	if (unlikely(bio->bi_opf & REQ_PREFLUSH)
> -	    && md_flush_request(mddev, bio))
> -		return true;
> -
> -	if (unlikely((bio_op(bio) == REQ_OP_DISCARD))) {
> -		raid0_handle_discard(mddev, bio);
> -		return true;
> -	}
> -
> -	bio_sector = bio->bi_iter.bi_sector;
> -	sector = bio_sector;
> -	chunk_sects = mddev->chunk_sectors;
> -
> -	sectors = chunk_sects -
> -		(likely(is_power_of_2(chunk_sects))
> -		 ? (sector & (chunk_sects-1))
> -		 : sector_div(sector, chunk_sects));
> -
> -	/* Restore due to sector_div */
> -	sector = bio_sector;
> -
> -	if (sectors < bio_sectors(bio)) {
> -		struct bio *split = bio_split(bio, sectors, GFP_NOIO,
> -					      &mddev->bio_set);
> -		bio_chain(split, bio);
> -		submit_bio_noacct(bio);
> -		bio = split;
> -	}
> +	sector_t bio_sector = bio->bi_iter.bi_sector;
> +	sector_t sector = bio_sector;
>   
>   	if (bio->bi_pool != &mddev->bio_set)
>   		md_account_bio(mddev, &bio);
>   
> -	orig_sector = sector;
>   	zone = find_zone(mddev->private, &sector);
>   	switch (conf->layout) {
>   	case RAID0_ORIG_LAYOUT:
> -		tmp_dev = map_sector(mddev, zone, orig_sector, &sector);
> +		tmp_dev = map_sector(mddev, zone, bio_sector, &sector);
>   		break;
>   	case RAID0_ALT_MULTIZONE_LAYOUT:
>   		tmp_dev = map_sector(mddev, zone, sector, &sector);
> @@ -612,13 +579,13 @@ static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
>   	default:
>   		WARN(1, "md/raid0:%s: Invalid layout\n", mdname(mddev));
>   		bio_io_error(bio);
> -		return true;
> +		return;
>   	}
>   
>   	if (unlikely(is_rdev_broken(tmp_dev))) {
>   		bio_io_error(bio);
>   		md_error(mddev, tmp_dev);
> -		return true;
> +		return;
>   	}
>   
>   	bio_set_dev(bio, tmp_dev->bdev);
> @@ -630,6 +597,40 @@ static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
>   				      bio_sector);
>   	mddev_check_write_zeroes(mddev, bio);
>   	submit_bio_noacct(bio);
> +}
> +
> +static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
> +{
> +	sector_t sector;
> +	unsigned chunk_sects;
> +	unsigned sectors;
> +
> +	if (unlikely(bio->bi_opf & REQ_PREFLUSH)
> +	    && md_flush_request(mddev, bio))
> +		return true;
> +
> +	if (unlikely((bio_op(bio) == REQ_OP_DISCARD))) {
> +		raid0_handle_discard(mddev, bio);
> +		return true;
> +	}
> +
> +	sector = bio->bi_iter.bi_sector;
> +	chunk_sects = mddev->chunk_sectors;
> +
> +	sectors = chunk_sects -
> +		(likely(is_power_of_2(chunk_sects))
> +		 ? (sector & (chunk_sects-1))
> +		 : sector_div(sector, chunk_sects));
> +
> +	if (sectors < bio_sectors(bio)) {
> +		struct bio *split = bio_split(bio, sectors, GFP_NOIO,
> +					      &mddev->bio_set);
> +		bio_chain(split, bio);
> +		submit_bio_noacct(bio);
> +		bio = split;
> +	}
> +
> +	raid0_map_submit_bio(mddev, bio);
>   	return true;
>   }
>   
>
Song Liu Aug. 15, 2023, 7:38 a.m. UTC | #2
On Tue, Aug 15, 2023 at 9:33 AM Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
> 在 2023/08/14 17:27, Jan Kara 写道:
> > Factor out helper function for mapping and submitting a bio out of
> > raid0_make_request(). We will use it later for submitting both parts of
> > a split bio.
> >
> LGTM
>
> Reviewed-by: Yu Kuai <yukuai3@huawei.com>
>
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---

Applied the set to md-next. Thanks!

Song
diff mbox series

Patch

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index d1ac73fcd852..d3c55f2e9b18 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -557,54 +557,21 @@  static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
 	bio_endio(bio);
 }
 
-static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
+static void raid0_map_submit_bio(struct mddev *mddev, struct bio *bio)
 {
 	struct r0conf *conf = mddev->private;
 	struct strip_zone *zone;
 	struct md_rdev *tmp_dev;
-	sector_t bio_sector;
-	sector_t sector;
-	sector_t orig_sector;
-	unsigned chunk_sects;
-	unsigned sectors;
-
-	if (unlikely(bio->bi_opf & REQ_PREFLUSH)
-	    && md_flush_request(mddev, bio))
-		return true;
-
-	if (unlikely((bio_op(bio) == REQ_OP_DISCARD))) {
-		raid0_handle_discard(mddev, bio);
-		return true;
-	}
-
-	bio_sector = bio->bi_iter.bi_sector;
-	sector = bio_sector;
-	chunk_sects = mddev->chunk_sectors;
-
-	sectors = chunk_sects -
-		(likely(is_power_of_2(chunk_sects))
-		 ? (sector & (chunk_sects-1))
-		 : sector_div(sector, chunk_sects));
-
-	/* Restore due to sector_div */
-	sector = bio_sector;
-
-	if (sectors < bio_sectors(bio)) {
-		struct bio *split = bio_split(bio, sectors, GFP_NOIO,
-					      &mddev->bio_set);
-		bio_chain(split, bio);
-		submit_bio_noacct(bio);
-		bio = split;
-	}
+	sector_t bio_sector = bio->bi_iter.bi_sector;
+	sector_t sector = bio_sector;
 
 	if (bio->bi_pool != &mddev->bio_set)
 		md_account_bio(mddev, &bio);
 
-	orig_sector = sector;
 	zone = find_zone(mddev->private, &sector);
 	switch (conf->layout) {
 	case RAID0_ORIG_LAYOUT:
-		tmp_dev = map_sector(mddev, zone, orig_sector, &sector);
+		tmp_dev = map_sector(mddev, zone, bio_sector, &sector);
 		break;
 	case RAID0_ALT_MULTIZONE_LAYOUT:
 		tmp_dev = map_sector(mddev, zone, sector, &sector);
@@ -612,13 +579,13 @@  static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
 	default:
 		WARN(1, "md/raid0:%s: Invalid layout\n", mdname(mddev));
 		bio_io_error(bio);
-		return true;
+		return;
 	}
 
 	if (unlikely(is_rdev_broken(tmp_dev))) {
 		bio_io_error(bio);
 		md_error(mddev, tmp_dev);
-		return true;
+		return;
 	}
 
 	bio_set_dev(bio, tmp_dev->bdev);
@@ -630,6 +597,40 @@  static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
 				      bio_sector);
 	mddev_check_write_zeroes(mddev, bio);
 	submit_bio_noacct(bio);
+}
+
+static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
+{
+	sector_t sector;
+	unsigned chunk_sects;
+	unsigned sectors;
+
+	if (unlikely(bio->bi_opf & REQ_PREFLUSH)
+	    && md_flush_request(mddev, bio))
+		return true;
+
+	if (unlikely((bio_op(bio) == REQ_OP_DISCARD))) {
+		raid0_handle_discard(mddev, bio);
+		return true;
+	}
+
+	sector = bio->bi_iter.bi_sector;
+	chunk_sects = mddev->chunk_sectors;
+
+	sectors = chunk_sects -
+		(likely(is_power_of_2(chunk_sects))
+		 ? (sector & (chunk_sects-1))
+		 : sector_div(sector, chunk_sects));
+
+	if (sectors < bio_sectors(bio)) {
+		struct bio *split = bio_split(bio, sectors, GFP_NOIO,
+					      &mddev->bio_set);
+		bio_chain(split, bio);
+		submit_bio_noacct(bio);
+		bio = split;
+	}
+
+	raid0_map_submit_bio(mddev, bio);
 	return true;
 }