From: "Chen Cheng" <chencheng@fnnas.com>
To: <linux-raid@vger.kernel.org>, <yukuai@fnnas.com>
Cc: <chencheng@fnnas.com>, <chenchneg33@gmail.com>
Subject: [PATCH 2/4] md/raid10: prepare r10bio allocation width tracking
Date: Wed, 22 Apr 2026 10:33:15 +0800 [thread overview]
Message-ID: <20260422023317.796326-2-chencheng@fnnas.com> (raw)
In-Reply-To: <20260422023317.796326-1-chencheng@fnnas.com>
From: Chen Cheng <chencheng@fnnas.com>
Record how many devs[] slots each r10bio was allocated with.
Keep the active r10bio pool in a separate object that carries its width.
This keeps the allocation width separate from the per-request width stored
in used_nr_devs and prepares the pool for replacement during reshape.
---
drivers/md/raid10.c | 40 +++++++++++++++++++++++++++-------------
drivers/md/raid10.h | 8 +++++++-
2 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index e93933632893..b447903fbdc6 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -103,14 +103,22 @@ static inline struct r10bio *get_resync_r10bio(struct bio *bio)
return get_resync_pages(bio)->raid_bio;
}
-static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data)
+static void *r10bio_pool_alloc(gfp_t gfp_flags, void *data)
{
- struct r10conf *conf = data;
- int size = offsetof(struct r10bio, devs[conf->geo.raid_disks]);
+ struct r10bio_pool *pool = data;
+ int size = offsetof(struct r10bio, devs[pool->nr_devs]);
+ struct r10bio *r10_bio = kzalloc(size, gfp_flags);
+
+ if (r10_bio)
+ r10_bio->alloc_nr_devs = pool->nr_devs;
+ return r10_bio;
+}
- /* allocate a r10bio with room for raid_disks entries in the
- * bios array */
- return kzalloc(size, gfp_flags);
+static int init_r10bio_pool(struct r10bio_pool *pool, unsigned int nr_devs)
+{
+ pool->nr_devs = nr_devs;
+ return mempool_init(&pool->pool, NR_RAID_BIOS, r10bio_pool_alloc,
+ rbio_pool_free, pool);
}
#define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
@@ -137,7 +145,7 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
int nalloc, nalloc_rp;
struct resync_pages *rps;
- r10_bio = r10bio_pool_alloc(gfp_flags, conf);
+ r10_bio = r10bio_pool_alloc(gfp_flags, conf->r10bio_pool);
if (!r10_bio)
return NULL;
@@ -277,7 +285,7 @@ static void free_r10bio(struct r10bio *r10_bio)
struct r10conf *conf = r10_bio->mddev->private;
put_all_bios(conf, r10_bio);
- mempool_free(r10_bio, &conf->r10bio_pool);
+ mempool_free(r10_bio, &conf->r10bio_pool->pool);
}
static void put_buf(struct r10bio *r10_bio)
@@ -1531,7 +1539,7 @@ static void __make_request(struct mddev *mddev, struct bio *bio, int sectors)
struct r10conf *conf = mddev->private;
struct r10bio *r10_bio;
- r10_bio = mempool_alloc(&conf->r10bio_pool, GFP_NOIO);
+ r10_bio = mempool_alloc(&conf->r10bio_pool->pool, GFP_NOIO);
r10_bio->master_bio = bio;
r10_bio->sectors = sectors;
@@ -1724,7 +1732,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
(last_stripe_index << geo->chunk_shift);
retry_discard:
- r10_bio = mempool_alloc(&conf->r10bio_pool, GFP_NOIO);
+ r10_bio = mempool_alloc(&conf->r10bio_pool->pool, GFP_NOIO);
r10_bio->mddev = mddev;
r10_bio->state = 0;
r10_bio->sectors = 0;
@@ -3825,7 +3833,10 @@ static void raid10_free_conf(struct r10conf *conf)
if (!conf)
return;
- mempool_exit(&conf->r10bio_pool);
+ if (conf->r10bio_pool) {
+ mempool_exit(&conf->r10bio_pool->pool);
+ kfree(conf->r10bio_pool);
+ }
kfree(conf->mirrors);
kfree(conf->mirrors_old);
kfree(conf->mirrors_new);
@@ -3870,10 +3881,13 @@ static struct r10conf *setup_conf(struct mddev *mddev)
if (!conf->tmppage)
goto out;
+ conf->r10bio_pool = kzalloc_obj(struct r10bio_pool);
+ if (!conf->r10bio_pool)
+ goto out;
+
conf->geo = geo;
conf->copies = copies;
- err = mempool_init(&conf->r10bio_pool, NR_RAID_BIOS, r10bio_pool_alloc,
- rbio_pool_free, conf);
+ err = init_r10bio_pool(conf->r10bio_pool, conf->geo.raid_disks);
if (err)
goto out;
diff --git a/drivers/md/raid10.h b/drivers/md/raid10.h
index 92e8743023e6..8fa4e54c444c 100644
--- a/drivers/md/raid10.h
+++ b/drivers/md/raid10.h
@@ -20,6 +20,11 @@ struct raid10_info {
sector_t head_position;
};
+struct r10bio_pool {
+ mempool_t pool;
+ unsigned int nr_devs;
+};
+
struct r10conf {
struct mddev *mddev;
struct raid10_info *mirrors;
@@ -87,7 +92,7 @@ struct r10conf {
*/
wait_queue_head_t wait_barrier;
- mempool_t r10bio_pool;
+ struct r10bio_pool *r10bio_pool;
mempool_t r10buf_pool;
struct page *tmppage;
struct bio_set bio_split;
@@ -128,6 +133,7 @@ struct r10bio {
*/
int read_slot;
unsigned int used_nr_devs;
+ unsigned int alloc_nr_devs;
struct list_head retry_list;
/*
--
2.53.0
next prev parent reply other threads:[~2026-04-22 2:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 2:33 [PATCH 1/4] md/raid10: prepare per-r10bio dev slot tracking Chen Cheng
2026-04-22 2:33 ` Chen Cheng [this message]
2026-04-22 2:33 ` [PATCH 3/4] md/raid10: fix r10bio devs overflow across reshape Chen Cheng
2026-04-22 2:33 ` [PATCH 4/4] md/raid10: reset read_slot when reusing r10bio for discard Chen Cheng
2026-04-22 6:40 ` [PATCH 1/4] md/raid10: prepare per-r10bio dev slot tracking Paul Menzel
2026-04-24 2:11 ` Chen Cheng
2026-04-24 7:04 ` Yu Kuai
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=20260422023317.796326-2-chencheng@fnnas.com \
--to=chencheng@fnnas.com \
--cc=chenchneg33@gmail.com \
--cc=linux-raid@vger.kernel.org \
--cc=yukuai@fnnas.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