public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Paul Jackson <pj@sgi.com>
Cc: Andrew Morton <akpm@osdl.org>,
	clameter@engr.sgi.com, steiner@sgi.com, dgc@sgi.com,
	Simon.Derr@bull.net, ak@suse.de, linux-kernel@vger.kernel.org,
	manfred@colorfullife.com
Subject: Re: [PATCH 2/5] cpuset memory spread page cache implementation and hooks
Date: Mon, 06 Feb 2006 19:32:13 +0200	[thread overview]
Message-ID: <1139247134.11803.3.camel@localhost> (raw)
In-Reply-To: <Pine.LNX.4.58.0602060948560.21447@sbz-30.cs.Helsinki.FI>

Hi,

On Mon, 6 Feb 2006, Pekka J Enberg wrote:
> > Actually, the above patch isn't probably any good as it moves 
> > cache_alloc_cpucache() out-of-line which should be the common case for 
> > NUMA too (it's hurting kmem_cache_alloc and kmalloc). The following should 
> > be better.

Paul, as requested, here's one on top of your cpuset changes. This one
preserves kernel text size for both UMA and NUMA so it's code
restructuring only. The optimizations you did in the cpuset patches
already make the NUMA fastpath so small that I wasn't able to improve it
on i386.

			Pekka

Subject: slab: alloc path consolidation
From: Pekka Enberg <penberg@cs.helsinki.fi>

This patch consolidates the UMA and NUMA memory allocation paths in the
slab allocator. This is accomplished by making the UMA-path look like
we are on NUMA but always allocating from the current node. The patch has
no functional changes, only code restructuring.

Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Christoph Lameter <christoph@lameter.com>
Cc: Paul Jackson <pj@sgi.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 mm/slab.c |   98 ++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 54 insertions(+), 44 deletions(-)

Index: 2.6-cpuset/mm/slab.c
===================================================================
--- 2.6-cpuset.orig/mm/slab.c
+++ 2.6-cpuset/mm/slab.c
@@ -830,7 +830,6 @@ static struct array_cache *alloc_arrayca
 
 #ifdef CONFIG_NUMA
 static void *__cache_alloc_node(struct kmem_cache *, gfp_t, int);
-static void *alternate_node_alloc(struct kmem_cache *, gfp_t);
 
 static struct array_cache **alloc_alien_cache(int node, int limit)
 {
@@ -2667,17 +2666,11 @@ static void *cache_alloc_debugcheck_afte
 #define cache_alloc_debugcheck_after(a,b,objp,d) (objp)
 #endif
 
-static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags)
+static inline void *cache_alloc_cpu_cache(struct kmem_cache *cachep, gfp_t flags)
 {
 	void *objp;
 	struct array_cache *ac;
 
-#ifdef CONFIG_NUMA
-	if (unlikely(current->flags & (PF_MEM_SPREAD|PF_MEMPOLICY)))
-		if ((objp = alternate_node_alloc(cachep, flags)) != NULL)
-			return objp;
-#endif
-
 	check_irq_off();
 	ac = cpu_cache_get(cachep);
 	if (likely(ac->avail)) {
@@ -2691,23 +2684,6 @@ static inline void *____cache_alloc(stru
 	return objp;
 }
 
-static __always_inline void *
-__cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller)
-{
-	unsigned long save_flags;
-	void *objp;
-
-	cache_alloc_debugcheck_before(cachep, flags);
-
-	local_irq_save(save_flags);
-	objp = ____cache_alloc(cachep, flags);
-	local_irq_restore(save_flags);
-	objp = cache_alloc_debugcheck_after(cachep, flags, objp,
-					    caller);
-	prefetchw(objp);
-	return objp;
-}
-
 #ifdef CONFIG_NUMA
 /*
  * Try allocating on another node if PF_MEM_SPREAD or PF_MEMPOLICY.
@@ -2788,8 +2764,58 @@ static void *__cache_alloc_node(struct k
       done:
 	return obj;
 }
+
+static __always_inline void *__cache_alloc(struct kmem_cache *cachep,
+					   gfp_t flags, int nodeid)
+{
+	void *objp;
+
+	if (nodeid == -1 || nodeid == numa_node_id() ||
+	    !cachep->nodelists[nodeid]) {
+		if (unlikely(current->flags & (PF_MEM_SPREAD|PF_MEMPOLICY))) {
+			objp = alternate_node_alloc(cachep, flags);
+			if (objp)
+				goto out;
+		}
+		objp = cache_alloc_cpu_cache(cachep, flags);
+	} else
+		objp = __cache_alloc_node(cachep, flags, nodeid);
+  out:
+	return objp;
+}
+
+#else
+
+static __always_inline void *__cache_alloc(struct kmem_cache *cachep,
+					   gfp_t flags, int nodeid)
+{
+	return cache_alloc_cpu_cache(cachep, flags);
+}
+
 #endif
 
+static __always_inline void *cache_alloc(struct kmem_cache *cache,
+					 gfp_t flags, int nodeid, void *caller)
+{
+	unsigned long save_flags;
+	void *obj;
+
+	cache_alloc_debugcheck_before(cache, flags);
+	local_irq_save(save_flags);
+	obj = __cache_alloc(cache, flags, nodeid);
+	local_irq_restore(save_flags);
+	obj = cache_alloc_debugcheck_after(cache, flags, obj, caller);
+	return obj;
+}
+
+static __always_inline void *
+cache_alloc_current(struct kmem_cache *cache, gfp_t flags, void *caller)
+{
+	void *obj = cache_alloc(cache, flags, -1, caller);
+	prefetchw(obj);
+	return obj;
+}
+
 /*
  * Caller needs to acquire correct kmem_list's list_lock
  */
@@ -2951,7 +2977,7 @@ static inline void __cache_free(struct k
  */
 void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
 {
-	return __cache_alloc(cachep, flags, __builtin_return_address(0));
+	return cache_alloc_current(cachep, flags, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(kmem_cache_alloc);
 
@@ -3012,23 +3038,7 @@ int fastcall kmem_ptr_validate(struct km
  */
 void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid)
 {
-	unsigned long save_flags;
-	void *ptr;
-
-	cache_alloc_debugcheck_before(cachep, flags);
-	local_irq_save(save_flags);
-
-	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));
-
-	return ptr;
+	return cache_alloc(cachep, flags, nodeid, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(kmem_cache_alloc_node);
 
@@ -3078,7 +3088,7 @@ static __always_inline void *__do_kmallo
 	cachep = __find_general_cachep(size, flags);
 	if (unlikely(cachep == NULL))
 		return NULL;
-	return __cache_alloc(cachep, flags, caller);
+	return cache_alloc_current(cachep, flags, caller);
 }
 
 #ifndef CONFIG_DEBUG_SLAB



  reply	other threads:[~2006-02-06 17:32 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-04  7:19 [PATCH 1/5] cpuset memory spread basic implementation Paul Jackson
2006-02-04  7:19 ` [PATCH 2/5] cpuset memory spread page cache implementation and hooks Paul Jackson
2006-02-04 23:49   ` Andrew Morton
2006-02-05  1:42     ` Paul Jackson
2006-02-05  1:54       ` Andrew Morton
2006-02-05  3:28         ` Christoph Lameter
2006-02-05  5:06           ` Andrew Morton
2006-02-05  6:08             ` Paul Jackson
2006-02-05  6:15               ` Andrew Morton
2006-02-05  6:28                 ` Paul Jackson
2006-02-06  0:20                 ` Paul Jackson
2006-02-06  5:51                 ` Paul Jackson
2006-02-06  7:14                   ` Pekka J Enberg
2006-02-06  7:42                     ` Pekka J Enberg
2006-02-06  7:51                       ` Pekka J Enberg
2006-02-06 17:32                         ` Pekka Enberg [this message]
2006-02-04  7:19 ` [PATCH 3/5] cpuset memory spread slab cache implementation Paul Jackson
2006-02-04 23:49   ` Andrew Morton
2006-02-05  3:37     ` Christoph Lameter
2006-02-04  7:19 ` [PATCH 4/5] cpuset memory spread slab cache optimizations Paul Jackson
2006-02-04 23:50   ` Andrew Morton
2006-02-05  3:18     ` Paul Jackson
2006-02-04 23:50   ` Andrew Morton
2006-02-05  4:10     ` Paul Jackson
2006-02-04  7:19 ` [PATCH 5/5] cpuset memory spread slab cache hooks Paul Jackson
2006-02-06  4:37   ` Andrew Morton
2006-02-04 23:49 ` [PATCH 1/5] cpuset memory spread basic implementation Andrew Morton
2006-02-05  3:35   ` Christoph Lameter
2006-02-06  4:33   ` Andrew Morton
2006-02-06  5:50     ` Paul Jackson
2006-02-06  6:02       ` Andrew Morton
2006-02-06  6:17         ` Ingo Molnar
2006-02-06  7:22           ` Paul Jackson
2006-02-06  7:43             ` Ingo Molnar
2006-02-06  8:19               ` Paul Jackson
2006-02-06  8:22                 ` Ingo Molnar
2006-02-06  8:40                   ` Ingo Molnar
2006-02-06  9:03                     ` Paul Jackson
2006-02-06  9:09                       ` Ingo Molnar
2006-02-06  9:27                         ` Paul Jackson
2006-02-06  9:37                           ` Ingo Molnar
2006-02-06 20:22                     ` Paul Jackson
2006-02-06  8:47                   ` Paul Jackson
2006-02-06  8:51                     ` Ingo Molnar
2006-02-06  9:09                       ` Paul Jackson
2006-02-06 10:09                   ` Andi Kleen
2006-02-06 10:11                     ` Ingo Molnar
2006-02-06 10:16                       ` Andi Kleen
2006-02-06 10:23                         ` Ingo Molnar
2006-02-06 10:35                           ` Andi Kleen
2006-02-06 14:42                           ` Paul Jackson
2006-02-06 14:35                         ` Paul Jackson
2006-02-06 16:48                           ` Christoph Lameter
2006-02-06 17:11                             ` Andi Kleen
2006-02-06 18:21                               ` Christoph Lameter
2006-02-06 18:36                                 ` Andi Kleen
2006-02-06 18:43                                   ` Christoph Lameter
2006-02-06 18:48                                     ` Andi Kleen
2006-02-06 19:19                                       ` Christoph Lameter
2006-02-06 20:27                                       ` Paul Jackson
2006-02-06 18:43                                   ` Ingo Molnar
2006-02-06 20:01                                     ` Paul Jackson
2006-02-06 20:05                                       ` Ingo Molnar
2006-02-06 20:27                                         ` Christoph Lameter
2006-02-06 20:41                                           ` Ingo Molnar
2006-02-06 20:49                                             ` Christoph Lameter
2006-02-06 21:07                                               ` Ingo Molnar
2006-02-06 22:10                                                 ` Christoph Lameter
2006-02-06 23:29                                                   ` Ingo Molnar
2006-02-06 23:45                                         ` Paul Jackson
2006-02-07  0:19                                           ` Ingo Molnar
2006-02-07  1:17                                             ` David Chinner
2006-02-07  9:31                                             ` Andi Kleen
2006-02-07 11:53                                               ` Ingo Molnar
2006-02-07 12:14                                                 ` Andi Kleen
2006-02-07 12:30                                                   ` Ingo Molnar
2006-02-07 12:43                                                     ` Andi Kleen
2006-02-07 12:58                                                       ` Ingo Molnar
2006-02-07 13:14                                                         ` Andi Kleen
2006-02-07 14:11                                                           ` Ingo Molnar
2006-02-07 14:23                                                             ` Andi Kleen
2006-02-07 17:11                                                               ` Christoph Lameter
2006-02-07 17:29                                                                 ` Andi Kleen
2006-02-07 17:39                                                                   ` Christoph Lameter
2006-02-07 17:10                                                       ` Christoph Lameter
2006-02-07 17:28                                                         ` Andi Kleen
2006-02-07 17:42                                                           ` Christoph Lameter
2006-02-07 17:51                                                             ` Andi Kleen
2006-02-07 17:06                                                     ` Christoph Lameter
2006-02-07 17:26                                                       ` Andi Kleen
2006-02-04 23:50 ` Andrew Morton
2006-02-04 23:57   ` David S. Miller
2006-02-06  4:37 ` Andrew Morton
2006-02-06  6:02   ` Ingo Molnar
2006-02-06  6:56   ` Paul Jackson
2006-02-06  7:08     ` Andrew Morton
2006-02-06  7:39       ` Ingo Molnar
2006-02-06  8:22         ` Paul Jackson
2006-02-06  8:35         ` Paul Jackson
2006-02-06  9:32       ` Paul Jackson
2006-02-06  9:57         ` Andrew Morton
2006-02-06  9:18 ` Simon Derr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1139247134.11803.3.camel@localhost \
    --to=penberg@cs.helsinki.fi \
    --cc=Simon.Derr@bull.net \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=clameter@engr.sgi.com \
    --cc=dgc@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=pj@sgi.com \
    --cc=steiner@sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox