Skip to content

Commit 8db70b1

Browse files
patrickmarlierpaulmck
authored andcommitted
rculist: Make list_entry_rcu() use lockless_dereference()
The current list_entry_rcu() implementation copies the pointer to a stack variable, then invokes rcu_dereference_raw() on it. This results in an additional store-load pair. Now, most compilers will emit normal store and load instructions, which might seem to be of negligible overhead, but this results in a load-hit-store situation that can cause surprisingly long pipeline stalls, even on modern microprocessors. The problem is that it takes time for the store to get the store buffer updated, which can delay the subsequent load, which immediately follows. This commit therefore switches to the lockless_dereference() primitive, which does not expect the __rcu annotations (that are anyway not present in the list_head structure) and which, like rcu_dereference_raw(), does not check for an enclosing RCU read-side critical section. Most importantly, it does not copy the pointer, thus avoiding the load-hit-store overhead. Signed-off-by: Patrick Marlier <patrick.marlier@gmail.com> [ paulmck: Switched to lockless_dereference() to suppress sparse warnings. ] Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
1 parent c3ac7cf commit 8db70b1

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

include/linux/rculist.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ static inline void list_splice_init_rcu(struct list_head *list,
247247
* primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
248248
*/
249249
#define list_entry_rcu(ptr, type, member) \
250-
({ \
251-
typeof(*ptr) __rcu *__ptr = (typeof(*ptr) __rcu __force *)ptr; \
252-
container_of((typeof(ptr))rcu_dereference_raw(__ptr), type, member); \
253-
})
250+
container_of(lockless_dereference(ptr), type, member)
254251

255252
/**
256253
* Where are list_empty_rcu() and list_first_entry_rcu()?

0 commit comments

Comments
 (0)