block: don't allocate inline bvecs if this bioset needn't bvecs
authorMing Lei <ming.lei@redhat.com>
Mon, 11 Jan 2021 03:05:54 +0000 (11:05 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Jan 2021 04:22:45 +0000 (21:22 -0700)
The inline bvecs won't be used if user needn't bvecs by not passing
BIOSET_NEED_BVECS, so don't allocate bvecs in this situation.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Tested-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c
include/linux/bio.h

index 87bf16460e0ead5d57a47a8380dda83a49fd8830..8ccda51dd831bf23f82168f3d86a484bbacdc506 100644 (file)
@@ -89,8 +89,7 @@ fail_alloc_slab:
 
 static inline unsigned int bs_bio_slab_size(struct bio_set *bs)
 {
-       return bs->front_pad + sizeof(struct bio) +
-               BIO_INLINE_VECS * sizeof(struct bio_vec);
+       return bs->front_pad + sizeof(struct bio) + bs->back_pad;
 }
 
 static struct kmem_cache *bio_find_or_create_slab(struct bio_set *bs)
@@ -1563,6 +1562,10 @@ int bioset_init(struct bio_set *bs,
                int flags)
 {
        bs->front_pad = front_pad;
+       if (flags & BIOSET_NEED_BVECS)
+               bs->back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec);
+       else
+               bs->back_pad = 0;
 
        spin_lock_init(&bs->rescue_lock);
        bio_list_init(&bs->rescue_list);
index 2f1155eabaff2989e8f7c2ed4043124bc884b76c..5d8977aafa199e4ee38f17d6b45ec3867f22b9e5 100644 (file)
@@ -703,6 +703,7 @@ struct bio_set {
        mempool_t bvec_integrity_pool;
 #endif
 
+       unsigned int back_pad;
        /*
         * Deadlock avoidance for stacking block drivers: see comments in
         * bio_alloc_bioset() for details