diff mbox series

[V3,3/6] block: don't allocate inline bvecs if this bioset needn't bvecs

Message ID 20210111030557.4154161-4-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: improvement on bioset & bvec allocation | expand

Commit Message

Ming Lei Jan. 11, 2021, 3:05 a.m. UTC
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>
---
 block/bio.c         | 7 +++++--
 include/linux/bio.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

Comments

Pavel Begunkov Jan. 11, 2021, 4:41 a.m. UTC | #1
On 11/01/2021 03:05, Ming Lei wrote:
> 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>

> ---
>  block/bio.c         | 7 +++++--
>  include/linux/bio.h | 1 +
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index cfa0e9db30e0..496aa5938f79 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -89,8 +89,7 @@ static struct bio_slab *create_bio_slab(unsigned int size)
>  
>  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)
> @@ -1572,6 +1571,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);
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 1edda614f7ce..f606eb1e556f 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -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
>
Hannes Reinecke Jan. 11, 2021, 6:58 a.m. UTC | #2
On 1/11/21 4:05 AM, Ming Lei wrote:
> 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>
> ---
>   block/bio.c         | 7 +++++--
>   include/linux/bio.h | 1 +
>   2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index cfa0e9db30e0..496aa5938f79 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -89,8 +89,7 @@ static struct bio_slab *create_bio_slab(unsigned int size)
>   
>   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)
> @@ -1572,6 +1571,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);
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 1edda614f7ce..f606eb1e556f 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -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
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index cfa0e9db30e0..496aa5938f79 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -89,8 +89,7 @@  static struct bio_slab *create_bio_slab(unsigned int size)
 
 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)
@@ -1572,6 +1571,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);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 1edda614f7ce..f606eb1e556f 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -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