public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm 2/6] slob: introduce __kfree_rcu
@ 2009-03-03 13:44 Lai Jiangshan
  0 siblings, 0 replies; only message in thread
From: Lai Jiangshan @ 2009-03-03 13:44 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Pekka Enberg, Christoph Lameter, Nick Piggin, Paul E. McKenney,
	Manfred Spraul, Ingo Molnar, Peter Zijlstra, linux-kernel


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@cn.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;








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

only message in thread, other threads:[~2009-03-03 13:46 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:44 [PATCH -mm 2/6] slob: introduce __kfree_rcu Lai Jiangshan

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