aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2015-04-17 18:23:59 -0400
committerJens Axboe <axboe@fb.com>2015-05-05 15:32:49 -0400
commitdac56212e8127dbc0bff7be35c508bc280213309 (patch)
treea1a066d7f6deb7d66403137b8edafb394ce0ca6a /block
parentc4cf5261f8bffd9de132b50660a69148e7575bd6 (diff)
bio: skip atomic inc/dec of ->bi_cnt for most use cases
Struct bio has a reference count that controls when it can be freed. Most uses cases is allocating the bio, which then returns with a single reference to it, doing IO, and then dropping that single reference. We can remove this atomic_dec_and_test() in the completion path, if nobody else is holding a reference to the bio. If someone does call bio_get() on the bio, then we flag the bio as now having valid count and that we must properly honor the reference count when it's being put. Tested-by: Robert Elliott <elliott@hp.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/bio.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/block/bio.c b/block/bio.c
index 117da319afb6..c2ff8a88aef1 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -271,7 +271,7 @@ void bio_init(struct bio *bio)
271 memset(bio, 0, sizeof(*bio)); 271 memset(bio, 0, sizeof(*bio));
272 bio->bi_flags = 1 << BIO_UPTODATE; 272 bio->bi_flags = 1 << BIO_UPTODATE;
273 atomic_set(&bio->__bi_remaining, 1); 273 atomic_set(&bio->__bi_remaining, 1);
274 atomic_set(&bio->bi_cnt, 1); 274 atomic_set(&bio->__bi_cnt, 1);
275} 275}
276EXPORT_SYMBOL(bio_init); 276EXPORT_SYMBOL(bio_init);
277 277
@@ -524,13 +524,17 @@ EXPORT_SYMBOL(zero_fill_bio);
524 **/ 524 **/
525void bio_put(struct bio *bio) 525void bio_put(struct bio *bio)
526{ 526{
527 BIO_BUG_ON(!atomic_read(&bio->bi_cnt)); 527 if (!bio_flagged(bio, BIO_REFFED))
528
529 /*
530 * last put frees it
531 */
532 if (atomic_dec_and_test(&bio->bi_cnt))
533 bio_free(bio); 528 bio_free(bio);
529 else {
530 BIO_BUG_ON(!atomic_read(&bio->__bi_cnt));
531
532 /*
533 * last put frees it
534 */
535 if (atomic_dec_and_test(&bio->__bi_cnt))
536 bio_free(bio);
537 }
534} 538}
535EXPORT_SYMBOL(bio_put); 539EXPORT_SYMBOL(bio_put);
536 540