* [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt
@ 2025-11-21 5:13 Yu Kuai
2025-11-21 5:13 ` [PATCH 1/7] md/raid5: use mempool to allocate stripe_request_ctx Yu Kuai
` (7 more replies)
0 siblings, 8 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:13 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
Yu Kuai (7):
md/raid5: use mempool to allocate stripe_request_ctx
md/raid5: make sure max_sectors is not less than io_opt
md: support to align bio to limits
md: add a helper md_config_align_limits()
md/raid5: align bio to io_opt
md/raid10: align bio to io_opt
md/raid0: align bio to io_opt
drivers/md/md.c | 46 ++++++++++++++++++++++++
drivers/md/md.h | 16 +++++++++
drivers/md/raid0.c | 2 ++
drivers/md/raid1-10.c | 5 ---
drivers/md/raid10.c | 2 ++
drivers/md/raid5.c | 82 +++++++++++++++++++++++++++++--------------
drivers/md/raid5.h | 2 ++
7 files changed, 124 insertions(+), 31 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/7] md/raid5: use mempool to allocate stripe_request_ctx
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
@ 2025-11-21 5:13 ` Yu Kuai
2025-11-21 5:14 ` [PATCH] md: support to align bio to limits Yu Kuai
` (6 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:13 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
On the one hand, stripe_request_ctx is 72 bytes, and it's a bit huge for
a stack variable.
On the other hand, the bitmap sectors_to_do is a fixed size, result in
max_hw_sector_kb of raid5 array is at most 256 * 4k = 1Mb, and this will
make full stripe IO impossible for the array that chunk_size * data_disks
is bigger. Allocate ctx during runtime will make it possible to get rid
of this limit.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/md.h | 4 +++
drivers/md/raid1-10.c | 5 ----
drivers/md/raid5.c | 58 +++++++++++++++++++++++++++----------------
drivers/md/raid5.h | 2 ++
4 files changed, 42 insertions(+), 27 deletions(-)
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 6985f2829bbd..75fd8c873b6f 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -22,6 +22,10 @@
#include <trace/events/block.h>
#define MaxSector (~(sector_t)0)
+/*
+ * Number of guaranteed raid bios in case of extreme VM load:
+ */
+#define NR_RAID_BIOS 256
enum md_submodule_type {
MD_PERSONALITY = 0,
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 521625756128..c33099925f23 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -3,11 +3,6 @@
#define RESYNC_BLOCK_SIZE (64*1024)
#define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
-/*
- * Number of guaranteed raid bios in case of extreme VM load:
- */
-#define NR_RAID_BIOS 256
-
/* when we get a read error on a read-only array, we redirect to another
* device without failing the first device, or trying to over-write to
* correct the read error. To keep track of bad blocks on a per-bio
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index cdbc7eba5c54..0ccb5907cd20 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6079,13 +6079,13 @@ static sector_t raid5_bio_lowest_chunk_sector(struct r5conf *conf,
static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
- bool on_wq;
struct r5conf *conf = mddev->private;
- sector_t logical_sector;
- struct stripe_request_ctx ctx = {};
const int rw = bio_data_dir(bi);
+ struct stripe_request_ctx *ctx;
+ sector_t logical_sector;
enum stripe_result res;
int s, stripe_cnt;
+ bool on_wq;
if (unlikely(bi->bi_opf & REQ_PREFLUSH)) {
int ret = log_handle_flush_request(conf, bi);
@@ -6097,11 +6097,6 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
return true;
}
/* ret == -EAGAIN, fallback */
- /*
- * if r5l_handle_flush_request() didn't clear REQ_PREFLUSH,
- * we need to flush journal device
- */
- ctx.do_flush = bi->bi_opf & REQ_PREFLUSH;
}
md_write_start(mddev, bi);
@@ -6124,16 +6119,24 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
}
logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1);
- ctx.first_sector = logical_sector;
- ctx.last_sector = bio_end_sector(bi);
bi->bi_next = NULL;
- stripe_cnt = DIV_ROUND_UP_SECTOR_T(ctx.last_sector - logical_sector,
+ ctx = mempool_alloc(conf->ctx_pool, GFP_NOIO | __GFP_ZERO);
+ ctx->first_sector = logical_sector;
+ ctx->last_sector = bio_end_sector(bi);
+ /*
+ * if r5l_handle_flush_request() didn't clear REQ_PREFLUSH,
+ * we need to flush journal device
+ */
+ if (unlikely(bi->bi_opf & REQ_PREFLUSH))
+ ctx->do_flush = true;
+
+ stripe_cnt = DIV_ROUND_UP_SECTOR_T(ctx->last_sector - logical_sector,
RAID5_STRIPE_SECTORS(conf));
- bitmap_set(ctx.sectors_to_do, 0, stripe_cnt);
+ bitmap_set(ctx->sectors_to_do, 0, stripe_cnt);
pr_debug("raid456: %s, logical %llu to %llu\n", __func__,
- bi->bi_iter.bi_sector, ctx.last_sector);
+ bi->bi_iter.bi_sector, ctx->last_sector);
/* Bail out if conflicts with reshape and REQ_NOWAIT is set */
if ((bi->bi_opf & REQ_NOWAIT) &&
@@ -6141,6 +6144,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
bio_wouldblock_error(bi);
if (rw == WRITE)
md_write_end(mddev);
+ mempool_free(ctx, conf->ctx_pool);
return true;
}
md_account_bio(mddev, &bi);
@@ -6159,10 +6163,10 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
add_wait_queue(&conf->wait_for_reshape, &wait);
on_wq = true;
}
- s = (logical_sector - ctx.first_sector) >> RAID5_STRIPE_SHIFT(conf);
+ s = (logical_sector - ctx->first_sector) >> RAID5_STRIPE_SHIFT(conf);
while (1) {
- res = make_stripe_request(mddev, conf, &ctx, logical_sector,
+ res = make_stripe_request(mddev, conf, ctx, logical_sector,
bi);
if (res == STRIPE_FAIL || res == STRIPE_WAIT_RESHAPE)
break;
@@ -6179,9 +6183,9 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
* raid5_activate_delayed() from making progress
* and thus deadlocking.
*/
- if (ctx.batch_last) {
- raid5_release_stripe(ctx.batch_last);
- ctx.batch_last = NULL;
+ if (ctx->batch_last) {
+ raid5_release_stripe(ctx->batch_last);
+ ctx->batch_last = NULL;
}
wait_woken(&wait, TASK_UNINTERRUPTIBLE,
@@ -6189,21 +6193,23 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
continue;
}
- s = find_next_bit_wrap(ctx.sectors_to_do, stripe_cnt, s);
+ s = find_next_bit_wrap(ctx->sectors_to_do, stripe_cnt, s);
if (s == stripe_cnt)
break;
- logical_sector = ctx.first_sector +
+ logical_sector = ctx->first_sector +
(s << RAID5_STRIPE_SHIFT(conf));
}
if (unlikely(on_wq))
remove_wait_queue(&conf->wait_for_reshape, &wait);
- if (ctx.batch_last)
- raid5_release_stripe(ctx.batch_last);
+ if (ctx->batch_last)
+ raid5_release_stripe(ctx->batch_last);
if (rw == WRITE)
md_write_end(mddev);
+
+ mempool_free(ctx, conf->ctx_pool);
if (res == STRIPE_WAIT_RESHAPE) {
md_free_cloned_bio(bi);
return false;
@@ -7370,6 +7376,7 @@ static void free_conf(struct r5conf *conf)
bioset_exit(&conf->bio_split);
kfree(conf->stripe_hashtbl);
kfree(conf->pending_data);
+ mempool_destroy(conf->ctx_pool);
kfree(conf);
}
@@ -8053,6 +8060,13 @@ static int raid5_run(struct mddev *mddev)
goto abort;
}
+ conf->ctx_pool = mempool_create_kmalloc_pool(NR_RAID_BIOS,
+ sizeof(struct stripe_request_ctx));
+ if (!conf->ctx_pool) {
+ ret = -ENOMEM;
+ goto abort;
+ }
+
if (log_init(conf, journal_dev, raid5_has_ppl(conf)))
goto abort;
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index eafc6e9ed6ee..6e3f07119fa4 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -690,6 +690,8 @@ struct r5conf {
struct list_head pending_list;
int pending_data_cnt;
struct r5pending_data *next_pending_data;
+
+ mempool_t *ctx_pool;
};
#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH] md: support to align bio to limits
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 ` Yu Kuai
2025-11-21 5:19 ` Yu Kuai
` (2 more replies)
2025-11-21 5:14 ` [PATCH 2/7] md/raid5: make sure max_sectors is not less than io_opt Yu Kuai
` (5 subsequent siblings)
7 siblings, 3 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
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 {
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/7] md/raid5: make sure max_sectors is not less than io_opt
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:14 ` Yu Kuai
2025-11-21 5:14 ` [PATCH 3/7] md: support to align bio to limits Yu Kuai
` (4 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
Otherwise, even if user issue IO by io_opt, such IO will be split
by max_sectors before they are submitted to raid5. For consequence,
full stripe IO is impossible.
BTW, dm-raid5 is not affected and still have such problem.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/raid5.c | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 0ccb5907cd20..dc7bdbdb04b7 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -773,14 +773,14 @@ struct stripe_request_ctx {
/* last sector in the request */
sector_t last_sector;
+ /* the request had REQ_PREFLUSH, cleared after the first stripe_head */
+ bool do_flush;
+
/*
* bitmap to track stripe sectors that have been added to stripes
* add one to account for unaligned requests
*/
- DECLARE_BITMAP(sectors_to_do, RAID5_MAX_REQ_STRIPES + 1);
-
- /* the request had REQ_PREFLUSH, cleared after the first stripe_head */
- bool do_flush;
+ unsigned long sectors_to_do[];
};
/*
@@ -7732,6 +7732,24 @@ static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded
return 0;
}
+static int raid5_create_ctx_pool(struct r5conf *conf)
+{
+ struct stripe_request_ctx *ctx;
+ int size;
+
+ if (mddev_is_dm(conf->mddev))
+ size = BITS_TO_LONGS(RAID5_MAX_REQ_STRIPES);
+ else
+ size = BITS_TO_LONGS(
+ queue_max_hw_sectors(conf->mddev->gendisk->queue) >>
+ RAID5_STRIPE_SHIFT(conf));
+
+ conf->ctx_pool = mempool_create_kmalloc_pool(NR_RAID_BIOS,
+ struct_size(ctx, sectors_to_do, size));
+
+ return conf->ctx_pool ? 0 : -ENOMEM;
+}
+
static int raid5_set_limits(struct mddev *mddev)
{
struct r5conf *conf = mddev->private;
@@ -7788,6 +7806,8 @@ static int raid5_set_limits(struct mddev *mddev)
* Limit the max sectors based on this.
*/
lim.max_hw_sectors = RAID5_MAX_REQ_STRIPES << RAID5_STRIPE_SHIFT(conf);
+ if ((lim.max_hw_sectors << 9) < lim.io_opt)
+ lim.max_hw_sectors = lim.io_opt >> 9;
/* No restrictions on the number of segments in the request */
lim.max_segments = USHRT_MAX;
@@ -8060,12 +8080,9 @@ static int raid5_run(struct mddev *mddev)
goto abort;
}
- conf->ctx_pool = mempool_create_kmalloc_pool(NR_RAID_BIOS,
- sizeof(struct stripe_request_ctx));
- if (!conf->ctx_pool) {
- ret = -ENOMEM;
+ ret = raid5_create_ctx_pool(conf);
+ if (ret)
goto abort;
- }
if (log_init(conf, journal_dev, raid5_has_ppl(conf)))
goto abort;
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/7] md: support to align bio to limits
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
` (2 preceding siblings ...)
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 ` 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
` (3 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
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 {
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/7] md: add a helper md_config_align_limits()
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
` (3 preceding siblings ...)
2025-11-21 5:14 ` [PATCH 3/7] md: support to align bio to limits Yu Kuai
@ 2025-11-21 5:14 ` Yu Kuai
2025-11-21 5:14 ` [PATCH 5/7] md/raid5: align bio to io_opt Yu Kuai
` (2 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
This helper will be used by personalities that want to align bio to
io_opt to get best IO bandwidth.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/md.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 1ed90fd85ac4..c8190cf02701 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -1088,6 +1088,17 @@ static inline bool rdev_blocked(struct md_rdev *rdev)
return false;
}
+static inline void md_config_align_limits(struct mddev *mddev,
+ struct queue_limits *lim)
+{
+ if ((lim->max_hw_sectors << 9) < lim->io_opt)
+ lim->max_hw_sectors = lim->io_opt >> 9;
+ else
+ lim->max_hw_sectors = rounddown(lim->max_hw_sectors,
+ lim->io_opt >> 9);
+ mddev->bio_align_to_limits = true;
+}
+
#define mddev_add_trace_msg(mddev, fmt, args...) \
do { \
if (!mddev_is_dm(mddev)) \
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/7] md/raid5: align bio to io_opt
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
` (4 preceding siblings ...)
2025-11-21 5:14 ` [PATCH 4/7] md: add a helper md_config_align_limits() Yu Kuai
@ 2025-11-21 5:14 ` 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
7 siblings, 0 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
raid5 internal implementaion indicates that if write bio is aligned to
io_opt, then full stripe write will be used, which will be best for
bandwidth because there is no need to read extra data to build new
xor data.
Simple test in my VM, 32 disks raid5 with 64kb chunksize:
dd if=/dev/zero of=/dev/md0 bs=100M oflag=direct
Before this patch: 782 MB/s
With this patch: 1.1 GB/s
BTW, there are still other bottleneck related to stripe handler, and
require further optimization.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/raid5.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index dc7bdbdb04b7..2db4e4fe913a 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7806,8 +7806,7 @@ static int raid5_set_limits(struct mddev *mddev)
* Limit the max sectors based on this.
*/
lim.max_hw_sectors = RAID5_MAX_REQ_STRIPES << RAID5_STRIPE_SHIFT(conf);
- if ((lim.max_hw_sectors << 9) < lim.io_opt)
- lim.max_hw_sectors = lim.io_opt >> 9;
+ md_config_align_limits(mddev, &lim);
/* No restrictions on the number of segments in the request */
lim.max_segments = USHRT_MAX;
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 6/7] md/raid10: align bio to io_opt
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
` (5 preceding siblings ...)
2025-11-21 5:14 ` [PATCH 5/7] md/raid5: align bio to io_opt Yu Kuai
@ 2025-11-21 5:14 ` Yu Kuai
2025-11-21 5:14 ` [PATCH 7/7] md/raid0: " Yu Kuai
7 siblings, 0 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
The impact is not so significant for raid10 compared to raid5, however
it's still more appropriate to issue IOs evenly to underlying disks.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/raid10.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 84be4cc7e873..f6a4bb26fb4a 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4008,6 +4008,8 @@ static int raid10_set_queue_limits(struct mddev *mddev)
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
if (err)
return err;
+
+ md_config_align_limits(mddev, &lim);
return queue_limits_set(mddev->gendisk->queue, &lim);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 7/7] md/raid0: align bio to io_opt
2025-11-21 5:13 [PATCH 0/7] md: raid5,raid0,raid10: align bio to io_opt Yu Kuai
` (6 preceding siblings ...)
2025-11-21 5:14 ` [PATCH 6/7] md/raid10: " Yu Kuai
@ 2025-11-21 5:14 ` Yu Kuai
2025-11-21 8:59 ` Paul Menzel
7 siblings, 1 reply; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:14 UTC (permalink / raw)
To: song, yukuai; +Cc: linux-raid, linux-kernel, linan122, xni
The impact is not so significant for raid0 compared to raid5, however
it's still more appropriate to issue IOs evenly to underlying disks.
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
drivers/md/raid0.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 47aee1b1d4d1..332f413bcf51 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -388,6 +388,8 @@ static int raid0_set_limits(struct mddev *mddev)
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
if (err)
return err;
+
+ md_config_align_limits(mddev, &lim);
return queue_limits_set(mddev->gendisk->queue, &lim);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH] md: support to align bio to limits
2025-11-21 5:14 ` [PATCH] md: support to align bio to limits Yu Kuai
@ 2025-11-21 5:19 ` Yu Kuai
2025-11-25 1:37 ` kernel test robot
2025-11-25 8:23 ` kernel test robot
2 siblings, 0 replies; 14+ messages in thread
From: Yu Kuai @ 2025-11-21 5:19 UTC (permalink / raw)
To: song; +Cc: linux-raid, linux-kernel, linan122, xni, Yu Kuai
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 7/7] md/raid0: align bio to io_opt
2025-11-21 5:14 ` [PATCH 7/7] md/raid0: " Yu Kuai
@ 2025-11-21 8:59 ` Paul Menzel
0 siblings, 0 replies; 14+ messages in thread
From: Paul Menzel @ 2025-11-21 8:59 UTC (permalink / raw)
To: Yu Kuai; +Cc: song, linux-raid, linux-kernel, linan122, xni
Dear Kuai,
Thank you for your patches.
Am 21.11.25 um 06:14 schrieb Yu Kuai:
> The impact is not so significant for raid0 compared to raid5, however
> it's still more appropriate to issue IOs evenly to underlying disks.
Could you please elaborate, what the problem is, and also share your
benchmark results and test setups?
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
> drivers/md/raid0.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index 47aee1b1d4d1..332f413bcf51 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -388,6 +388,8 @@ static int raid0_set_limits(struct mddev *mddev)
> err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
> if (err)
> return err;
> +
> + md_config_align_limits(mddev, &lim);
> return queue_limits_set(mddev->gendisk->queue, &lim);
> }
>
Kind regards,
Paul
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/7] md: support to align bio to limits
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
0 siblings, 0 replies; 14+ messages in thread
From: kernel test robot @ 2025-11-22 21:20 UTC (permalink / raw)
To: Yu Kuai, song; +Cc: oe-kbuild-all, linux-raid, linux-kernel, linan122, xni
Hi Yu,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.18-rc6 next-20251121]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/md-raid5-use-mempool-to-allocate-stripe_request_ctx/20251121-131818
base: linus/master
patch link: https://lore.kernel.org/r/20251121051406.1316884-5-yukuai%40fnnas.com
patch subject: [PATCH 3/7] md: support to align bio to limits
config: powerpc-randconfig-002-20251123 (https://download.01.org/0day-ci/archive/20251123/202511230429.aSwW3knO-lkp@intel.com/config)
compiler: powerpc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251123/202511230429.aSwW3knO-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511230429.aSwW3knO-lkp@intel.com/
All errors (new ones prefixed by >>):
powerpc-linux-ld: drivers/md/md.o: in function `md_submit_bio':
>> md.c:(.text+0xf8c4): undefined reference to `__udivdi3'
>> powerpc-linux-ld: md.c:(.text+0xf914): undefined reference to `__umoddi3'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] md: support to align bio to limits
2025-11-21 5:14 ` [PATCH] md: support to align bio to limits Yu Kuai
2025-11-21 5:19 ` Yu Kuai
@ 2025-11-25 1:37 ` kernel test robot
2025-11-25 8:23 ` kernel test robot
2 siblings, 0 replies; 14+ messages in thread
From: kernel test robot @ 2025-11-25 1:37 UTC (permalink / raw)
To: Yu Kuai, song; +Cc: oe-kbuild-all, linux-raid, linux-kernel, linan122, xni
Hi Yu,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.18-rc7 next-20251124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/md-support-to-align-bio-to-limits/20251121-131703
base: linus/master
patch link: https://lore.kernel.org/r/20251121051406.1316884-3-yukuai%40fnnas.com
patch subject: [PATCH] md: support to align bio to limits
config: i386-randconfig-002-20251125 (https://download.01.org/0day-ci/archive/20251125/202511250848.gq6d7JeR-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251125/202511250848.gq6d7JeR-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511250848.gq6d7JeR-lkp@intel.com/
All errors (new ones prefixed by >>):
ld: drivers/md/md.o: in function `__md_bio_align_to_limits':
>> drivers/md/md.c:434:(.text+0x68e4): undefined reference to `__umoddi3'
>> ld: drivers/md/md.c:443:(.text+0x693a): undefined reference to `__umoddi3'
vim +434 drivers/md/md.c
428
429 static struct bio *__md_bio_align_to_limits(struct mddev *mddev,
430 struct bio *bio)
431 {
432 unsigned int max_sectors = mddev->gendisk->queue->limits.max_sectors;
433 sector_t start = bio->bi_iter.bi_sector;
> 434 sector_t align_start = roundup(start, max_sectors);
435 sector_t end;
436 sector_t align_end;
437
438 /* already aligned */
439 if (align_start == start)
440 return bio;
441
442 end = start + bio_sectors(bio);
> 443 align_end = rounddown(end, max_sectors);
444
445 /* bio is too small to split */
446 if (align_end <= align_start)
447 return bio;
448
449 return bio_submit_split_bioset(bio, align_start - start,
450 &mddev->gendisk->bio_split);
451 }
452
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] md: support to align bio to limits
2025-11-21 5:14 ` [PATCH] md: support to align bio to limits Yu Kuai
2025-11-21 5:19 ` Yu Kuai
2025-11-25 1:37 ` kernel test robot
@ 2025-11-25 8:23 ` kernel test robot
2 siblings, 0 replies; 14+ messages in thread
From: kernel test robot @ 2025-11-25 8:23 UTC (permalink / raw)
To: Yu Kuai, song; +Cc: oe-kbuild-all, linux-raid, linux-kernel, linan122, xni
Hi Yu,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.18-rc7 next-20251124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/md-support-to-align-bio-to-limits/20251121-131703
base: linus/master
patch link: https://lore.kernel.org/r/20251121051406.1316884-3-yukuai%40fnnas.com
patch subject: [PATCH] md: support to align bio to limits
config: arm-randconfig-002-20251125 (https://download.01.org/0day-ci/archive/20251125/202511251523.ariD3O9E-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251125/202511251523.ariD3O9E-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511251523.ariD3O9E-lkp@intel.com/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "__aeabi_uldivmod" [drivers/md/md-mod.ko] undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2025-11-25 8:23 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox