linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] slab: minor cleanup to kmem_cache_alloc_node
@ 2005-11-21 14:30 Pekka J Enberg
  2005-11-21 15:58 ` Eric Dumazet
  2005-11-21 17:21 ` Christoph Lameter
  0 siblings, 2 replies; 9+ messages in thread
From: Pekka J Enberg @ 2005-11-21 14:30 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, manfred, christoph

This patch gets rid of one if-else statement by moving current node allocation
check at the beginning of kmem_cache_alloc_node().

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 slab.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 7f80ec3..a05bbfe 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2881,7 +2881,7 @@ void *kmem_cache_alloc_node(kmem_cache_t
 	unsigned long save_flags;
 	void *ptr;
 
-	if (nodeid == -1)
+	if (nodeid == -1 || nodeid == numa_node_id())
 		return __cache_alloc(cachep, flags);
 
 	if (unlikely(!cachep->nodelists[nodeid])) {
@@ -2892,10 +2892,7 @@ void *kmem_cache_alloc_node(kmem_cache_t
 
 	cache_alloc_debugcheck_before(cachep, flags);
 	local_irq_save(save_flags);
-	if (nodeid == numa_node_id())
-		ptr = ____cache_alloc(cachep, flags);
-	else
-		ptr = __cache_alloc_node(cachep, flags, nodeid);
+	ptr = __cache_alloc_node(cachep, flags, nodeid);
 	local_irq_restore(save_flags);
 	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
 

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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 14:30 [PATCH] slab: minor cleanup to kmem_cache_alloc_node Pekka J Enberg
@ 2005-11-21 15:58 ` Eric Dumazet
  2005-11-21 16:23   ` Pekka Enberg
  2005-11-21 17:21 ` Christoph Lameter
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2005-11-21 15:58 UTC (permalink / raw)
  To: Pekka J Enberg; +Cc: akpm, linux-kernel, manfred, christoph

Pekka J Enberg a écrit :
> This patch gets rid of one if-else statement by moving current node allocation
> check at the beginning of kmem_cache_alloc_node().
> 

Are you sure this is valid ?
What about preemption ?
The "if (nodeid == numa_node_id())" check was done with IRQ off, and you want 
do do it with IRQ on.

> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
> ---
> 
>  slab.c |    7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/slab.c b/mm/slab.c
> index 7f80ec3..a05bbfe 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -2881,7 +2881,7 @@ void *kmem_cache_alloc_node(kmem_cache_t
>  	unsigned long save_flags;
>  	void *ptr;
>  
> -	if (nodeid == -1)
> +	if (nodeid == -1 || nodeid == numa_node_id())

<Imagine preemption here, and thread migrated to another NUMA node.>

>  		return __cache_alloc(cachep, flags);
>  
>  	if (unlikely(!cachep->nodelists[nodeid])) {
> @@ -2892,10 +2892,7 @@ void *kmem_cache_alloc_node(kmem_cache_t
>  
>  	cache_alloc_debugcheck_before(cachep, flags);
>  	local_irq_save(save_flags);
> -	if (nodeid == numa_node_id())
> -		ptr = ____cache_alloc(cachep, flags);
> -	else
> -		ptr = __cache_alloc_node(cachep, flags, nodeid);
> +	ptr = __cache_alloc_node(cachep, flags, nodeid);
>  	local_irq_restore(save_flags);
>  	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
>  


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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 15:58 ` Eric Dumazet
@ 2005-11-21 16:23   ` Pekka Enberg
  0 siblings, 0 replies; 9+ messages in thread
From: Pekka Enberg @ 2005-11-21 16:23 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: akpm, linux-kernel, manfred, christoph

Hi Eric,

On Mon, 2005-11-21 at 16:58 +0100, Eric Dumazet wrote:
> Are you sure this is valid ?
> What about preemption ?
> The "if (nodeid == numa_node_id())" check was done with IRQ off, and you want 
> do do it with IRQ on.

You're right. Please ignore the patch.

			Pekka


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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 14:30 [PATCH] slab: minor cleanup to kmem_cache_alloc_node Pekka J Enberg
  2005-11-21 15:58 ` Eric Dumazet
@ 2005-11-21 17:21 ` Christoph Lameter
  2005-11-21 18:36   ` Pekka Enberg
  1 sibling, 1 reply; 9+ messages in thread
From: Christoph Lameter @ 2005-11-21 17:21 UTC (permalink / raw)
  To: Pekka J Enberg; +Cc: akpm, linux-kernel, manfred

On Mon, 21 Nov 2005, Pekka J Enberg wrote:

> This patch gets rid of one if-else statement by moving current node allocation
> check at the beginning of kmem_cache_alloc_node().

The problem with this is that the numa_node may change if irqs are still 
active and your patch moves the check for the numa node outside of the 
section where irqs are enabled.

You could move the check for -1 into the section where interrupts are 
disabled.

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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 17:21 ` Christoph Lameter
@ 2005-11-21 18:36   ` Pekka Enberg
  2005-11-21 19:47     ` Christoph Lameter
  0 siblings, 1 reply; 9+ messages in thread
From: Pekka Enberg @ 2005-11-21 18:36 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: akpm, linux-kernel, manfred

On Mon, 2005-11-21 at 09:21 -0800, Christoph Lameter wrote:
> On Mon, 21 Nov 2005, Pekka J Enberg wrote:
> 
> > This patch gets rid of one if-else statement by moving current node allocation
> > check at the beginning of kmem_cache_alloc_node().
> 
> The problem with this is that the numa_node may change if irqs are still 
> active and your patch moves the check for the numa node outside of the 
> section where irqs are enabled.
> 
> You could move the check for -1 into the section where interrupts are 
> disabled.

So we could do something like the following. Unfortunately it does not
seem much of an improvement... Thoughts?

			Pekka

Index: 2.6/mm/slab.c
===================================================================
--- 2.6.orig/mm/slab.c
+++ 2.6/mm/slab.c
@@ -2866,21 +2866,23 @@ void *kmem_cache_alloc_node(kmem_cache_t
 	unsigned long save_flags;
 	void *ptr;
 
-	if (nodeid == -1)
-		return __cache_alloc(cachep, flags);
+	cache_alloc_debugcheck_before(cachep, flags);
+	local_irq_save(save_flags);
+
+	if (nodeid == -1 || nodeid == numa_node_id()) {
+		ptr = ____cache_alloc(cachep, flags);
+		goto out;
+	}
 
 	if (unlikely(!cachep->nodelists[nodeid])) {
 		/* Fall back to __cache_alloc if we run into trouble */
 		printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name);
-		return __cache_alloc(cachep,flags);
+		ptr = ____cache_alloc(cachep,flags);
+		goto out;
 	}
 
-	cache_alloc_debugcheck_before(cachep, flags);
-	local_irq_save(save_flags);
-	if (nodeid == numa_node_id())
-		ptr = ____cache_alloc(cachep, flags);
-	else
-		ptr = __cache_alloc_node(cachep, flags, nodeid);
+	ptr = __cache_alloc_node(cachep, flags, nodeid);
+  out:
 	local_irq_restore(save_flags);
 	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
 



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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 18:36   ` Pekka Enberg
@ 2005-11-21 19:47     ` Christoph Lameter
  2005-11-21 21:07       ` Pekka Enberg
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Lameter @ 2005-11-21 19:47 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: akpm, linux-kernel, manfred

On Mon, 21 Nov 2005, Pekka Enberg wrote:

> On Mon, 2005-11-21 at 09:21 -0800, Christoph Lameter wrote:
> > You could move the check for -1 into the section where interrupts are 
> > disabled.
> So we could do something like the following. Unfortunately it does not
> seem much of an improvement... Thoughts?

Remove the gotos. Something like this. It would be nice if we could remove 
the printk. Hmm....

Index: linux-2.6.15-rc1-mm2/mm/slab.c
===================================================================
--- linux-2.6.15-rc1-mm2.orig/mm/slab.c	2005-11-21 10:51:03.000000000 -0800
+++ linux-2.6.15-rc1-mm2/mm/slab.c	2005-11-21 11:43:31.000000000 -0800
@@ -2890,21 +2890,20 @@ void *kmem_cache_alloc_node(kmem_cache_t
 	unsigned long save_flags;
 	void *ptr;
 
-	if (nodeid == -1)
-		return __cache_alloc(cachep, flags);
+	cache_alloc_debugcheck_before(cachep, flags);
+	local_irq_save(save_flags);
 
-	if (unlikely(!cachep->nodelists[nodeid])) {
+	if (nodeid == -1 || nodeid == numa_node_id())
+		ptr = ____cache_alloc(cachep, flags);
+
+	else if (unlikely(!cachep->nodelists[nodeid])) {
 		/* Fall back to __cache_alloc if we run into trouble */
 		printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name);
-		return __cache_alloc(cachep,flags);
-	}
+		ptr =  ____cache_alloc(cachep,flags);
 
-	cache_alloc_debugcheck_before(cachep, flags);
-	local_irq_save(save_flags);
-	if (nodeid == numa_node_id())
-		ptr = ____cache_alloc(cachep, flags);
-	else
+	} else
 		ptr = __cache_alloc_node(cachep, flags, nodeid);
+
 	local_irq_restore(save_flags);
 	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
 

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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 19:47     ` Christoph Lameter
@ 2005-11-21 21:07       ` Pekka Enberg
  2005-11-21 21:17         ` Christoph Lameter
  0 siblings, 1 reply; 9+ messages in thread
From: Pekka Enberg @ 2005-11-21 21:07 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: akpm, linux-kernel, manfred, Joe Perches

Hi,

On Mon, 2005-11-21 at 11:47 -0800, Christoph Lameter wrote:
> Remove the gotos. Something like this. It would be nice if we could remove 
> the printk. Hmm....

Definite improvement to my patch. I think I like Joe's suggestion 
better, though. (Any mistakes in the following are mine.)

			Pekka

Index: 2.6/mm/slab.c
===================================================================
--- 2.6.orig/mm/slab.c
+++ 2.6/mm/slab.c
@@ -2866,21 +2866,16 @@ void *kmem_cache_alloc_node(kmem_cache_t
 	unsigned long save_flags;
 	void *ptr;
 
-	if (nodeid == -1)
-		return __cache_alloc(cachep, flags);
-
-	if (unlikely(!cachep->nodelists[nodeid])) {
-		/* Fall back to __cache_alloc if we run into trouble */
-		printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name);
-		return __cache_alloc(cachep,flags);
-	}
-
 	cache_alloc_debugcheck_before(cachep, flags);
 	local_irq_save(save_flags);
-	if (nodeid == numa_node_id())
+
+	if (nodeid == -1 || nodeid == numa_node_id())
 		ptr = ____cache_alloc(cachep, flags);
-	else
+	else if (likely(cachep->nodelists[nodeid]))
 		ptr = __cache_alloc_node(cachep, flags, nodeid);
+	else
+		ptr = ____cache_alloc(cachep, flags);
+
 	local_irq_restore(save_flags);
 	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
 



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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 21:07       ` Pekka Enberg
@ 2005-11-21 21:17         ` Christoph Lameter
  2005-11-22  6:57           ` Pekka J Enberg
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Lameter @ 2005-11-21 21:17 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: akpm, linux-kernel, manfred, Joe Perches

On Mon, 21 Nov 2005, Pekka Enberg wrote:

> Hi,
> 
> On Mon, 2005-11-21 at 11:47 -0800, Christoph Lameter wrote:
> > Remove the gotos. Something like this. It would be nice if we could remove 
> > the printk. Hmm....
> 
> Definite improvement to my patch. I think I like Joe's suggestion 
> better, though. (Any mistakes in the following are mine.)

If we drop the printk then this may be even simpler

Signed-off-by: Christoph Lameter <clameter@sgi.com>

Index: linux-2.6.15-rc1-mm2/mm/slab.c
===================================================================
--- linux-2.6.15-rc1-mm2.orig/mm/slab.c	2005-11-21 13:16:07.000000000 -0800
+++ linux-2.6.15-rc1-mm2/mm/slab.c	2005-11-21 13:16:59.000000000 -0800
@@ -2890,21 +2890,14 @@ void *kmem_cache_alloc_node(kmem_cache_t
 	unsigned long save_flags;
 	void *ptr;
 
-	if (nodeid == -1)
-		return __cache_alloc(cachep, flags);
-
-	if (unlikely(!cachep->nodelists[nodeid])) {
-		/* Fall back to __cache_alloc if we run into trouble */
-		printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name);
-		return __cache_alloc(cachep,flags);
-	}
-
 	cache_alloc_debugcheck_before(cachep, flags);
 	local_irq_save(save_flags);
-	if (nodeid == numa_node_id())
+
+	if (nodeid == -1 || nodeid == numa_node_id() || !cachep->nodelists[nodeid])
 		ptr = ____cache_alloc(cachep, flags);
 	else
 		ptr = __cache_alloc_node(cachep, flags, nodeid);
+
 	local_irq_restore(save_flags);
 	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
 

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

* Re: [PATCH] slab: minor cleanup to kmem_cache_alloc_node
  2005-11-21 21:17         ` Christoph Lameter
@ 2005-11-22  6:57           ` Pekka J Enberg
  0 siblings, 0 replies; 9+ messages in thread
From: Pekka J Enberg @ 2005-11-22  6:57 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: akpm, linux-kernel, manfred, Joe Perches

On Mon, 21 Nov 2005, Christoph Lameter wrote:
> If we drop the printk then this may be even simpler
> 
> Signed-off-by: Christoph Lameter <clameter@sgi.com>

Even better. Thanks!

Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>

> Index: linux-2.6.15-rc1-mm2/mm/slab.c
> ===================================================================
> --- linux-2.6.15-rc1-mm2.orig/mm/slab.c	2005-11-21 13:16:07.000000000 -0800
> +++ linux-2.6.15-rc1-mm2/mm/slab.c	2005-11-21 13:16:59.000000000 -0800
> @@ -2890,21 +2890,14 @@ void *kmem_cache_alloc_node(kmem_cache_t
>  	unsigned long save_flags;
>  	void *ptr;
>  
> -	if (nodeid == -1)
> -		return __cache_alloc(cachep, flags);
> -
> -	if (unlikely(!cachep->nodelists[nodeid])) {
> -		/* Fall back to __cache_alloc if we run into trouble */
> -		printk(KERN_WARNING "slab: not allocating in inactive node %d for cache %s\n", nodeid, cachep->name);
> -		return __cache_alloc(cachep,flags);
> -	}
> -
>  	cache_alloc_debugcheck_before(cachep, flags);
>  	local_irq_save(save_flags);
> -	if (nodeid == numa_node_id())
> +
> +	if (nodeid == -1 || nodeid == numa_node_id() || !cachep->nodelists[nodeid])
>  		ptr = ____cache_alloc(cachep, flags);
>  	else
>  		ptr = __cache_alloc_node(cachep, flags, nodeid);
> +
>  	local_irq_restore(save_flags);
>  	ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, __builtin_return_address(0));
>  
> 

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

end of thread, other threads:[~2005-11-22  6:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-21 14:30 [PATCH] slab: minor cleanup to kmem_cache_alloc_node Pekka J Enberg
2005-11-21 15:58 ` Eric Dumazet
2005-11-21 16:23   ` Pekka Enberg
2005-11-21 17:21 ` Christoph Lameter
2005-11-21 18:36   ` Pekka Enberg
2005-11-21 19:47     ` Christoph Lameter
2005-11-21 21:07       ` Pekka Enberg
2005-11-21 21:17         ` Christoph Lameter
2005-11-22  6:57           ` Pekka J Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).