Re: [PATCH v4 06/11] md: support to align bio to limits
Li Nan <[email protected]>
| Newsgroups | gmane.linux.raid |
|---|---|
| Message-ID | <[email protected]> |
在 2026/1/12 19:24, Li Nan 写道: > > > 在 2026/1/12 12:28, Yu Kuai 写道: >> For personalities that report optimal IO size, it indicates 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. >> >> Link: >> https://lore.kernel.org/linux-raid/[email protected] >> Signed-off-by: Yu Kuai <[email protected]> >> Reviewed-by: Li Nan <[email protected]> >> --- >> drivers/md/md.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ >> drivers/md/md.h | 2 ++ >> 2 files changed, 56 insertions(+) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index 21b0bc3088d2..731ec800f5cb 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -428,6 +428,56 @@ 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 end = start + bio_sectors(bio); >> + sector_t align_start; >> + sector_t align_end; >> + u32 rem; >> + >> + /* calculate align_start = roundup(start, max_sectors) */ > > Can we use roundup_u64() here? > >> + align_start = start; >> + rem = sector_div(align_start, max_sectors); >> + /* already aligned */ >> + if (!rem) >> + return bio; >> + >> + align_start = start + max_sectors - rem; >> + >> + /* calculate align_end = rounddown(end, max_sectors) */ > > Use div64_u64_rem() here seems better. div64_u64_rem is same as sector_div. Please ignore it. > >> + align_end = end; >> + rem = sector_div(align_end, max_sectors); >> + align_end = end - rem; >> + >> + /* 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); >> +} >> + -- Thanks, Nan