Skip to contentSkip to conversation

SLUB: Use GFP_PANIC for early-boot allocations

PATCH In review Pekka Enberg 5 participants 14 messages May 8, 2009 – May 9, 2009

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

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
index 7ab54ec..55216b4 100644
@@ -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
#1 lore raw

[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

#2 lore raw
In reply to Pekka Enberg
Quoted 2 lines · Pekka Enberg

This patch converts SLUB early-boot code to use GFP_PANIC instead of explicit BUG_ON() calls.

Yirks this is not only early boot code. create_unique_id may be executed whenever a slab is created.

#3 lore raw
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg

This patch converts SLUB early-boot code to use GFP_PANIC instead of explicit BUG_ON() calls.

Yirks this is not only early boot code. create_unique_id may be executed whenever a slab is created.

Argh. We should do -ENOMEM there then. I'll drop that hunk.

#4 lore raw
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_PANIC instead of explicit BUG_ON() calls.

Yirks this is not only early boot code. create_unique_id may be executed whenever a slab is created.

Argh. We should do -ENOMEM there then. I'll drop that hunk.

BUG_ON((gfp & __GFP_PANIC) && (system_state != STATE_BOOTING));

?

#5 lore raw

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_PANIC instead of explicit BUG_ON() calls.

Yirks this is not only early boot code. create_unique_id may be executed whenever a slab is created.

Quoted 1 line · Pekka Enberg
Quoted 1 line

Argh. We should do -ENOMEM there 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

#6 lore raw
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_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?

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 :/

#7 lore raw

[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

#8 lore raw
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_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.

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?

#9 lore raw
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_PANIC usage outside of system_state == STATE_BOOTING is a bug we should fix. Not create a better syntax for.

I agree.

#10 lore raw
In reply to Peter Zijlstra

[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

#11 lore raw
In reply to Peter Zijlstra
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_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.

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

#12 lore raw
In reply to Christoph Lameter
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg

This patch converts SLUB early-boot code to use GFP_PANIC instead of explicit BUG_ON() calls.

Yirks this is not only early boot code. create_unique_id may 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
index 7ab54ec..2cdf731 100644
@@ -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
Acked-by
#13 lore raw
Quoted 9 lines · Pekka Enberg
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Pekka Enberg

This patch converts SLUB early-boot code to use GFP_PANIC instead of explicit BUG_ON() calls.

Yirks this is not only early boot code. create_unique_id may be executed whenever a slab is created.

Quoted 8 lines

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().

thanks Pekka!

Ingo