All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] block: increase bio_slab_nr only for necessary case
@ 2019-03-08 10:15 Chengguang Xu
  2019-03-08 10:15 ` [PATCH 2/2] block: code cleanup for bio_find_or_create_slab() Chengguang Xu
  2019-03-20  2:56 ` [PATCH 1/2] block: increase bio_slab_nr only for necessary case cgxu519
  0 siblings, 2 replies; 3+ messages in thread
From: Chengguang Xu @ 2019-03-08 10:15 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, Chengguang Xu

When fail to create new cache in bio_find_or_create_slab(),
we should not increase bio_slab_nr because it will cause
referring uninitilized data in subsequent search.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 block/bio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index 4db1008309ed..8081906f5d01 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -109,7 +109,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
 		bio_slabs = new_bio_slabs;
 	}
 	if (entry == -1)
-		entry = bio_slab_nr++;
+		entry = bio_slab_nr;
 
 	bslab = &bio_slabs[entry];
 
@@ -122,6 +122,10 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
 	bslab->slab = slab;
 	bslab->slab_ref = 1;
 	bslab->slab_size = sz;
+
+	if (entry == bio_slab_nr)
+		bio_slab_nr++;
+
 out_unlock:
 	mutex_unlock(&bio_slab_lock);
 	return slab;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] block: code cleanup for bio_find_or_create_slab()
  2019-03-08 10:15 [PATCH 1/2] block: increase bio_slab_nr only for necessary case Chengguang Xu
@ 2019-03-08 10:15 ` Chengguang Xu
  2019-03-20  2:56 ` [PATCH 1/2] block: increase bio_slab_nr only for necessary case cgxu519
  1 sibling, 0 replies; 3+ messages in thread
From: Chengguang Xu @ 2019-03-08 10:15 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, Chengguang Xu

It's just a simple code cleanup, not functional change.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 block/bio.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 8081906f5d01..fefd49a561ab 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -90,29 +90,27 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
 		else if (bslab->slab_size == sz) {
 			slab = bslab->slab;
 			bslab->slab_ref++;
-			break;
+			goto out_unlock;
 		}
 		i++;
 	}
 
-	if (slab)
-		goto out_unlock;
-
-	if (bio_slab_nr == bio_slab_max && entry == -1) {
-		new_bio_slab_max = bio_slab_max << 1;
-		new_bio_slabs = krealloc(bio_slabs,
+	if (entry == -1) {
+		if (bio_slab_nr == bio_slab_max) {
+			new_bio_slab_max = bio_slab_max << 1;
+			new_bio_slabs = krealloc(bio_slabs,
 					 new_bio_slab_max * sizeof(struct bio_slab),
 					 GFP_KERNEL);
-		if (!new_bio_slabs)
-			goto out_unlock;
-		bio_slab_max = new_bio_slab_max;
-		bio_slabs = new_bio_slabs;
-	}
-	if (entry == -1)
+			if (!new_bio_slabs)
+				goto out_unlock;
+			bio_slab_max = new_bio_slab_max;
+			bio_slabs = new_bio_slabs;
+		}
+
 		entry = bio_slab_nr;
+	}
 
 	bslab = &bio_slabs[entry];
-
 	snprintf(bslab->name, sizeof(bslab->name), "bio-%d", entry);
 	slab = kmem_cache_create(bslab->name, sz, ARCH_KMALLOC_MINALIGN,
 				 SLAB_HWCACHE_ALIGN, NULL);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] block: increase bio_slab_nr only for necessary case
  2019-03-08 10:15 [PATCH 1/2] block: increase bio_slab_nr only for necessary case Chengguang Xu
  2019-03-08 10:15 ` [PATCH 2/2] block: code cleanup for bio_find_or_create_slab() Chengguang Xu
@ 2019-03-20  2:56 ` cgxu519
  1 sibling, 0 replies; 3+ messages in thread
From: cgxu519 @ 2019-03-20  2:56 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

On 3/8/19 6:15 PM, Chengguang Xu wrote:
> When fail to create new cache in bio_find_or_create_slab(),
> we should not increase bio_slab_nr because it will cause
> referring uninitilized data in subsequent search.
>
> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> ---
>   block/bio.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index 4db1008309ed..8081906f5d01 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -109,7 +109,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
>   		bio_slabs = new_bio_slabs;
>   	}
>   	if (entry == -1)
> -		entry = bio_slab_nr++;
> +		entry = bio_slab_nr;
>
>   	bslab = &bio_slabs[entry];
>
> @@ -122,6 +122,10 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
>   	bslab->slab = slab;
>   	bslab->slab_ref = 1;
>   	bslab->slab_size = sz;
> +
> +	if (entry == bio_slab_nr)
> +		bio_slab_nr++;
> +
>   out_unlock:
>   	mutex_unlock(&bio_slab_lock);
>   	return slab;

Any suggestion?

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-20  2:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08 10:15 [PATCH 1/2] block: increase bio_slab_nr only for necessary case Chengguang Xu
2019-03-08 10:15 ` [PATCH 2/2] block: code cleanup for bio_find_or_create_slab() Chengguang Xu
2019-03-20  2:56 ` [PATCH 1/2] block: increase bio_slab_nr only for necessary case cgxu519

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.