SLUB: Use GFP_PANIC for early-boot allocations
Subsystems (2)
PATCH 2/2 SLUB: Use GFP_PANIC for early-boot allocations
From: Pekka Enberg <[email protected]>
This patch converts SLUB early-boot code to use GFP_PANIC instead of explicit BUG_ON() calls.
--- mm/slub.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
mm/slub.c +3 -5
@@ -2109,9 +2109,8 @@ static void early_kmem_cache_node_alloc(gfp_t gfpflags, int node)BUG_ON (kmalloc_caches->size <sizeof (struct kmem_cache_node )); - page =new_slab (kmalloc_caches, gfpflags, node); + page =new_slab (kmalloc_caches, gfpflags |GFP_PANIC , node); -BUG_ON (!page);if (page_to_nid (page) != node) {printk (KERN_ERR "SLUB: Unable to allocate memory from " "node %d\n" , node);
@@ -4367,10 +4366,9 @@ static struct kset *slab_kset;*/ static char *create_unique_id (struct kmem_cache *s) { -char *name =kmalloc (ID_STR_LENGTH ,GFP_KERNEL ); -char *p = name; +char *name, *p; -BUG_ON (!name); + p = name =kmalloc (ID_STR_LENGTH ,GFP_KERNEL |GFP_PANIC ); *p++ =':' ;/*
Signature · 1 line
1.5.6.3
[Pekka Enberg - Fri, May 08, 2009 at 06:10:29PM +0300]
| From: Pekka Enberg <[email protected]> | | This patch converts SLUB early-boot code to use GFP_PANIC instead of explicit | BUG_ON() calls. | | Signed-off-by: Pekka Enberg <[email protected]> | --- | mm/slub.c | 8 +++----- | 1 files changed, 3 insertions(+), 5 deletions(-) |
If the idea will be accepted -- I add 3 callsites on x86 area too :)
-- Cyrill
Quoted 2 lines · Pekka Enberg
This patch converts SLUB early-boot code to use
GFP_PANICinstead of explicitBUG_ON()calls.
Yirks this is not only early boot code. create_unique_id may be executed whenever a slab is created.
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg
This patch converts SLUB early-boot code to use
GFP_PANICinstead of explicitBUG_ON()calls.Yirks this is not only early boot code.
create_unique_idmay be executed whenever a slab is created.
Argh. We should do -ENOMEM there then. I'll drop that hunk.
Quoted 10 lines · Pekka Enberg
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg
This patch converts SLUB early-boot code to use
GFP_PANICinstead of explicitBUG_ON()calls.Yirks this is not only early boot code.
create_unique_idmay be executed whenever a slab is created.Argh. We should do
-ENOMEMthere then. I'll drop that hunk.
BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING));
?
Hi Peter,
Quoted 7 lines · Christoph Lameter
Quoted 7 lines
Quoted 7 lines · Pekka Enberg
Quoted 3 lines
This patch converts SLUB early-boot code to use
GFP_PANICinstead of explicitBUG_ON()calls.Yirks this is not only early boot code.
create_unique_idmay be executed whenever a slab is created.
Quoted 1 line · Pekka Enberg
Quoted 1 line
Argh. We should do
-ENOMEMthere then. I'll drop that hunk.
Quoted 1 line · Peter Zijlstra
BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING));
There's no technical reason not to use GFP_PANIC when system_state != STATE_BOOTING so I don't think it's needed. It's just that GFP_PANIC (and BUG_ON) is IMHO too harsh for create_unique_id().
Pekka
Quoted 6 lines · Pekka Enberg
Quoted 1 line · Peter Zijlstra
BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING));There's no technical reason not to use
GFP_PANICwhensystem_state!=STATE_BOOTINGso I don't think it's needed. It's just thatGFP_PANIC(andBUG_ON) is IMHO too harsh forcreate_unique_id().
Shouldn't we handle every allocation failure after booting?
I think it _is_ a bug to panic on allocation failures once we're running.
I'm really not very fond of __GFP_PANIC as it stands, it seems to suggest its OK to ignore allocation failures, which would bring us back to the original UNIX error handling :/
[Peter Zijlstra - Fri, May 08, 2009 at 05:50:58PM +0200]
| On Fri, 2009-05-08 at 18:45 +0300, Pekka Enberg wrote: | | > On Fri, 2009-05-08 at 17:42 +0200, Peter Zijlstra wrote: | > > BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING)); | > | > There's no technical reason not to use GFP_PANIC when system_state != | > STATE_BOOTING so I don't think it's needed. It's just that GFP_PANIC | > (and BUG_ON) is IMHO too harsh for create_unique_id(). | | Shouldn't we handle every allocation failure after booting?
Definitely
| | I think it _is_ a bug to panic on allocation failures once we're | running. |
But Peter I believe there was no suggestion to use GFP_PANIC everywhere to get rid of error handling. But rather to use it in case if kmalloc is followed by BUG_ON.
| | I'm really not very fond of __GFP_PANIC as it stands, it seems to | suggest its OK to ignore allocation failures, which would bring us back | to the original UNIX error handling :/ |
-- Cyrill
Quoted 14 lines · Cyrill Gorcunov
[Peter Zijlstra - Fri, May 08, 2009 at 05:50:58PM +0200]
| On Fri, 2009-05-08 at 18:45 +0300, Pekka Enberg wrote: | | > On Fri, 2009-05-08 at 17:42 +0200, Peter Zijlstra wrote: | > > BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING)); | > | > There's no technical reason not to use GFP_PANIC when system_state != | > STATE_BOOTING so I don't think it's needed. It's just that GFP_PANIC | > (and BUG_ON) is IMHO too harsh for create_unique_id(). | | Shouldn't we handle every allocation failure after booting?Definitely
Quoted 8 lines
| | I think it _is_ a bug to panic on allocation failures once we're | running. |But Peter I believe there was no suggestion to use
GFP_PANICeverywhere to get rid of error handling. But rather to use it in case if kmalloc is followed byBUG_ON.
Well, what I'm saying is that that either is a genuine bug we should fix, or its boot code, which is exactly what my assertion above tests for.
I really believe GFP_PANIC usage outside of system_state == STATE_BOOTING is a bug we should fix. Not create a better syntax for.
What code outside of booting is allowed to bring down the kernel on an allocation failure?
Quoted 6 lines · Peter Zijlstra
Well, what I'm saying is that that either is a genuine bug we should fix, or its boot code, which is exactly what my assertion above tests for.
I really believe
GFP_PANICusage outside ofsystem_state==STATE_BOOTINGis a bug we should fix. Not create a better syntax for.
I agree.
[Peter Zijlstra - Fri, May 08, 2009 at 06:31:07PM +0200]
| On Fri, 2009-05-08 at 20:15 +0400, Cyrill Gorcunov wrote: | > [Peter Zijlstra - Fri, May 08, 2009 at 05:50:58PM +0200] | > | On Fri, 2009-05-08 at 18:45 +0300, Pekka Enberg wrote: | > | | > | > On Fri, 2009-05-08 at 17:42 +0200, Peter Zijlstra wrote: | > | > > BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING)); | > | > | > | > There's no technical reason not to use GFP_PANIC when system_state != | > | > STATE_BOOTING so I don't think it's needed. It's just that GFP_PANIC | > | > (and BUG_ON) is IMHO too harsh for create_unique_id(). | > | | > | Shouldn't we handle every allocation failure after booting? | > | > Definitely | > | > | | > | I think it _is_ a bug to panic on allocation failures once we're | > | running. | > | | > | > But Peter I believe there was no suggestion to use GFP_PANIC everywhere | > to get rid of error handling. But rather to use it in case if kmalloc is | > followed by BUG_ON. | | Well, what I'm saying is that that either is a genuine bug we should | fix, or its boot code, which is exactly what my assertion above tests | for.
Yes, I agree and didn't argue against actually (but most probably I was not precise in words). There is no protection of using it wrong or buggy way (to eliminate error paths but just panic). By adding STATE_BOOTING we seem to protect ourself from such a case but then we better rename it to something like GFP_BOOT_PANIC maybe? Since from plain GFP_PANIC it's not clear, hmm?
| | I really believe GFP_PANIC usage outside of system_state == | STATE_BOOTING is a bug we should fix. Not create a better syntax for. | | What code outside of booting is allowed to bring down the kernel on an | allocation failure? |
-- Cyrill
Quoted 20 lines · Peter Zijlstra
Quoted 19 lines · Cyrill Gorcunov
[Peter Zijlstra - Fri, May 08, 2009 at 05:50:58PM +0200]
| On Fri, 2009-05-08 at 18:45 +0300, Pekka Enberg wrote: | | > On Fri, 2009-05-08 at 17:42 +0200, Peter Zijlstra wrote: | > > BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING)); | > | > There's no technical reason not to use GFP_PANIC when system_state != | > STATE_BOOTING so I don't think it's needed. It's just that GFP_PANIC | > (and BUG_ON) is IMHO too harsh for create_unique_id(). | | Shouldn't we handle every allocation failure after booting?Definitely
| | I think it _is_ a bug to panic on allocation failures once we're | running. |
Quoted 7 lines
Quoted 3 lines
But Peter I believe there was no suggestion to use
GFP_PANICeverywhere to get rid of error handling. But rather to use it in case if kmalloc is followed byBUG_ON.Well, what I'm saying is that that either is a genuine bug we should fix, or its boot code, which is exactly what my assertion above tests for.
This is about boot code - and only about boot code.
This is a really simple thing. Replace existing x86 platform code early boot allocaton patterns of:
x = alloc(GFP_KERNEL, ...); BUG_ON(!x); y = alloc(GFP_KERNEL, ...); BUG_ON(!y);
With:
x = alloc(GFP_KERNEL | __GFP_PANIC, ...); y = alloc(GFP_KERNEL | __GFP_PANIC, ...);
it makes code shorter, smaller and easier to read. Nothing more, nothing less. And yes, i agree that we should disallow this after bootup has finished - but the boot-alloc case Cyrill and me would like to handle via this is still fully valid.
Ingo
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg
This patch converts SLUB early-boot code to use
GFP_PANICinstead of explicitBUG_ON()calls.Yirks this is not only early boot code.
create_unique_idmay be executed whenever a slab is created.
Updated patch here:
Subject: [PATCH 2/2] SLUB: Use GFP_PANIC for early-boot allocations
From: Pekka Enberg <[email protected]>
This patch converts SLUB early-boot code to use GFP_PANIC instead of BUG_ON().
--- mm/slub.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
mm/slub.c +1 -2
@@ -2109,9 +2109,8 @@ static void early_kmem_cache_node_alloc(gfp_t gfpflags, int node)BUG_ON (kmalloc_caches->size <sizeof (struct kmem_cache_node )); - page =new_slab (kmalloc_caches, gfpflags, node); + page =new_slab (kmalloc_caches, gfpflags |GFP_PANIC , node); -BUG_ON (!page);if (page_to_nid (page) != node) {printk (KERN_ERR "SLUB: Unable to allocate memory from " "node %d\n" , node);
Signature · 1 line
1.5.6.3
Ingo Molnar
Acked-byQuoted 9 lines · Pekka Enberg
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg
This patch converts SLUB early-boot code to use
GFP_PANICinstead of explicitBUG_ON()calls.Yirks this is not only early boot code.
create_unique_idmay be executed whenever a slab is created.
Quoted 8 lines
Updated patch here:
Subject: [PATCH 2/2] SLUB: Use
GFP_PANICfor early-boot allocations
From: Pekka Enberg <[email protected]>This patch converts SLUB early-boot code to use
GFP_PANICinstead ofBUG_ON().Signed-off-by Pekka Enberg <[email protected]>
thanks Pekka!
Ingo