Skip to content

Commit 39cf0ed

Browse files
Mikulas Patockakergon
authored andcommitted
dm raid1: use per_bio_data
Replace read_record_pool with per_bio_data in dm-raid1. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent c0820cf commit 39cf0ed

File tree

1 file changed

+5
-34
lines changed

1 file changed

+5
-34
lines changed

drivers/md/dm-raid1.c

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ struct mirror_set {
6161
struct dm_region_hash *rh;
6262
struct dm_kcopyd_client *kcopyd_client;
6363
struct dm_io_client *io_client;
64-
mempool_t *read_record_pool;
6564

6665
/* recovery */
6766
region_t nr_regions;
@@ -139,14 +138,11 @@ static void dispatch_bios(void *context, struct bio_list *bio_list)
139138
queue_bio(ms, bio, WRITE);
140139
}
141140

142-
#define MIN_READ_RECORDS 20
143141
struct dm_raid1_read_record {
144142
struct mirror *m;
145143
struct dm_bio_details details;
146144
};
147145

148-
static struct kmem_cache *_dm_raid1_read_record_cache;
149-
150146
/*
151147
* Every mirror should look like this one.
152148
*/
@@ -876,19 +872,9 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
876872
atomic_set(&ms->suspend, 0);
877873
atomic_set(&ms->default_mirror, DEFAULT_MIRROR);
878874

879-
ms->read_record_pool = mempool_create_slab_pool(MIN_READ_RECORDS,
880-
_dm_raid1_read_record_cache);
881-
882-
if (!ms->read_record_pool) {
883-
ti->error = "Error creating mirror read_record_pool";
884-
kfree(ms);
885-
return NULL;
886-
}
887-
888875
ms->io_client = dm_io_client_create();
889876
if (IS_ERR(ms->io_client)) {
890877
ti->error = "Error creating dm_io client";
891-
mempool_destroy(ms->read_record_pool);
892878
kfree(ms);
893879
return NULL;
894880
}
@@ -900,7 +886,6 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
900886
if (IS_ERR(ms->rh)) {
901887
ti->error = "Error creating dirty region hash";
902888
dm_io_client_destroy(ms->io_client);
903-
mempool_destroy(ms->read_record_pool);
904889
kfree(ms);
905890
return NULL;
906891
}
@@ -916,7 +901,6 @@ static void free_context(struct mirror_set *ms, struct dm_target *ti,
916901

917902
dm_io_client_destroy(ms->io_client);
918903
dm_region_hash_destroy(ms->rh);
919-
mempool_destroy(ms->read_record_pool);
920904
kfree(ms);
921905
}
922906

@@ -1088,6 +1072,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
10881072

10891073
ti->num_flush_requests = 1;
10901074
ti->num_discard_requests = 1;
1075+
ti->per_bio_data_size = sizeof(struct dm_raid1_read_record);
10911076
ti->discard_zeroes_data_unsupported = true;
10921077

10931078
ms->kmirrord_wq = alloc_workqueue("kmirrord",
@@ -1161,7 +1146,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
11611146
int r, rw = bio_rw(bio);
11621147
struct mirror *m;
11631148
struct mirror_set *ms = ti->private;
1164-
struct dm_raid1_read_record *read_record = NULL;
1149+
struct dm_raid1_read_record *read_record;
11651150
struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
11661151

11671152
if (rw == WRITE) {
@@ -1194,7 +1179,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
11941179
if (unlikely(!m))
11951180
return -EIO;
11961181

1197-
read_record = mempool_alloc(ms->read_record_pool, GFP_NOIO);
1182+
read_record = dm_per_bio_data(bio, sizeof(struct dm_raid1_read_record));
11981183
dm_bio_record(&read_record->details, bio);
11991184
map_context->ptr = read_record;
12001185
read_record->m = m;
@@ -1254,7 +1239,6 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
12541239
bd = &read_record->details;
12551240

12561241
dm_bio_restore(bd, bio);
1257-
mempool_free(read_record, ms->read_record_pool);
12581242
map_context->ptr = NULL;
12591243
queue_bio(ms, bio, rw);
12601244
return DM_ENDIO_INCOMPLETE;
@@ -1263,10 +1247,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
12631247
}
12641248

12651249
out:
1266-
if (read_record) {
1267-
mempool_free(read_record, ms->read_record_pool);
1268-
map_context->ptr = NULL;
1269-
}
1250+
map_context->ptr = NULL;
12701251

12711252
return error;
12721253
}
@@ -1420,7 +1401,7 @@ static int mirror_iterate_devices(struct dm_target *ti,
14201401

14211402
static struct target_type mirror_target = {
14221403
.name = "mirror",
1423-
.version = {1, 12, 1},
1404+
.version = {1, 13, 1},
14241405
.module = THIS_MODULE,
14251406
.ctr = mirror_ctr,
14261407
.dtr = mirror_dtr,
@@ -1437,13 +1418,6 @@ static int __init dm_mirror_init(void)
14371418
{
14381419
int r;
14391420

1440-
_dm_raid1_read_record_cache = KMEM_CACHE(dm_raid1_read_record, 0);
1441-
if (!_dm_raid1_read_record_cache) {
1442-
DMERR("Can't allocate dm_raid1_read_record cache");
1443-
r = -ENOMEM;
1444-
goto bad_cache;
1445-
}
1446-
14471421
r = dm_register_target(&mirror_target);
14481422
if (r < 0) {
14491423
DMERR("Failed to register mirror target");
@@ -1453,15 +1427,12 @@ static int __init dm_mirror_init(void)
14531427
return 0;
14541428

14551429
bad_target:
1456-
kmem_cache_destroy(_dm_raid1_read_record_cache);
1457-
bad_cache:
14581430
return r;
14591431
}
14601432

14611433
static void __exit dm_mirror_exit(void)
14621434
{
14631435
dm_unregister_target(&mirror_target);
1464-
kmem_cache_destroy(_dm_raid1_read_record_cache);
14651436
}
14661437

14671438
/* Module hooks */

0 commit comments

Comments
 (0)