iomap: enable use of bio allocation cache io_uring-bio-cache.3
authorJens Axboe <axboe@kernel.dk>
Tue, 9 Mar 2021 16:25:47 +0000 (09:25 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 10 Aug 2021 19:57:19 +0000 (13:57 -0600)
If the kiocb passed in has a bio cache specified, then use that to allocate
a (and free) new bio if possible.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/iomap/direct-io.c

index 9398b8c31323b39278144bf8cbaa1ba5d0f94180..ccef77fec4a073880ce6c86e45aa13485fd42684 100644 (file)
@@ -154,7 +154,10 @@ static void iomap_dio_bio_end_io(struct bio *bio)
 {
        struct iomap_dio *dio = bio->bi_private;
        bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY);
+       struct bio_alloc_cache *cache = dio->iocb->ki_bio_cache;
 
+       if (!(dio->iocb->ki_flags & IOCB_ALLOC_CACHE))
+               cache = NULL;
        if (bio->bi_status)
                iomap_dio_set_error(dio, blk_status_to_errno(bio->bi_status));
 
@@ -177,7 +180,7 @@ static void iomap_dio_bio_end_io(struct bio *bio)
                bio_check_pages_dirty(bio);
        } else {
                bio_release_pages(bio, false);
-               bio_put(bio);
+               bio_cache_put(cache, bio);
        }
 }
 
@@ -305,7 +308,15 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
                        goto out;
                }
 
-               bio = bio_alloc(GFP_KERNEL, nr_pages);
+               bio = NULL;
+               if (dio->iocb->ki_flags & IOCB_ALLOC_CACHE) {
+                       bio = bio_cache_get(dio->iocb->ki_bio_cache, GFP_KERNEL,
+                                               nr_pages, &fs_bio_set);
+                       if (!bio)
+                               dio->iocb->ki_flags &= ~IOCB_ALLOC_CACHE;
+               }
+               if (!bio)
+                       bio = bio_alloc(GFP_KERNEL, nr_pages);
                bio_set_dev(bio, iomap->bdev);
                bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
                bio->bi_write_hint = dio->iocb->ki_hint;