summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-03-08 11:39:16 -0700
committerJens Axboe <axboe@kernel.dk>2021-08-09 15:14:16 -0600
commitdb69e416ac26a7c89b00e5a9093f90d9b2e16fc9 (patch)
tree68fc48f4363e407b2a15aa126a27f5cecda03f37
parent38949f870e205b60275c2870d0428e3afcb42a6f (diff)
block: enable use of bio allocation cache
If a kiocb is marked as being valid for bio caching, then use that to allocate a (and free) new bio if possible. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--fs/block_dev.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9ef4f1fc2cb0..36a3d53326c0 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -327,6 +327,14 @@ static int blkdev_iopoll(struct kiocb *kiocb, bool wait)
return blk_poll(q, READ_ONCE(kiocb->ki_cookie), wait);
}
+static void dio_bio_put(struct blkdev_dio *dio)
+{
+ if (!dio->is_sync && (dio->iocb->ki_flags & IOCB_ALLOC_CACHE))
+ bio_cache_put(&dio->bio);
+ else
+ bio_put(&dio->bio);
+}
+
static void blkdev_bio_end_io(struct bio *bio)
{
struct blkdev_dio *dio = bio->bi_private;
@@ -362,7 +370,7 @@ static void blkdev_bio_end_io(struct bio *bio)
bio_check_pages_dirty(bio);
} else {
bio_release_pages(bio, false);
- bio_put(bio);
+ dio_bio_put(dio);
}
}
@@ -385,7 +393,14 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
(bdev_logical_block_size(bdev) - 1))
return -EINVAL;
- bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, &blkdev_dio_pool);
+ bio = NULL;
+ if (iocb->ki_flags & IOCB_ALLOC_CACHE) {
+ bio = bio_cache_get(GFP_KERNEL, nr_pages, &blkdev_dio_pool);
+ if (!bio)
+ iocb->ki_flags &= ~IOCB_ALLOC_CACHE;
+ }
+ if (!bio)
+ bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, &blkdev_dio_pool);
dio = container_of(bio, struct blkdev_dio, bio);
dio->is_sync = is_sync = is_sync_kiocb(iocb);
@@ -467,7 +482,14 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
}
submit_bio(bio);
- bio = bio_alloc(GFP_KERNEL, nr_pages);
+ bio = NULL;
+ if (iocb->ki_flags & IOCB_ALLOC_CACHE) {
+ bio = bio_cache_get(GFP_KERNEL, nr_pages, &fs_bio_set);
+ if (!bio)
+ iocb->ki_flags &= ~IOCB_ALLOC_CACHE;
+ }
+ if (!bio)
+ bio = bio_alloc(GFP_KERNEL, nr_pages);
}
if (!is_poll)
@@ -492,7 +514,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
if (likely(!ret))
ret = dio->size;
- bio_put(&dio->bio);
+ dio_bio_put(dio);
return ret;
}