Skip to contentSkip to conversation

slqb: introduce __kfree_rcu

PATCH In review Lai Jiangshan 3 participants 3 messages Mar 3, 2009 – Mar 23, 2009 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 5/6 slqb: introduce __kfree_rcu

Introduce __kfree_rcu() for kfree_rcu()

It like __kfree_rcu() in slab.c, slub.c
We can calculate the object poiter from a poiter inside this object in slqb.c, so we can use it for rcu callback and free the object.

---

mm/slqb.c +17 -0
index 48bdf3b..c258ddc 100644
@@ -2482,6 +2484,23 @@ void kfree(const void *object)
 }
 EXPORT_SYMBOL(kfree);
 
+static void kfree_rcu_callback(struct rcu_head *rcu)
+{
+	void *portion = rcu;
+	struct slqb_page *page = virt_to_head_slqb_page(portion);
+	struct kmem_cache *s = page->list->cache;
+	unsigned int index = (portion - page->s_mem) / s->size;
+	void *object = page->s_mem + s->size * index;
+
+	slab_free(s, page, object);
+}
+
+void __kfree_rcu(const void *objp, struct rcu_head *rcu)
+{
+	call_rcu(rcu, kfree_rcu_callback);
+}
+EXPORT_SYMBOL(__kfree_rcu);
+
 static void kmem_cache_trim_percpu(void *arg)
 {
 	int cpu = smp_processor_id();
#1 lore raw
Quoted 6 lines · Lai Jiangshan

Introduce __kfree_rcu() for kfree_rcu()

It like __kfree_rcu() in slab.c, slub.c
We can calculate the object poiter from a poiter inside this object in slqb.c, so we can use it for rcu callback and free the object.

s/poiter/pointer

(that typo is in other patches too.)

Ingo

#2 lore raw
In reply to Lai Jiangshan
Quoted 14 lines · Lai Jiangshan

Introduce __kfree_rcu() for kfree_rcu()

It like __kfree_rcu() in slab.c, slub.c
We can calculate the object poiter from a poiter inside this object in slqb.c, so we can use it for rcu callback and free the object.

---

mm/slqb.c +0 -0
index 48bdf3b..c258ddc 100644

mm/slqb.c void kfree(const void *object) · line 2493

Quoted 10 lines
mm/slqb.c +7 -0
@@ -2482,6 +2484,23 @@ void kfree(const void *object)
 }
 EXPORT_SYMBOL(kfree);
 
+static void kfree_rcu_callback(struct rcu_head *rcu)
+{
+	void *portion = rcu;
+	struct slqb_page *page = virt_to_head_slqb_page(portion);
+	struct kmem_cache *s = page->list->cache;
+	unsigned int index = (portion - page->s_mem) / s->size;
+	void *object = page->s_mem + s->size * index;

Basically the same nit as with the other patches as well: please separate variable declarations from the initializations for readability.

Quoted 18 lines
mm/slqb.c +10 -0
+
+	slab_free(s, page, object);
+}
+
+void __kfree_rcu(const void *objp, struct rcu_head *rcu)
+{
+	call_rcu(rcu, kfree_rcu_callback);
+}
+EXPORT_SYMBOL(__kfree_rcu);
+
 static void kmem_cache_trim_percpu(void *arg)
 {
 	int cpu = smp_processor_id();