public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm] slqb: cleanup for concatenating kmlist
@ 2009-03-03 13:27 Lai Jiangshan
  0 siblings, 0 replies; only message in thread
From: Lai Jiangshan @ 2009-03-03 13:27 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Nick Piggin, Andrew Morton, linux-kernel


move duplicate code into a inline functions.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/mm/slqb.c b/mm/slqb.c
index 07bf5b3..48bdf3b 100644
--- a/mm/slqb.c
+++ b/mm/slqb.c
@@ -307,6 +307,23 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
 	*(void **)(object + s->offset) = fp;
 }
 
+static inline void __kmlist_concat(struct kmem_cache *s, struct kmlist *dest,
+		void **head, void **tail, int nr)
+{
+	if (!dest->head)
+		dest->head = head;
+	else
+		set_freepointer(s, dest->tail, head);
+	dest->tail = tail;
+	dest->nr += nr;
+}
+
+static inline void kmlist_concat(struct kmem_cache *s, struct kmlist *dest,
+		struct kmlist *src)
+{
+	__kmlist_concat(s, dest, src->head, src->tail, src->nr);
+}
+
 /* Loop over all objects in a slab */
 #define for_each_object(__p, __s, __addr) \
 	for (__p = (__addr); __p < (__addr) + (__s)->objects * (__s)->size;\
@@ -1152,8 +1169,7 @@ static void flush_free_list_all(struct kmem_cache *s, struct kmem_cache_list *l)
 static void claim_remote_free_list(struct kmem_cache *s,
 					struct kmem_cache_list *l)
 {
-	void **head, **tail;
-	int nr;
+	struct kmlist tmp_list;
 
 	if (!l->remote_free.list.nr)
 		return;
@@ -1161,29 +1177,20 @@ static void claim_remote_free_list(struct kmem_cache *s,
 	spin_lock(&l->remote_free.lock);
 
 	l->remote_free_check = 0;
-	head = l->remote_free.list.head;
+	tmp_list = l->remote_free.list;
+
 	l->remote_free.list.head = NULL;
-	tail = l->remote_free.list.tail;
 	l->remote_free.list.tail = NULL;
-	nr = l->remote_free.list.nr;
 	l->remote_free.list.nr = 0;
 
 	spin_unlock(&l->remote_free.lock);
 
-	VM_BUG_ON(!nr);
-
-	if (!l->freelist.nr) {
-		/* Get head hot for likely subsequent allocation or flush */
-		prefetchw(head);
-		l->freelist.head = head;
-	} else
-		set_freepointer(s, l->freelist.tail, head);
-	l->freelist.tail = tail;
+	VM_BUG_ON(!tmp_list.nr);
 
-	l->freelist.nr += nr;
+	kmlist_concat(s, &l->freelist, &tmp_list);
 
 	slqb_stat_inc(l, CLAIM_REMOTE_LIST);
-	slqb_stat_add(l, CLAIM_REMOTE_LIST_OBJECTS, nr);
+	slqb_stat_add(l, CLAIM_REMOTE_LIST_OBJECTS, tmp_list.nr);
 }
 #endif
 
@@ -1549,22 +1556,16 @@ static void flush_remote_free_cache(struct kmem_cache *s,
 
 	spin_lock(&dst->remote_free.lock);
 
-	if (!dst->remote_free.list.head)
-		dst->remote_free.list.head = src->head;
-	else
-		set_freepointer(s, dst->remote_free.list.tail, src->head);
-	dst->remote_free.list.tail = src->tail;
-
-	src->head = NULL;
-	src->tail = NULL;
-	src->nr = 0;
-
 	if (dst->remote_free.list.nr < slab_freebatch(s))
 		set = 1;
 	else
 		set = 0;
 
-	dst->remote_free.list.nr += nr;
+	kmlist_concat(s, &dst->remote_free.list, src);
+
+	src->head = NULL;
+	src->tail = NULL;
+	src->nr = 0;
 
 	if (unlikely(dst->remote_free.list.nr >= slab_freebatch(s) && set))
 		dst->remote_free_check = 1;
@@ -1593,13 +1594,8 @@ static noinline void slab_free_to_remote(struct kmem_cache *s,
 	}
 
 	r = &c->rlist;
-	if (!r->head)
-		r->head = object;
-	else
-		set_freepointer(s, r->tail, object);
 	set_freepointer(s, object, NULL);
-	r->tail = object;
-	r->nr++;
+	__kmlist_concat(s, r, object, object, 1);
 
 	if (unlikely(r->nr > slab_freebatch(s)))
 		flush_remote_free_cache(s, c);



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-03 13:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-03 13:27 [PATCH -mm] slqb: cleanup for concatenating kmlist Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox