Skip to contentSkip to conversation

block: fix 'kmem_cache of name 'bio-108' already exists'

PATCH Applied Ming Lei 3 participants 4 messages Feb 28, 2025 – Mar 4, 2025 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: fix 'kmem_cache of name 'bio-108' already exists'

Device mapper bioset often has big bio_slab size, which can be more than 1000, then 8byte can't hold the slab name any more, cause the kmem_cache allocation warning of 'kmem_cache of name 'bio-108' already exists'.

Fix the warning by extending bio_slab->name to 12 bytes, but fix output of /proc/slabinfo

---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/bio.c +1 -1
index f0c416e5931d..6ac5983ba51e 100644
@@ -77,7 +77,7 @@ struct bio_slab {
 	struct kmem_cache *slab;
 	unsigned int slab_ref;
 	unsigned int slab_size;
-	char name[8];
+	char name[12];
 };
 static DEFINE_MUTEX(bio_slab_lock);
 static DEFINE_XARRAY(bio_slabs);
Signature · 1 line
2.47.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Ming Lei

Device mapper bioset often has big bio_slab size, which can be more than 1000, then 8byte can't hold the slab name any more, cause the kmem_cache allocation warning of 'kmem_cache of name 'bio-108' already exists'.

Fix the warning by extending bio_slab->name to 12 bytes, but fix output of /proc/slabinfo

[...]

Applied, thanks!

[1/1] block: fix 'kmem_cache of name 'bio-108' already exists'
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Ming Lei
Quoted 18 lines · Ming Lei

Device mapper bioset often has big bio_slab size, which can be more than 1000, then 8byte can't hold the slab name any more, cause the kmem_cache allocation warning of 'kmem_cache of name 'bio-108' already exists'.

Fix the warning by extending bio_slab->name to 12 bytes, but fix output of /proc/slabinfo

---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/bio.c +0 -0
index f0c416e5931d..6ac5983ba51e 100644

block/bio.c struct bio_slab { · line 80

Quoted 5 lines
block/bio.c +1 -1
@@ -77,7 +77,7 @@ struct bio_slab {
 	struct kmem_cache *slab;
 	unsigned int slab_ref;
 	unsigned int slab_size;
-	char name[8];
+	char name[12];

Can you please turn this into a pointer and use kasprintf to fill it? That way we fix the string overflow problem for real and don't need to doctor around it the next time someone uses names with a longer name.

author
#3 lore raw
Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Ming Lei

Device mapper bioset often has big bio_slab size, which can be more than 1000, then 8byte can't hold the slab name any more, cause the kmem_cache allocation warning of 'kmem_cache of name 'bio-108' already exists'.

Fix the warning by extending bio_slab->name to 12 bytes, but fix output of /proc/slabinfo

---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

block/bio.c struct bio_slab { · line 80

Quoted 10 lines
block/bio.c +1 -1
index f0c416e5931d..6ac5983ba51e 100644
@@ -77,7 +77,7 @@ struct bio_slab {
 	struct kmem_cache *slab;
 	unsigned int slab_ref;
 	unsigned int slab_size;
-	char name[8];
+	char name[12];

Can you please turn this into a pointer and use kasprintf to fill it? That way we fix the string overflow problem for real and don't need to doctor around it the next time someone uses names with a longer name.

There isn't the overflow problem, please see create_bio_slab(), which calls snprintf() to fill the ->name[].

Also extra 4byte can support bio size of ~10^7, which is big enough as block layer API.

Thanks,
Ming