aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-04-24 10:48:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-24 10:48:24 -0400
commit97c68d00dbb2decda4b3dce79ce55df04246a834 (patch)
treef7c2f3185e4dfb073f6d268b4aa0a4d9a0015ece /fs
parent596a5c4e43b08e90c0cd788861f859bf7ed6eddc (diff)
parentf2d1f0ae7851be5ebd9613a80dac139270938809 (diff)
Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
* 'for-linus' of git://git.kernel.dk/linux-2.6-block: cfq-iosched: cache prio_tree root in cfqq->p_root cfq-iosched: fix bug with aliased request and cooperation detection cfq-iosched: clear ->prio_trees[] on cfqd alloc block: fix intermittent dm timeout based oops umem: fix request_queue lock warning block: simplify I/O stat accounting pktcdvd.h should include mempool.h cfq-iosched: use the default seek distance when there aren't enough seek samples cfq-iosched: make seek_mean converge more quickly block: make blk_abort_queue() ignore non-request based devices block: include empty disks in /proc/diskstats bio: use bio_kmalloc() in copy/map functions bio: fix bio_kmalloc() block: fix queue bounce limit setting block: fix SG_IO vector request data length handling scatterlist: make sure sg_miter_next() doesn't return 0 sized mappings
Diffstat (limited to 'fs')
-rw-r--r--fs/bio.c124
1 files changed, 57 insertions, 67 deletions
diff --git a/fs/bio.c b/fs/bio.c
index cd42bb882f30..7bbc98f0eda1 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -175,14 +175,6 @@ struct bio_vec *bvec_alloc_bs(gfp_t gfp_mask, int nr, unsigned long *idx,
175 struct bio_vec *bvl; 175 struct bio_vec *bvl;
176 176
177 /* 177 /*
178 * If 'bs' is given, lookup the pool and do the mempool alloc.
179 * If not, this is a bio_kmalloc() allocation and just do a
180 * kzalloc() for the exact number of vecs right away.
181 */
182 if (!bs)
183 bvl = kmalloc(nr * sizeof(struct bio_vec), gfp_mask);
184
185 /*
186 * see comment near bvec_array define! 178 * see comment near bvec_array define!
187 */ 179 */
188 switch (nr) { 180 switch (nr) {
@@ -260,21 +252,6 @@ void bio_free(struct bio *bio, struct bio_set *bs)
260 mempool_free(p, bs->bio_pool); 252 mempool_free(p, bs->bio_pool);
261} 253}
262 254
263/*
264 * default destructor for a bio allocated with bio_alloc_bioset()
265 */
266static void bio_fs_destructor(struct bio *bio)
267{
268 bio_free(bio, fs_bio_set);
269}
270
271static void bio_kmalloc_destructor(struct bio *bio)
272{
273 if (bio_has_allocated_vec(bio))
274 kfree(bio->bi_io_vec);
275 kfree(bio);
276}
277
278void bio_init(struct bio *bio) 255void bio_init(struct bio *bio)
279{ 256{
280 memset(bio, 0, sizeof(*bio)); 257 memset(bio, 0, sizeof(*bio));
@@ -301,21 +278,15 @@ void bio_init(struct bio *bio)
301 **/ 278 **/
302struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs) 279struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
303{ 280{
281 unsigned long idx = BIO_POOL_NONE;
304 struct bio_vec *bvl = NULL; 282 struct bio_vec *bvl = NULL;
305 struct bio *bio = NULL; 283 struct bio *bio;
306 unsigned long idx = 0; 284 void *p;
307 void *p = NULL; 285
308 286 p = mempool_alloc(bs->bio_pool, gfp_mask);
309 if (bs) { 287 if (unlikely(!p))
310 p = mempool_alloc(bs->bio_pool, gfp_mask); 288 return NULL;
311 if (!p) 289 bio = p + bs->front_pad;
312 goto err;
313 bio = p + bs->front_pad;
314 } else {
315 bio = kmalloc(sizeof(*bio), gfp_mask);
316 if (!bio)
317 goto err;
318 }
319 290
320 bio_init(bio); 291 bio_init(bio);
321 292
@@ -332,22 +303,50 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
332 303
333 nr_iovecs = bvec_nr_vecs(idx); 304 nr_iovecs = bvec_nr_vecs(idx);
334 } 305 }
306out_set:
335 bio->bi_flags |= idx << BIO_POOL_OFFSET; 307 bio->bi_flags |= idx << BIO_POOL_OFFSET;
336 bio->bi_max_vecs = nr_iovecs; 308 bio->bi_max_vecs = nr_iovecs;
337out_set:
338 bio->bi_io_vec = bvl; 309 bio->bi_io_vec = bvl;
339
340 return bio; 310 return bio;
341 311
342err_free: 312err_free:
343 if (bs) 313 mempool_free(p, bs->bio_pool);
344 mempool_free(p, bs->bio_pool);
345 else
346 kfree(bio);
347err:
348 return NULL; 314 return NULL;
349} 315}
350 316
317static void bio_fs_destructor(struct bio *bio)
318{
319 bio_free(bio, fs_bio_set);
320}
321
322/**
323 * bio_alloc - allocate a new bio, memory pool backed
324 * @gfp_mask: allocation mask to use
325 * @nr_iovecs: number of iovecs
326 *
327 * Allocate a new bio with @nr_iovecs bvecs. If @gfp_mask
328 * contains __GFP_WAIT, the allocation is guaranteed to succeed.
329 *
330 * RETURNS:
331 * Pointer to new bio on success, NULL on failure.
332 */
333struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
334{
335 struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
336
337 if (bio)
338 bio->bi_destructor = bio_fs_destructor;
339
340 return bio;
341}
342
343static void bio_kmalloc_destructor(struct bio *bio)
344{
345 if (bio_integrity(bio))
346 bio_integrity_free(bio);
347 kfree(bio);
348}
349
351/** 350/**
352 * bio_alloc - allocate a bio for I/O 351 * bio_alloc - allocate a bio for I/O
353 * @gfp_mask: the GFP_ mask given to the slab allocator 352 * @gfp_mask: the GFP_ mask given to the slab allocator
@@ -366,29 +365,20 @@ err:
366 * do so can cause livelocks under memory pressure. 365 * do so can cause livelocks under memory pressure.
367 * 366 *
368 **/ 367 **/
369struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
370{
371 struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
372
373 if (bio)
374 bio->bi_destructor = bio_fs_destructor;
375
376 return bio;
377}
378
379/*
380 * Like bio_alloc(), but doesn't use a mempool backing. This means that
381 * it CAN fail, but while bio_alloc() can only be used for allocations
382 * that have a short (finite) life span, bio_kmalloc() should be used
383 * for more permanent bio allocations (like allocating some bio's for
384 * initalization or setup purposes).
385 */
386struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs) 368struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs)
387{ 369{
388 struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, NULL); 370 struct bio *bio;
389 371
390 if (bio) 372 bio = kmalloc(sizeof(struct bio) + nr_iovecs * sizeof(struct bio_vec),
391 bio->bi_destructor = bio_kmalloc_destructor; 373 gfp_mask);
374 if (unlikely(!bio))
375 return NULL;
376
377 bio_init(bio);
378 bio->bi_flags |= BIO_POOL_NONE << BIO_POOL_OFFSET;
379 bio->bi_max_vecs = nr_iovecs;
380 bio->bi_io_vec = bio->bi_inline_vecs;
381 bio->bi_destructor = bio_kmalloc_destructor;
392 382
393 return bio; 383 return bio;
394} 384}
@@ -832,7 +822,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
832 return ERR_PTR(-ENOMEM); 822 return ERR_PTR(-ENOMEM);
833 823
834 ret = -ENOMEM; 824 ret = -ENOMEM;
835 bio = bio_alloc(gfp_mask, nr_pages); 825 bio = bio_kmalloc(gfp_mask, nr_pages);
836 if (!bio) 826 if (!bio)
837 goto out_bmd; 827 goto out_bmd;
838 828
@@ -956,7 +946,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
956 if (!nr_pages) 946 if (!nr_pages)
957 return ERR_PTR(-EINVAL); 947 return ERR_PTR(-EINVAL);
958 948
959 bio = bio_alloc(gfp_mask, nr_pages); 949 bio = bio_kmalloc(gfp_mask, nr_pages);
960 if (!bio) 950 if (!bio)
961 return ERR_PTR(-ENOMEM); 951 return ERR_PTR(-ENOMEM);
962 952
@@ -1140,7 +1130,7 @@ static struct bio *__bio_map_kern(struct request_queue *q, void *data,
1140 int offset, i; 1130 int offset, i;
1141 struct bio *bio; 1131 struct bio *bio;
1142 1132
1143 bio = bio_alloc(gfp_mask, nr_pages); 1133 bio = bio_kmalloc(gfp_mask, nr_pages);
1144 if (!bio) 1134 if (!bio)
1145 return ERR_PTR(-ENOMEM); 1135 return ERR_PTR(-ENOMEM);
1146 1136