diff options
author | Kent Overstreet <koverstreet@google.com> | 2012-09-06 18:35:00 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-09-09 04:35:39 -0400 |
commit | 4254bba17d92d53822a56ebc2a0c1eb7e2a71155 (patch) | |
tree | 77668d39949a0751c5e9ef8d0fb47b96392e84e5 | |
parent | ccc5c9ca6aac08218b1ba52afd07a1a9864c8c5d (diff) |
block: Kill bi_destructor
Now that we've got generic code for freeing bios allocated from bio
pools, this isn't needed anymore.
This patch also makes bio_free() static, since without bi_destructor
there should be no need for it to be called anywhere else.
bio_free() is now only called from bio_put, so we can refactor those a
bit - move some code from bio_put() to bio_free() and kill the redundant
bio->bi_next = NULL.
v5: Switch to BIO_KMALLOC_POOL ((void *)~0), per Boaz
v6: BIO_KMALLOC_POOL now NULL, drop bio_free's EXPORT_SYMBOL
v7: No #define BIO_KMALLOC_POOL anymore
Signed-off-by: Kent Overstreet <koverstreet@google.com>
CC: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | Documentation/block/biodoc.txt | 5 | ||||
-rw-r--r-- | block/blk-core.c | 2 | ||||
-rw-r--r-- | fs/bio.c | 64 | ||||
-rw-r--r-- | include/linux/bio.h | 1 | ||||
-rw-r--r-- | include/linux/blk_types.h | 3 |
5 files changed, 27 insertions, 48 deletions
diff --git a/Documentation/block/biodoc.txt b/Documentation/block/biodoc.txt index e418dc0a7086..8df5e8e6dceb 100644 --- a/Documentation/block/biodoc.txt +++ b/Documentation/block/biodoc.txt | |||
@@ -465,7 +465,6 @@ struct bio { | |||
465 | bio_end_io_t *bi_end_io; /* bi_end_io (bio) */ | 465 | bio_end_io_t *bi_end_io; /* bi_end_io (bio) */ |
466 | atomic_t bi_cnt; /* pin count: free when it hits zero */ | 466 | atomic_t bi_cnt; /* pin count: free when it hits zero */ |
467 | void *bi_private; | 467 | void *bi_private; |
468 | bio_destructor_t *bi_destructor; /* bi_destructor (bio) */ | ||
469 | }; | 468 | }; |
470 | 469 | ||
471 | With this multipage bio design: | 470 | With this multipage bio design: |
@@ -647,10 +646,6 @@ for a non-clone bio. There are the 6 pools setup for different size biovecs, | |||
647 | so bio_alloc(gfp_mask, nr_iovecs) will allocate a vec_list of the | 646 | so bio_alloc(gfp_mask, nr_iovecs) will allocate a vec_list of the |
648 | given size from these slabs. | 647 | given size from these slabs. |
649 | 648 | ||
650 | The bi_destructor() routine takes into account the possibility of the bio | ||
651 | having originated from a different source (see later discussions on | ||
652 | n/w to block transfers and kvec_cb) | ||
653 | |||
654 | The bio_get() routine may be used to hold an extra reference on a bio prior | 649 | The bio_get() routine may be used to hold an extra reference on a bio prior |
655 | to i/o submission, if the bio fields are likely to be accessed after the | 650 | to i/o submission, if the bio fields are likely to be accessed after the |
656 | i/o is issued (since the bio may otherwise get freed in case i/o completion | 651 | i/o is issued (since the bio may otherwise get freed in case i/o completion |
diff --git a/block/blk-core.c b/block/blk-core.c index 95c493511be7..b776cc90a4e7 100644 --- a/block/blk-core.c +++ b/block/blk-core.c | |||
@@ -2807,7 +2807,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src, | |||
2807 | 2807 | ||
2808 | free_and_out: | 2808 | free_and_out: |
2809 | if (bio) | 2809 | if (bio) |
2810 | bio_free(bio, bs); | 2810 | bio_put(bio); |
2811 | blk_rq_unprep_clone(rq); | 2811 | blk_rq_unprep_clone(rq); |
2812 | 2812 | ||
2813 | return -ENOMEM; | 2813 | return -ENOMEM; |
@@ -233,26 +233,37 @@ fallback: | |||
233 | return bvl; | 233 | return bvl; |
234 | } | 234 | } |
235 | 235 | ||
236 | void bio_free(struct bio *bio, struct bio_set *bs) | 236 | static void __bio_free(struct bio *bio) |
237 | { | 237 | { |
238 | void *p; | 238 | bio_disassociate_task(bio); |
239 | |||
240 | if (bio_has_allocated_vec(bio)) | ||
241 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | ||
242 | 239 | ||
243 | if (bio_integrity(bio)) | 240 | if (bio_integrity(bio)) |
244 | bio_integrity_free(bio); | 241 | bio_integrity_free(bio); |
242 | } | ||
245 | 243 | ||
246 | /* | 244 | static void bio_free(struct bio *bio) |
247 | * If we have front padding, adjust the bio pointer before freeing | 245 | { |
248 | */ | 246 | struct bio_set *bs = bio->bi_pool; |
249 | p = bio; | 247 | void *p; |
250 | if (bs->front_pad) | 248 | |
249 | __bio_free(bio); | ||
250 | |||
251 | if (bs) { | ||
252 | if (bio_has_allocated_vec(bio)) | ||
253 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | ||
254 | |||
255 | /* | ||
256 | * If we have front padding, adjust the bio pointer before freeing | ||
257 | */ | ||
258 | p = bio; | ||
251 | p -= bs->front_pad; | 259 | p -= bs->front_pad; |
252 | 260 | ||
253 | mempool_free(p, bs->bio_pool); | 261 | mempool_free(p, bs->bio_pool); |
262 | } else { | ||
263 | /* Bio was allocated by bio_kmalloc() */ | ||
264 | kfree(bio); | ||
265 | } | ||
254 | } | 266 | } |
255 | EXPORT_SYMBOL(bio_free); | ||
256 | 267 | ||
257 | void bio_init(struct bio *bio) | 268 | void bio_init(struct bio *bio) |
258 | { | 269 | { |
@@ -276,10 +287,7 @@ void bio_reset(struct bio *bio) | |||
276 | { | 287 | { |
277 | unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS); | 288 | unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS); |
278 | 289 | ||
279 | if (bio_integrity(bio)) | 290 | __bio_free(bio); |
280 | bio_integrity_free(bio); | ||
281 | |||
282 | bio_disassociate_task(bio); | ||
283 | 291 | ||
284 | memset(bio, 0, BIO_RESET_BYTES); | 292 | memset(bio, 0, BIO_RESET_BYTES); |
285 | bio->bi_flags = flags|(1 << BIO_UPTODATE); | 293 | bio->bi_flags = flags|(1 << BIO_UPTODATE); |
@@ -362,13 +370,6 @@ struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs) | |||
362 | } | 370 | } |
363 | EXPORT_SYMBOL(bio_alloc); | 371 | EXPORT_SYMBOL(bio_alloc); |
364 | 372 | ||
365 | static void bio_kmalloc_destructor(struct bio *bio) | ||
366 | { | ||
367 | if (bio_integrity(bio)) | ||
368 | bio_integrity_free(bio); | ||
369 | kfree(bio); | ||
370 | } | ||
371 | |||
372 | /** | 373 | /** |
373 | * bio_kmalloc - allocate a bio for I/O using kmalloc() | 374 | * bio_kmalloc - allocate a bio for I/O using kmalloc() |
374 | * @gfp_mask: the GFP_ mask given to the slab allocator | 375 | * @gfp_mask: the GFP_ mask given to the slab allocator |
@@ -395,7 +396,6 @@ struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs) | |||
395 | bio->bi_flags |= BIO_POOL_NONE << BIO_POOL_OFFSET; | 396 | bio->bi_flags |= BIO_POOL_NONE << BIO_POOL_OFFSET; |
396 | bio->bi_max_vecs = nr_iovecs; | 397 | bio->bi_max_vecs = nr_iovecs; |
397 | bio->bi_io_vec = bio->bi_inline_vecs; | 398 | bio->bi_io_vec = bio->bi_inline_vecs; |
398 | bio->bi_destructor = bio_kmalloc_destructor; | ||
399 | 399 | ||
400 | return bio; | 400 | return bio; |
401 | } | 401 | } |
@@ -431,20 +431,8 @@ void bio_put(struct bio *bio) | |||
431 | /* | 431 | /* |
432 | * last put frees it | 432 | * last put frees it |
433 | */ | 433 | */ |
434 | if (atomic_dec_and_test(&bio->bi_cnt)) { | 434 | if (atomic_dec_and_test(&bio->bi_cnt)) |
435 | bio_disassociate_task(bio); | 435 | bio_free(bio); |
436 | bio->bi_next = NULL; | ||
437 | |||
438 | /* | ||
439 | * This if statement is temporary - bi_pool is replacing | ||
440 | * bi_destructor, but bi_destructor will be taken out in another | ||
441 | * patch. | ||
442 | */ | ||
443 | if (bio->bi_pool) | ||
444 | bio_free(bio, bio->bi_pool); | ||
445 | else | ||
446 | bio->bi_destructor(bio); | ||
447 | } | ||
448 | } | 436 | } |
449 | EXPORT_SYMBOL(bio_put); | 437 | EXPORT_SYMBOL(bio_put); |
450 | 438 | ||
diff --git a/include/linux/bio.h b/include/linux/bio.h index 76f6c252baff..04944c91fae7 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h | |||
@@ -216,7 +216,6 @@ extern struct bio *bio_alloc(gfp_t, unsigned int); | |||
216 | extern struct bio *bio_kmalloc(gfp_t, unsigned int); | 216 | extern struct bio *bio_kmalloc(gfp_t, unsigned int); |
217 | extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *); | 217 | extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *); |
218 | extern void bio_put(struct bio *); | 218 | extern void bio_put(struct bio *); |
219 | extern void bio_free(struct bio *, struct bio_set *); | ||
220 | 219 | ||
221 | extern void bio_endio(struct bio *, int); | 220 | extern void bio_endio(struct bio *, int); |
222 | struct request_queue; | 221 | struct request_queue; |
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 1b607c247d72..3eefbb291192 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h | |||
@@ -84,11 +84,8 @@ struct bio { | |||
84 | 84 | ||
85 | struct bio_vec *bi_io_vec; /* the actual vec list */ | 85 | struct bio_vec *bi_io_vec; /* the actual vec list */ |
86 | 86 | ||
87 | /* If bi_pool is non NULL, bi_destructor is not called */ | ||
88 | struct bio_set *bi_pool; | 87 | struct bio_set *bi_pool; |
89 | 88 | ||
90 | bio_destructor_t *bi_destructor; /* destructor */ | ||
91 | |||
92 | /* | 89 | /* |
93 | * We can inline a number of vecs at the end of the bio, to avoid | 90 | * We can inline a number of vecs at the end of the bio, to avoid |
94 | * double allocations for a small number of bio_vecs. This member | 91 | * double allocations for a small number of bio_vecs. This member |