How to usage kfree_rcu:
struct my_struct {
int data;
struct rcu_head rcu;
};
----------------original code:--------------------------
void my_struct_release_rcu(struct rcu_head *rcu)
{
struct my_struct *p;
item = container_of(rcu, struct my_struct, rcu);
kfree(p);
}
void some_fuction()
{
struct my_struct *p;
.....;
call_rcu(&p->rcu, my_struct_release_rcu);
.....;
}
---end---
-----------------after use kfree_rcu:--------------------
/* my_struct_release_rcu() was removed */
void some_fuction()
{
struct my_struct *p;
.....;
kfree_rcu(p, &p->rcu);
.....;
}
---end---
1) unloadable modules:
A) use my_struct_release_rcu():
when we unload this modules, we need call rcu_barrier() to wait
all my_struct_release_rcu() had called.
B) use kfree_rcu():
if all trivial callback are removed and kfree_rcu() are used instead,
we do not need to wait anything. just quick finish unloading.
2) duplicate code:
A) use my_struct_release_rcu():
All trivial callback are very like my_struct_release_rcu(),
all are duplicate code.
B) use kfree_rcu():
all trivial callback are removed, not duplicate code like
my_struct_release_rcu().
3) cache:
A) use my_struct_release_rcu():
my_struct_release_rcu() is called rarely, when my_struct_release_rcu()
is being called, cache missing will occur.
B) use kfree_rcu():
my_struct_release_rcu() is removed, not such cache missing.
4) future:
A) use my_struct_release_rcu():
when new user use rcu, the most callback is trivial callback
like my_struct_release_rcu(). this is the common of using rcu.
so the problems of above are more and more heavy.
B) use kfree_rcu():
fix these problems for ever.
Paul E. McKenney wrote:
uses kfree_rcu() instead of trivial callback, not rcu_barrier()
we done need wait anything if not callback is defined in this module.
--