All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
	Christoph Lameter <cl@linux-foundation.org>,
	Nick Piggin <npiggin@suse.de>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Manfred Spraul <manfred@colorfullife.com>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH -mm 2/6] slob: introduce __kfree_rcu
Date: Tue, 03 Mar 2009 21:44:25 +0800	[thread overview]
Message-ID: <49AD3439.4000602@cn.fujitsu.com> (raw)


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;








                 reply	other threads:[~2009-03-03 13:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=49AD3439.4000602@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=mingo@elte.hu \
    --cc=npiggin@suse.de \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penberg@cs.helsinki.fi \
    --cc=peterz@infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.