diff options
author | Kent Overstreet <koverstreet@google.com> | 2012-09-06 18:34:58 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-09-09 04:35:39 -0400 |
commit | f44b48c7691be7643877d1f881b5eeace654d05d (patch) | |
tree | a862b4844b99abfa1bfb6fd437cf1ee4f055c438 | |
parent | 94818742316e27d01506240cf8b07d69844d31af (diff) |
block: Add bio_reset()
Reusing bios is something that's been highly frowned upon in the past,
but driver code keeps doing it anyways. If it's going to happen anyways,
we should provide a generic method.
This'll help with getting rid of bi_destructor - drivers/block/pktcdvd.c
was open coding it, by doing a bio_init() and resetting bi_destructor.
This required reordering struct bio, but the block layer is not yet
nearly fast enough for any cacheline effects to matter here.
v5: Add a define BIO_RESET_BITS, to be very explicit about what parts of
bio->bi_flags are saved.
v6: Further commenting verbosity, per Tejun
v9: Add a function comment
Signed-off-by: Kent Overstreet <koverstreet@google.com>
CC: Jens Axboe <axboe@kernel.dk>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | fs/bio.c | 24 | ||||
-rw-r--r-- | include/linux/bio.h | 1 | ||||
-rw-r--r-- | include/linux/blk_types.h | 25 |
3 files changed, 44 insertions, 6 deletions
@@ -263,6 +263,30 @@ void bio_init(struct bio *bio) | |||
263 | EXPORT_SYMBOL(bio_init); | 263 | EXPORT_SYMBOL(bio_init); |
264 | 264 | ||
265 | /** | 265 | /** |
266 | * bio_reset - reinitialize a bio | ||
267 | * @bio: bio to reset | ||
268 | * | ||
269 | * Description: | ||
270 | * After calling bio_reset(), @bio will be in the same state as a freshly | ||
271 | * allocated bio returned bio bio_alloc_bioset() - the only fields that are | ||
272 | * preserved are the ones that are initialized by bio_alloc_bioset(). See | ||
273 | * comment in struct bio. | ||
274 | */ | ||
275 | void bio_reset(struct bio *bio) | ||
276 | { | ||
277 | unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS); | ||
278 | |||
279 | if (bio_integrity(bio)) | ||
280 | bio_integrity_free(bio); | ||
281 | |||
282 | bio_disassociate_task(bio); | ||
283 | |||
284 | memset(bio, 0, BIO_RESET_BYTES); | ||
285 | bio->bi_flags = flags|(1 << BIO_UPTODATE); | ||
286 | } | ||
287 | EXPORT_SYMBOL(bio_reset); | ||
288 | |||
289 | /** | ||
266 | * bio_alloc_bioset - allocate a bio for I/O | 290 | * bio_alloc_bioset - allocate a bio for I/O |
267 | * @gfp_mask: the GFP_ mask given to the slab allocator | 291 | * @gfp_mask: the GFP_ mask given to the slab allocator |
268 | * @nr_iovecs: number of iovecs to pre-allocate | 292 | * @nr_iovecs: number of iovecs to pre-allocate |
diff --git a/include/linux/bio.h b/include/linux/bio.h index a11f74bc82d2..76f6c252baff 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h | |||
@@ -226,6 +226,7 @@ extern void __bio_clone(struct bio *, struct bio *); | |||
226 | extern struct bio *bio_clone(struct bio *, gfp_t); | 226 | extern struct bio *bio_clone(struct bio *, gfp_t); |
227 | 227 | ||
228 | extern void bio_init(struct bio *); | 228 | extern void bio_init(struct bio *); |
229 | extern void bio_reset(struct bio *); | ||
229 | 230 | ||
230 | extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int); | 231 | extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int); |
231 | extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, | 232 | extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, |
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index af9dd9d2efc4..1b607c247d72 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h | |||
@@ -59,12 +59,6 @@ struct bio { | |||
59 | unsigned int bi_seg_front_size; | 59 | unsigned int bi_seg_front_size; |
60 | unsigned int bi_seg_back_size; | 60 | unsigned int bi_seg_back_size; |
61 | 61 | ||
62 | unsigned int bi_max_vecs; /* max bvl_vecs we can hold */ | ||
63 | |||
64 | atomic_t bi_cnt; /* pin count */ | ||
65 | |||
66 | struct bio_vec *bi_io_vec; /* the actual vec list */ | ||
67 | |||
68 | bio_end_io_t *bi_end_io; | 62 | bio_end_io_t *bi_end_io; |
69 | 63 | ||
70 | void *bi_private; | 64 | void *bi_private; |
@@ -80,6 +74,16 @@ struct bio { | |||
80 | struct bio_integrity_payload *bi_integrity; /* data integrity */ | 74 | struct bio_integrity_payload *bi_integrity; /* data integrity */ |
81 | #endif | 75 | #endif |
82 | 76 | ||
77 | /* | ||
78 | * Everything starting with bi_max_vecs will be preserved by bio_reset() | ||
79 | */ | ||
80 | |||
81 | unsigned int bi_max_vecs; /* max bvl_vecs we can hold */ | ||
82 | |||
83 | atomic_t bi_cnt; /* pin count */ | ||
84 | |||
85 | struct bio_vec *bi_io_vec; /* the actual vec list */ | ||
86 | |||
83 | /* If bi_pool is non NULL, bi_destructor is not called */ | 87 | /* If bi_pool is non NULL, bi_destructor is not called */ |
84 | struct bio_set *bi_pool; | 88 | struct bio_set *bi_pool; |
85 | 89 | ||
@@ -93,6 +97,8 @@ struct bio { | |||
93 | struct bio_vec bi_inline_vecs[0]; | 97 | struct bio_vec bi_inline_vecs[0]; |
94 | }; | 98 | }; |
95 | 99 | ||
100 | #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs) | ||
101 | |||
96 | /* | 102 | /* |
97 | * bio flags | 103 | * bio flags |
98 | */ | 104 | */ |
@@ -108,6 +114,13 @@ struct bio { | |||
108 | #define BIO_FS_INTEGRITY 9 /* fs owns integrity data, not block layer */ | 114 | #define BIO_FS_INTEGRITY 9 /* fs owns integrity data, not block layer */ |
109 | #define BIO_QUIET 10 /* Make BIO Quiet */ | 115 | #define BIO_QUIET 10 /* Make BIO Quiet */ |
110 | #define BIO_MAPPED_INTEGRITY 11/* integrity metadata has been remapped */ | 116 | #define BIO_MAPPED_INTEGRITY 11/* integrity metadata has been remapped */ |
117 | |||
118 | /* | ||
119 | * Flags starting here get preserved by bio_reset() - this includes | ||
120 | * BIO_POOL_IDX() | ||
121 | */ | ||
122 | #define BIO_RESET_BITS 12 | ||
123 | |||
111 | #define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag))) | 124 | #define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag))) |
112 | 125 | ||
113 | /* | 126 | /* |