[<prev] [next>] [day] [month] [year] [list]
Date: Tue, 03 Mar 2009 21:44:25 +0800
From: Lai Jiangshan <laijs@...fujitsu.com>
To: Andrew Morton <akpm@...ux-foundation.org>
CC: Pekka Enberg <penberg@...helsinki.fi>,
Christoph Lameter <cl@...ux-foundation.org>,
Nick Piggin <npiggin@...e.de>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
Manfred Spraul <manfred@...orfullife.com>,
Ingo Molnar <mingo@...e.hu>,
Peter Zijlstra <peterz@...radead.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH -mm 2/6] slob: introduce __kfree_rcu
Introduce __kfree_rcu() for kfree_rcu()
The object pointer is stored in head->func instead of the
function pointer, and these rcu head(which are the same batch)
are queued in a list. When a batch's grace period is completed,
the objects in this batch are freed, and then we proccess the
next batch(if next batch not empty).
Signed-off-by: Lai Jiangshan <laijs@...fujitsu.com>
---
diff --git a/mm/slob.c b/mm/slob.c
index 52bc8a2..e703295 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -618,6 +618,57 @@ unsigned int kmem_cache_size(struct kmem_cache *c)
}
EXPORT_SYMBOL(kmem_cache_size);
+static DEFINE_SPINLOCK(kfree_rcu_lock);
+static struct rcu_head kfree_rcu_head;
+static struct rcu_head *curr_head;
+static struct rcu_head *next_head, **next_tail = &next_head;
+static void kfree_rcu_advance_batch(void);
+
+static void kfree_rcu_batch_callback(struct rcu_head *unused)
+{
+ unsigned long flags;
+ struct rcu_head *list;
+
+ spin_lock_irqsave(&kfree_rcu_lock, flags);
+ list = curr_head;
+ curr_head = NULL;
+ kfree_rcu_advance_batch();
+ spin_unlock_irqrestore(&kfree_rcu_lock, flags);
+
+ while (list) {
+ struct rcu_head *next = list->next;
+ prefetch(next);
+ kfree((void *)(unsigned long)list->func);
+ list = next;
+ }
+}
+
+static void kfree_rcu_advance_batch(void)
+{
+ if (!curr_head && next_head) {
+ curr_head = next_head;
+ next_head = NULL;
+ next_tail = &next_head;
+
+ call_rcu(&kfree_rcu_head, kfree_rcu_batch_callback);
+ }
+}
+
+void __kfree_rcu(const void *obj, struct rcu_head *rcu)
+{
+ unsigned long flags;
+
+ rcu->func = (typeof(rcu->func))(unsigned long)obj;
+ rcu->next = NULL;
+
+ spin_lock_irqsave(&kfree_rcu_lock, flags);
+ *next_tail = rcu;
+ next_tail = &rcu->next;
+ kfree_rcu_advance_batch();
+ spin_unlock_irqrestore(&kfree_rcu_lock, flags);
+}
+EXPORT_SYMBOL(__kfree_rcu);
+
const char *kmem_cache_name(struct kmem_cache *c)
{
return c->name;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists