Skip to content

Commit 178d139

Browse files
wangjinchaoYuKuai-huawei
authored andcommitted
md/raid1: remove struct pool_info and related code
The struct pool_info was originally introduced mainly to support reshape operations, serving as a parameter for mempool_init() when raid_disks changes. Now that mempool_create_kmalloc_pool() is sufficient for this purpose, struct pool_info and its related code are no longer needed. Remove struct pool_info and all associated code. Signed-off-by: Wang Jinchao <[email protected]> Link: https://lore.kernel.org/linux-raid/[email protected] Signed-off-by: Yu Kuai <[email protected]>
1 parent 987ca60 commit 178d139

File tree

2 files changed

+14
-55
lines changed

2 files changed

+14
-55
lines changed

drivers/md/raid1.c

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ static inline struct r1bio *get_resync_r1bio(struct bio *bio)
127127
return get_resync_pages(bio)->raid_bio;
128128
}
129129

130-
static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
130+
static void *r1bio_pool_alloc(gfp_t gfp_flags, struct r1conf *conf)
131131
{
132-
struct pool_info *pi = data;
133-
int size = offsetof(struct r1bio, bios[pi->raid_disks]);
132+
int size = offsetof(struct r1bio, bios[conf->raid_disks * 2]);
134133

135134
/* allocate a r1bio with room for raid_disks entries in the bios array */
136135
return kzalloc(size, gfp_flags);
@@ -145,26 +144,26 @@ static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
145144

146145
static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
147146
{
148-
struct pool_info *pi = data;
147+
struct r1conf *conf = data;
149148
struct r1bio *r1_bio;
150149
struct bio *bio;
151150
int need_pages;
152151
int j;
153152
struct resync_pages *rps;
154153

155-
r1_bio = r1bio_pool_alloc(gfp_flags, pi);
154+
r1_bio = r1bio_pool_alloc(gfp_flags, conf);
156155
if (!r1_bio)
157156
return NULL;
158157

159-
rps = kmalloc_array(pi->raid_disks, sizeof(struct resync_pages),
158+
rps = kmalloc_array(conf->raid_disks * 2, sizeof(struct resync_pages),
160159
gfp_flags);
161160
if (!rps)
162161
goto out_free_r1bio;
163162

164163
/*
165164
* Allocate bios : 1 for reading, n-1 for writing
166165
*/
167-
for (j = pi->raid_disks ; j-- ; ) {
166+
for (j = conf->raid_disks * 2; j-- ; ) {
168167
bio = bio_kmalloc(RESYNC_PAGES, gfp_flags);
169168
if (!bio)
170169
goto out_free_bio;
@@ -177,11 +176,11 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
177176
* If this is a user-requested check/repair, allocate
178177
* RESYNC_PAGES for each bio.
179178
*/
180-
if (test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery))
181-
need_pages = pi->raid_disks;
179+
if (test_bit(MD_RECOVERY_REQUESTED, &conf->mddev->recovery))
180+
need_pages = conf->raid_disks * 2;
182181
else
183182
need_pages = 1;
184-
for (j = 0; j < pi->raid_disks; j++) {
183+
for (j = 0; j < conf->raid_disks * 2; j++) {
185184
struct resync_pages *rp = &rps[j];
186185

187186
bio = r1_bio->bios[j];
@@ -207,7 +206,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
207206
resync_free_pages(&rps[j]);
208207

209208
out_free_bio:
210-
while (++j < pi->raid_disks) {
209+
while (++j < conf->raid_disks * 2) {
211210
bio_uninit(r1_bio->bios[j]);
212211
kfree(r1_bio->bios[j]);
213212
}
@@ -220,12 +219,12 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
220219

221220
static void r1buf_pool_free(void *__r1_bio, void *data)
222221
{
223-
struct pool_info *pi = data;
222+
struct r1conf *conf = data;
224223
int i;
225224
struct r1bio *r1bio = __r1_bio;
226225
struct resync_pages *rp = NULL;
227226

228-
for (i = pi->raid_disks; i--; ) {
227+
for (i = conf->raid_disks * 2; i--; ) {
229228
rp = get_resync_pages(r1bio->bios[i]);
230229
resync_free_pages(rp);
231230
bio_uninit(r1bio->bios[i]);
@@ -2746,7 +2745,7 @@ static int init_resync(struct r1conf *conf)
27462745
BUG_ON(mempool_initialized(&conf->r1buf_pool));
27472746

27482747
return mempool_init(&conf->r1buf_pool, buffs, r1buf_pool_alloc,
2749-
r1buf_pool_free, conf->poolinfo);
2748+
r1buf_pool_free, conf);
27502749
}
27512750

27522751
static struct r1bio *raid1_alloc_init_r1buf(struct r1conf *conf)
@@ -2756,7 +2755,7 @@ static struct r1bio *raid1_alloc_init_r1buf(struct r1conf *conf)
27562755
struct bio *bio;
27572756
int i;
27582757

2759-
for (i = conf->poolinfo->raid_disks; i--; ) {
2758+
for (i = conf->raid_disks * 2; i--; ) {
27602759
bio = r1bio->bios[i];
27612760
rps = bio->bi_private;
27622761
bio_reset(bio, NULL, 0);
@@ -3121,11 +3120,6 @@ static struct r1conf *setup_conf(struct mddev *mddev)
31213120
if (!conf->tmppage)
31223121
goto abort;
31233122

3124-
conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL);
3125-
if (!conf->poolinfo)
3126-
goto abort;
3127-
conf->poolinfo->raid_disks = mddev->raid_disks * 2;
3128-
31293123
r1bio_size = offsetof(struct r1bio, bios[mddev->raid_disks * 2]);
31303124
conf->r1bio_pool = mempool_create_kmalloc_pool(NR_RAID_BIOS, r1bio_size);
31313125
if (!conf->r1bio_pool)
@@ -3135,8 +3129,6 @@ static struct r1conf *setup_conf(struct mddev *mddev)
31353129
if (err)
31363130
goto abort;
31373131

3138-
conf->poolinfo->mddev = mddev;
3139-
31403132
err = -EINVAL;
31413133
spin_lock_init(&conf->device_lock);
31423134
conf->raid_disks = mddev->raid_disks;
@@ -3202,7 +3194,6 @@ static struct r1conf *setup_conf(struct mddev *mddev)
32023194
mempool_destroy(conf->r1bio_pool);
32033195
kfree(conf->mirrors);
32043196
safe_put_page(conf->tmppage);
3205-
kfree(conf->poolinfo);
32063197
kfree(conf->nr_pending);
32073198
kfree(conf->nr_waiting);
32083199
kfree(conf->nr_queued);
@@ -3315,7 +3306,6 @@ static void raid1_free(struct mddev *mddev, void *priv)
33153306
mempool_destroy(conf->r1bio_pool);
33163307
kfree(conf->mirrors);
33173308
safe_put_page(conf->tmppage);
3318-
kfree(conf->poolinfo);
33193309
kfree(conf->nr_pending);
33203310
kfree(conf->nr_waiting);
33213311
kfree(conf->nr_queued);
@@ -3369,7 +3359,6 @@ static int raid1_reshape(struct mddev *mddev)
33693359
* devices have the higher raid_disk numbers.
33703360
*/
33713361
mempool_t *newpool, *oldpool;
3372-
struct pool_info *newpoolinfo;
33733362
size_t new_r1bio_size;
33743363
struct raid1_info *newmirrors;
33753364
struct r1conf *conf = mddev->private;
@@ -3401,23 +3390,15 @@ static int raid1_reshape(struct mddev *mddev)
34013390
return -EBUSY;
34023391
}
34033392

3404-
newpoolinfo = kmalloc(sizeof(*newpoolinfo), GFP_KERNEL);
3405-
if (!newpoolinfo)
3406-
return -ENOMEM;
3407-
newpoolinfo->mddev = mddev;
3408-
newpoolinfo->raid_disks = raid_disks * 2;
3409-
34103393
new_r1bio_size = offsetof(struct r1bio, bios[raid_disks * 2]);
34113394
newpool = mempool_create_kmalloc_pool(NR_RAID_BIOS, new_r1bio_size);
34123395
if (!newpool) {
3413-
kfree(newpoolinfo);
34143396
return -ENOMEM;
34153397
}
34163398
newmirrors = kzalloc(array3_size(sizeof(struct raid1_info),
34173399
raid_disks, 2),
34183400
GFP_KERNEL);
34193401
if (!newmirrors) {
3420-
kfree(newpoolinfo);
34213402
mempool_destroy(newpool);
34223403
return -ENOMEM;
34233404
}
@@ -3443,8 +3424,6 @@ static int raid1_reshape(struct mddev *mddev)
34433424
}
34443425
kfree(conf->mirrors);
34453426
conf->mirrors = newmirrors;
3446-
kfree(conf->poolinfo);
3447-
conf->poolinfo = newpoolinfo;
34483427

34493428
spin_lock_irqsave(&conf->device_lock, flags);
34503429
mddev->degraded += (raid_disks - conf->raid_disks);

drivers/md/raid1.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,6 @@ struct raid1_info {
4949
sector_t seq_start;
5050
};
5151

52-
/*
53-
* memory pools need a pointer to the mddev, so they can force an unplug
54-
* when memory is tight, and a count of the number of drives that the
55-
* pool was allocated for, so they know how much to allocate and free.
56-
* mddev->raid_disks cannot be used, as it can change while a pool is active
57-
* These two datums are stored in a kmalloced struct.
58-
* The 'raid_disks' here is twice the raid_disks in r1conf.
59-
* This allows space for each 'real' device can have a replacement in the
60-
* second half of the array.
61-
*/
62-
63-
struct pool_info {
64-
struct mddev *mddev;
65-
int raid_disks;
66-
};
67-
6852
struct r1conf {
6953
struct mddev *mddev;
7054
struct raid1_info *mirrors; /* twice 'raid_disks' to
@@ -114,10 +98,6 @@ struct r1conf {
11498
*/
11599
int recovery_disabled;
116100

117-
/* poolinfo contains information about the content of the
118-
* mempools - it changes when the array grows or shrinks
119-
*/
120-
struct pool_info *poolinfo;
121101
mempool_t *r1bio_pool;
122102
mempool_t r1buf_pool;
123103

0 commit comments

Comments
 (0)