Skip to contentSkip to conversation

slub: Don't panic for memcg kmem cache creation failure

PATCH In review Shakeel Butt 4 participants 6 messages Jun 19, 2019 – Jun 21, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slub: Don't panic for memcg kmem cache creation failure

Currently for CONFIG_SLUB, if a memcg kmem cache creation is failed and the corresponding root kmem cache has SLAB_PANIC flag, the kernel will be crashed. This is unnecessary as the kernel can handle the creation failures of memcg kmem caches. Additionally CONFIG_SLAB does not implement this behavior. So, to keep the behavior consistent between SLAB and SLUB, removing the panic for memcg kmem cache creation failures. The root kmem cache creation failure for SLAB_PANIC correctly panics for both SLAB and SLUB.

---
 mm/slub.c | 4 ----
 1 file changed, 4 deletions(-)
mm/slub.c +0 -4
index 6a5174b51cd6..84c6508e360d 100644
@@ -3640,10 +3640,6 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
 
 	free_kmem_cache_nodes(s);
 error:
-	if (flags & SLAB_PANIC)
-		panic("Cannot create slab %s size=%u realsize=%u order=%u offset=%u flags=%lx\n",
-		      s->name, s->size, s->size,
-		      oo_order(s->oo), s->offset, (unsigned long)flags);
 	return -EINVAL;
 }
 
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Shakeel Butt

Currently for CONFIG_SLUB, if a memcg kmem cache creation is failed and the corresponding root kmem cache has SLAB_PANIC flag, the kernel will be crashed. This is unnecessary as the kernel can handle the creation failures of memcg kmem caches.

AFAICS it will handle those by simply not accounting those objects right?

Quoted 5 lines

Additionally CONFIG_SLAB does not
implement this behavior. So, to keep the behavior consistent between SLAB and SLUB, removing the panic for memcg kmem cache creation failures. The root kmem cache creation failure for SLAB_PANIC correctly panics for both SLAB and SLUB.

I do agree that panicing is really dubious especially because it opens doors to shut the system down from a restricted environment. So the patch makes sesne to me.

I am wondering whether SLAB_PANIC makes sense in general though. Why is it any different from any other essential early allocations? We tend to not care about allocation failures for those on bases that the system must be in a broken state to fail that early already. Do you think it is time to remove SLAB_PANIC altogether?

Quoted 2 lines
Quoted 21 lines
---
 mm/slub.c | 4 ----
 1 file changed, 4 deletions(-)
mm/slub.c +0 -4
index 6a5174b51cd6..84c6508e360d 100644
@@ -3640,10 +3640,6 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
 
 	free_kmem_cache_nodes(s);
 error:
-	if (flags & SLAB_PANIC)
-		panic("Cannot create slab %s size=%u realsize=%u order=%u offset=%u flags=%lx\n",
-		      s->name, s->size, s->size,
-		      oo_order(s->oo), s->offset, (unsigned long)flags);
 	return -EINVAL;
 }
 
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 10 lines · Michal Hocko
Quoted 4 lines · Shakeel Butt

Currently for CONFIG_SLUB, if a memcg kmem cache creation is failed and the corresponding root kmem cache has SLAB_PANIC flag, the kernel will be crashed. This is unnecessary as the kernel can handle the creation failures of memcg kmem caches.

AFAICS it will handle those by simply not accounting those objects right?

The memcg kmem cache creation is async. The allocation has already been decided not to be accounted on creation trigger. If memcg kmem cache creation is failed, it will fail silently and the next allocation will trigger the creation process again.

Quoted 10 lines
Quoted 5 lines

Additionally CONFIG_SLAB does not
implement this behavior. So, to keep the behavior consistent between SLAB and SLUB, removing the panic for memcg kmem cache creation failures. The root kmem cache creation failure for SLAB_PANIC correctly panics for both SLAB and SLUB.

I do agree that panicing is really dubious especially because it opens doors to shut the system down from a restricted environment. So the patch makes sesne to me.

Quoted 6 lines

I am wondering whether SLAB_PANIC makes sense in general though. Why is it any different from any other essential early allocations? We tend to not care about allocation failures for those on bases that the system must be in a broken state to fail that early already. Do you think it is time to remove SLAB_PANIC altogether?

That would need some investigation into the history of SLAB_PANIC. I will look into it.

Quoted 4 lines
Quoted 2 lines

Thanks.

#3 lore raw
Quoted 8 lines · Shakeel Butt
Quoted 6 lines

I am wondering whether SLAB_PANIC makes sense in general though. Why is it any different from any other essential early allocations? We tend to not care about allocation failures for those on bases that the system must be in a broken state to fail that early already. Do you think it is time to remove SLAB_PANIC altogether?

That would need some investigation into the history of SLAB_PANIC. I will look into it.

I think it still makes sense for things like the vma, filp, dentry caches. If we don't
have those, we can't even execve("/sbin/init") so we shouldn't even bother continuing to boot.

Maybe we should turn off SLAB_PANIC behavior after boot. We don't want a silly driver or filesystem module that's creating slabs to be causing panic()s.

#4 lore raw
In reply to Shakeel Butt
Quoted 8 lines · Shakeel Butt
Quoted 7 lines · Michal Hocko
Quoted 4 lines · Shakeel Butt

Currently for CONFIG_SLUB, if a memcg kmem cache creation is failed and the corresponding root kmem cache has SLAB_PANIC flag, the kernel will be crashed. This is unnecessary as the kernel can handle the creation failures of memcg kmem caches.

Quoted 8 lines
Quoted 3 lines

AFAICS it will handle those by simply not accounting those objects right?

The memcg kmem cache creation is async. The allocation has already been decided not to be accounted on creation trigger. If memcg kmem cache creation is failed, it will fail silently and the next allocation will trigger the creation process again.

Ohh, right I forgot that it will get retried. This would be useful to mention in the changelog as it is not straightforward from reading just the particular function.

Quoted 17 lines
Quoted 10 lines
Quoted 5 lines

Additionally CONFIG_SLAB does not
implement this behavior. So, to keep the behavior consistent between SLAB and SLUB, removing the panic for memcg kmem cache creation failures. The root kmem cache creation failure for SLAB_PANIC correctly panics for both SLAB and SLUB.

I do agree that panicing is really dubious especially because it opens doors to shut the system down from a restricted environment. So the patch makes sesne to me.

Quoted 6 lines

I am wondering whether SLAB_PANIC makes sense in general though. Why is it any different from any other essential early allocations? We tend to not care about allocation failures for those on bases that the system must be in a broken state to fail that early already. Do you think it is time to remove SLAB_PANIC altogether?

Quoted 2 lines

That would need some investigation into the history of SLAB_PANIC. I will look into it.

Well, I strongly suspect this is a relict from the past. I have hard time to believe that the system would get to a usable state if many of those caches would fail to allocate. And as Dave said in his reply it is quite silly to give this weapon to a random driver hands. Everybody just thinks his toy is the most important one...

Signature · 2 lines
Michal Hocko
SUSE Labs
reviewer Acked-by on v1 1/1
#5 lore raw
In reply to Shakeel Butt
Quoted 11 lines · Shakeel Butt

Currently for CONFIG_SLUB, if a memcg kmem cache creation is failed and the corresponding root kmem cache has SLAB_PANIC flag, the kernel will be crashed. This is unnecessary as the kernel can handle the creation failures of memcg kmem caches. Additionally CONFIG_SLAB does not implement this behavior. So, to keep the behavior consistent between SLAB and SLUB, removing the panic for memcg kmem cache creation failures. The root kmem cache creation failure for SLAB_PANIC correctly panics for both SLAB and SLUB.