slob: introduce __kfree_rcu
PATCH 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 <[email protected]>
---
mm/slob.c +51 -0
@@ -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;