Sleeping in RCU list traversal
Hi
Quoted 13 lines
Something like this?
rcu_read_lock();list_for_each_rcu(p, ...){
ptr =list_entry(p, struct ..., list);
/* Grab a reference to "ptr". */
rcu_read_unlock();
my_task_that_may_sleep(ptr);
rcu_read_lock();
/* Drop a reference to "ptr". */
}rcu_read_unlock();
Quoted 2 lines
Regarding my case, memory region pointed by "ptr" never be removed. Do I need to grab a reference to "ptr" ?
In Document/RCU/whatisRCU.txt
Note that the value returned by rcu_dereference() is valid
only within the enclosing RCU read-side critical section.
For example, the following is -not- legal:
rcu_read_lock();
p = rcu_dereference(head.next);
rcu_read_unlock();
x = p->address;
rcu_read_lock();
y = p->data;
rcu_read_unlock();
Holding a reference from one RCU read-side critical section
to another is just as illegal as holding a reference from
one lock-based critical section to another! Similarly,
using a reference outside of the critical section in which
it was acquired is just as illegal as doing so with normal
locking.
Jun WangHello.
Thank you for pointing out.
Quoted 11 lines · Jun WANG
Quoted 10 lines
rcu_read_lock();list_for_each_rcu(p, ...){
ptr =list_entry(p, struct ..., list);
/* Grab a reference to "ptr". */
rcu_read_unlock();
my_task_that_may_sleep(ptr);
rcu_read_lock();
/* Drop a reference to "ptr". */
}rcu_read_unlock();
Quoted 3 lines
In
Document/RCU/whatisRCU.txt
Note that the value returned byrcu_dereference()is valid
only within the enclosing RCU read-side critical section.
Excuse me, but I think "p" is used only between rcu_read_lock() and rcu_read_unlock(). Is it illegal to use "ptr" after rcu_read_unlock() if "ptr" is obtained before rcu_read_unlock() ?
Regards.
Quoted 19 lines
Hello.
Thank you for pointing out.
Quoted 13 lines · Jun WANG
Quoted 12 lines
rcu_read_lock();list_for_each_rcu(p, ...){
ptr =list_entry(p, struct ..., list);
/* Grab a reference to "ptr". */
rcu_read_unlock();
my_task_that_may_sleep(ptr);
rcu_read_lock();
/* Drop a reference to "ptr". */
}rcu_read_unlock();
Regarding my case, memory region pointed by "ptr" never be removed. Do I need to grab a reference to "ptr" ?
Quoted 8 lines
Quoted 3 lines
In
Document/RCU/whatisRCU.txt
Note that the value returned byrcu_dereference()is valid
only within the enclosing RCU read-side critical section.Excuse me, but I think "p" is used only between
rcu_read_lock()andrcu_read_unlock(). Is it illegal to use "ptr" afterrcu_read_unlock()if "ptr" is obtained beforercu_read_unlock()?Regards.
I'm sorry,I think I got your idea, if you do not need ptr in my_task_that_may_sleep(), why you need to grab a reference to "ptr". If your my_task_that_may_sleep() needs ptr, and according to the
Quoted 1 line
"memory region pointed by "ptr" never be removed." you say,
it is ok to use "ptr" after rcu_read_ulock(). The basic idea behind RCU is to split updates into "removal" and "reclamation" phases. If you memory region pointed by "ptr" will not "reclamation" in sleep, it is ok
Regards.
Hello.
Quoted 7 lines · Jun WANG
I'm sorry,I think I got your idea, if you do not need ptr in
my_task_that_may_sleep(), why you need to grab a reference to "ptr". If yourmy_task_that_may_sleep()needs ptr, and according to the "memory region pointed by "ptr" never be removed." you say, it is ok to use "ptr" afterrcu_read_ulock(). The basic idea behind RCU is to split updates into "removal" and "reclamation" phases. If you memory region pointed by "ptr" will not "reclamation" in sleep, it is ok
I need "ptr" in my_task_that_may_sleep(), but regarding my case, memory region pointed by "ptr" will never be kfree()ed.
So, I don't need to grab a reference to "ptr"
because memory region pointed by "ptr" will never be kfree()ed. And it is legal to use "ptr" after rcu_read_unlock() because memory region pointed by "ptr" will never be kfree()ed.
Thank you.
Quoted 4 lines · Tetsuo Handa
So, I don't need to grab a reference to "ptr"
because memory region pointed by "ptr" will never be kfree()ed. And it is legal to use "ptr" afterrcu_read_unlock()because memory region pointed by "ptr" will never be kfree()ed.
Still think that is a very BAD (tm) idea. Esp since with the help of RCU there is hardly any performance loss of not doing proper deletes.
Hello.
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines
So, I don't need to grab a reference to "ptr"
because memory region pointed by "ptr" will never be kfree()ed. And it is legal to use "ptr" afterrcu_read_unlock()because memory region pointed by "ptr" will never be kfree()ed.Still think that is a very BAD (tm) idea. Esp since with the help of RCU there is hardly any performance loss of not doing proper deletes.
Elements I keep in RCU list are policy table for access control that are referred throughout the lifetime of the kernel.
So, there is hardly any needs to delete these elements. Honestly speaking, I don't need to use RCU list at all.
Just using a singly linked list that doesn't support deletion is enough. But James Morris advises me to use the existing API
( http://lkml.org/lkml/2007/10/2/156 http://lkml.org/lkml/2007/10/3/124 ).
Thank you.