aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2012-09-06 18:34:55 -0400
committerJens Axboe <axboe@kernel.dk>2012-09-09 04:35:38 -0400
commit395c72a707d966b36d5a42fe12c3a237ded3a0d9 (patch)
tree79e4450a4f31409815d80ee8e1a7e1490a140f22 /drivers/md
parenteeea3ac912207dcf759b95b2b4c36f96bce583bf (diff)
block: Generalized bio pool freeing
With the old code, when you allocate a bio from a bio pool you have to implement your own destructor that knows how to find the bio pool the bio was originally allocated from. This adds a new field to struct bio (bi_pool) and changes bio_alloc_bioset() to use it. This makes various bio destructors unnecessary, so they're then deleted. v6: Explain the temporary if statement in bio_put Signed-off-by: Kent Overstreet <koverstreet@google.com> CC: Jens Axboe <axboe@kernel.dk> CC: NeilBrown <neilb@suse.de> CC: Alasdair Kergon <agk@redhat.com> CC: Nicholas Bellinger <nab@linux-iscsi.org> CC: Lars Ellenberg <lars.ellenberg@linbit.com> Acked-by: Tejun Heo <tj@kernel.org> Acked-by: Nicholas Bellinger <nab@linux-iscsi.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-crypt.c9
-rw-r--r--drivers/md/dm-io.c11
-rw-r--r--drivers/md/dm.c20
-rw-r--r--drivers/md/md.c28
4 files changed, 4 insertions, 64 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 664743d6a6cd..3c0acba042b6 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -798,14 +798,6 @@ static int crypt_convert(struct crypt_config *cc,
798 return 0; 798 return 0;
799} 799}
800 800
801static void dm_crypt_bio_destructor(struct bio *bio)
802{
803 struct dm_crypt_io *io = bio->bi_private;
804 struct crypt_config *cc = io->cc;
805
806 bio_free(bio, cc->bs);
807}
808
809/* 801/*
810 * Generate a new unfragmented bio with the given size 802 * Generate a new unfragmented bio with the given size
811 * This should never violate the device limitations 803 * This should never violate the device limitations
@@ -974,7 +966,6 @@ static void clone_init(struct dm_crypt_io *io, struct bio *clone)
974 clone->bi_end_io = crypt_endio; 966 clone->bi_end_io = crypt_endio;
975 clone->bi_bdev = cc->dev->bdev; 967 clone->bi_bdev = cc->dev->bdev;
976 clone->bi_rw = io->base_bio->bi_rw; 968 clone->bi_rw = io->base_bio->bi_rw;
977 clone->bi_destructor = dm_crypt_bio_destructor;
978} 969}
979 970
980static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp) 971static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index ea5dd289fe2a..1c46f97d6664 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -249,16 +249,6 @@ static void vm_dp_init(struct dpages *dp, void *data)
249 dp->context_ptr = data; 249 dp->context_ptr = data;
250} 250}
251 251
252static void dm_bio_destructor(struct bio *bio)
253{
254 unsigned region;
255 struct io *io;
256
257 retrieve_io_and_region_from_bio(bio, &io, &region);
258
259 bio_free(bio, io->client->bios);
260}
261
262/* 252/*
263 * Functions for getting the pages from kernel memory. 253 * Functions for getting the pages from kernel memory.
264 */ 254 */
@@ -317,7 +307,6 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
317 bio->bi_sector = where->sector + (where->count - remaining); 307 bio->bi_sector = where->sector + (where->count - remaining);
318 bio->bi_bdev = where->bdev; 308 bio->bi_bdev = where->bdev;
319 bio->bi_end_io = endio; 309 bio->bi_end_io = endio;
320 bio->bi_destructor = dm_bio_destructor;
321 store_io_and_region_in_bio(bio, io, region); 310 store_io_and_region_in_bio(bio, io, region);
322 311
323 if (rw & REQ_DISCARD) { 312 if (rw & REQ_DISCARD) {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 4e09b6ff5b49..0c3d6dd51897 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -681,11 +681,6 @@ static void clone_endio(struct bio *bio, int error)
681 } 681 }
682 } 682 }
683 683
684 /*
685 * Store md for cleanup instead of tio which is about to get freed.
686 */
687 bio->bi_private = md->bs;
688
689 free_tio(md, tio); 684 free_tio(md, tio);
690 bio_put(bio); 685 bio_put(bio);
691 dec_pending(io, error); 686 dec_pending(io, error);
@@ -1032,11 +1027,6 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
1032 /* error the io and bail out, or requeue it if needed */ 1027 /* error the io and bail out, or requeue it if needed */
1033 md = tio->io->md; 1028 md = tio->io->md;
1034 dec_pending(tio->io, r); 1029 dec_pending(tio->io, r);
1035 /*
1036 * Store bio_set for cleanup.
1037 */
1038 clone->bi_end_io = NULL;
1039 clone->bi_private = md->bs;
1040 bio_put(clone); 1030 bio_put(clone);
1041 free_tio(md, tio); 1031 free_tio(md, tio);
1042 } else if (r) { 1032 } else if (r) {
@@ -1055,13 +1045,6 @@ struct clone_info {
1055 unsigned short idx; 1045 unsigned short idx;
1056}; 1046};
1057 1047
1058static void dm_bio_destructor(struct bio *bio)
1059{
1060 struct bio_set *bs = bio->bi_private;
1061
1062 bio_free(bio, bs);
1063}
1064
1065/* 1048/*
1066 * Creates a little bio that just does part of a bvec. 1049 * Creates a little bio that just does part of a bvec.
1067 */ 1050 */
@@ -1073,7 +1056,6 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
1073 struct bio_vec *bv = bio->bi_io_vec + idx; 1056 struct bio_vec *bv = bio->bi_io_vec + idx;
1074 1057
1075 clone = bio_alloc_bioset(GFP_NOIO, 1, bs); 1058 clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
1076 clone->bi_destructor = dm_bio_destructor;
1077 *clone->bi_io_vec = *bv; 1059 *clone->bi_io_vec = *bv;
1078 1060
1079 clone->bi_sector = sector; 1061 clone->bi_sector = sector;
@@ -1105,7 +1087,6 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector,
1105 1087
1106 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs); 1088 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
1107 __bio_clone(clone, bio); 1089 __bio_clone(clone, bio);
1108 clone->bi_destructor = dm_bio_destructor;
1109 clone->bi_sector = sector; 1090 clone->bi_sector = sector;
1110 clone->bi_idx = idx; 1091 clone->bi_idx = idx;
1111 clone->bi_vcnt = idx + bv_count; 1092 clone->bi_vcnt = idx + bv_count;
@@ -1150,7 +1131,6 @@ static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
1150 */ 1131 */
1151 clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs); 1132 clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs);
1152 __bio_clone(clone, ci->bio); 1133 __bio_clone(clone, ci->bio);
1153 clone->bi_destructor = dm_bio_destructor;
1154 if (len) { 1134 if (len) {
1155 clone->bi_sector = ci->sector; 1135 clone->bi_sector = ci->sector;
1156 clone->bi_size = to_bytes(len); 1136 clone->bi_size = to_bytes(len);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 3f6203a4c7ea..b8eebe357b2b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -155,32 +155,17 @@ static int start_readonly;
155 * like bio_clone, but with a local bio set 155 * like bio_clone, but with a local bio set
156 */ 156 */
157 157
158static void mddev_bio_destructor(struct bio *bio)
159{
160 struct mddev *mddev, **mddevp;
161
162 mddevp = (void*)bio;
163 mddev = mddevp[-1];
164
165 bio_free(bio, mddev->bio_set);
166}
167
168struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs, 158struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs,
169 struct mddev *mddev) 159 struct mddev *mddev)
170{ 160{
171 struct bio *b; 161 struct bio *b;
172 struct mddev **mddevp;
173 162
174 if (!mddev || !mddev->bio_set) 163 if (!mddev || !mddev->bio_set)
175 return bio_alloc(gfp_mask, nr_iovecs); 164 return bio_alloc(gfp_mask, nr_iovecs);
176 165
177 b = bio_alloc_bioset(gfp_mask, nr_iovecs, 166 b = bio_alloc_bioset(gfp_mask, nr_iovecs, mddev->bio_set);
178 mddev->bio_set);
179 if (!b) 167 if (!b)
180 return NULL; 168 return NULL;
181 mddevp = (void*)b;
182 mddevp[-1] = mddev;
183 b->bi_destructor = mddev_bio_destructor;
184 return b; 169 return b;
185} 170}
186EXPORT_SYMBOL_GPL(bio_alloc_mddev); 171EXPORT_SYMBOL_GPL(bio_alloc_mddev);
@@ -189,18 +174,14 @@ struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask,
189 struct mddev *mddev) 174 struct mddev *mddev)
190{ 175{
191 struct bio *b; 176 struct bio *b;
192 struct mddev **mddevp;
193 177
194 if (!mddev || !mddev->bio_set) 178 if (!mddev || !mddev->bio_set)
195 return bio_clone(bio, gfp_mask); 179 return bio_clone(bio, gfp_mask);
196 180
197 b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, 181 b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, mddev->bio_set);
198 mddev->bio_set);
199 if (!b) 182 if (!b)
200 return NULL; 183 return NULL;
201 mddevp = (void*)b; 184
202 mddevp[-1] = mddev;
203 b->bi_destructor = mddev_bio_destructor;
204 __bio_clone(b, bio); 185 __bio_clone(b, bio);
205 if (bio_integrity(bio)) { 186 if (bio_integrity(bio)) {
206 int ret; 187 int ret;
@@ -5006,8 +4987,7 @@ int md_run(struct mddev *mddev)
5006 } 4987 }
5007 4988
5008 if (mddev->bio_set == NULL) 4989 if (mddev->bio_set == NULL)
5009 mddev->bio_set = bioset_create(BIO_POOL_SIZE, 4990 mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0);
5010 sizeof(struct mddev *));
5011 4991
5012 spin_lock(&pers_lock); 4992 spin_lock(&pers_lock);
5013 pers = find_pers(mddev->level, mddev->clevel); 4993 pers = find_pers(mddev->level, mddev->clevel);