From: "Yu Kuai" <yukuai@fnnas.com>
To: <song@kernel.org>
Cc: <linux-raid@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linan122@huawei.com>, <xni@redhat.com>,
"Yu Kuai" <yukuai@fnnas.com>
Subject: Re: [PATCH] md: support to align bio to limits
Date: Fri, 21 Nov 2025 13:19:40 +0800 [thread overview]
Message-ID: <8140d7a2-e152-4f6b-a16d-5fd1dcc2fe20@fnnas.com> (raw)
In-Reply-To: <20251121051406.1316884-3-yukuai@fnnas.com>
Hi,
I forgot to remove this patch, that is patch 3 in this set, before sending
to mail list, please ignore this one.
在 2025/11/21 13:14, Yu Kuai 写道:
> For personalities that report optimal IO size, it's indicate that users
> can get the best IO bandwidth if they issue IO with this size. However
> there is also an implicit condition that IO should also be aligned to the
> optimal IO size.
>
> Currently, bio will only be split by limits, if bio offset is not aligned
> to limits, then all split bio will not be aligned. This patch add a new
> feature to align bio to limits first, and following patches will support
> this for each personality if necessary.
>
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
> drivers/md/md.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> drivers/md/md.h | 1 +
> 2 files changed, 47 insertions(+)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 7b5c5967568f..b09f87b27807 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -427,6 +427,48 @@ bool md_handle_request(struct mddev *mddev, struct bio *bio)
> }
> EXPORT_SYMBOL(md_handle_request);
>
> +static struct bio *__md_bio_align_to_limits(struct mddev *mddev,
> + struct bio *bio)
> +{
> + unsigned int max_sectors = mddev->gendisk->queue->limits.max_sectors;
> + sector_t start = bio->bi_iter.bi_sector;
> + sector_t align_start = roundup(start, max_sectors);
> + sector_t end;
> + sector_t align_end;
> +
> + /* already aligned */
> + if (align_start == start)
> + return bio;
> +
> + end = start + bio_sectors(bio);
> + align_end = rounddown(end, max_sectors);
> +
> + /* bio is too small to split */
> + if (align_end <= align_start)
> + return bio;
> +
> + return bio_submit_split_bioset(bio, align_start - start,
> + &mddev->gendisk->bio_split);
> +}
> +
> +static struct bio *md_bio_align_to_limits(struct mddev *mddev, struct bio *bio)
> +{
> + if (!mddev->bio_align_to_limits)
> + return bio;
> +
> + /* atomic write can't split */
> + if (bio->bi_opf & REQ_ATOMIC)
> + return bio;
> +
> + switch (bio_op(bio)) {
> + case REQ_OP_READ:
> + case REQ_OP_WRITE:
> + return __md_bio_align_to_limits(mddev, bio);
> + default:
> + return bio;
> + }
> +}
> +
> static void md_submit_bio(struct bio *bio)
> {
> const int rw = bio_data_dir(bio);
> @@ -442,6 +484,10 @@ static void md_submit_bio(struct bio *bio)
> return;
> }
>
> + bio = md_bio_align_to_limits(mddev, bio);
> + if (!bio)
> + return;
> +
> bio = bio_split_to_limits(bio);
> if (!bio)
> return;
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index 75fd8c873b6f..1ed90fd85ac4 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -630,6 +630,7 @@ struct mddev {
> bool has_superblocks:1;
> bool fail_last_dev:1;
> bool serialize_policy:1;
> + bool bio_align_to_limits:1;
> };
>
> enum recovery_flags {
--
Thanks,
Kuai
next prev parent reply other threads:[~2025-11-21 5:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
2025-11-21 5:13 ` [PATCH 1/7] md/raid5: use mempool to allocate stripe_request_ctx Yu Kuai
2025-11-21 5:14 ` [PATCH] md: support to align bio to limits Yu Kuai
2025-11-21 5:19 ` Yu Kuai [this message]
2025-11-25 1:37 ` kernel test robot
2025-11-25 8:23 ` kernel test robot
2025-11-21 5:14 ` [PATCH 2/7] md/raid5: make sure max_sectors is not less than io_opt Yu Kuai
2025-11-21 5:14 ` [PATCH 3/7] md: support to align bio to limits Yu Kuai
2025-11-22 21:20 ` kernel test robot
2025-11-21 5:14 ` [PATCH 4/7] md: add a helper md_config_align_limits() Yu Kuai
2025-11-21 5:14 ` [PATCH 5/7] md/raid5: align bio to io_opt Yu Kuai
2025-11-21 5:14 ` [PATCH 6/7] md/raid10: " Yu Kuai
2025-11-21 5:14 ` [PATCH 7/7] md/raid0: " Yu Kuai
2025-11-21 8:59 ` Paul Menzel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8140d7a2-e152-4f6b-a16d-5fd1dcc2fe20@fnnas.com \
--to=yukuai@fnnas.com \
--cc=linan122@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=xni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox