percpu-refcount: Use normal instead of RCU-sched"
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 8 Nov 2019 17:35:53 +0000 (18:35 +0100)
committerDennis Zhou <dennis@kernel.org>
Sun, 17 Nov 2019 04:02:47 +0000 (20:02 -0800)
commit9e8d42a0f7eb9056f8bdb241b91738b5a2923f4c
tree4b66d1a9f0885001b0156eabe7f7ee101221ea99
parent825dbc6ff7a3a063ea91be7d94af940080b0c991
percpu-refcount: Use normal instead of RCU-sched"

This is a revert of commit
   a4244454df129 ("percpu-refcount: use RCU-sched insted of normal RCU")

which claims the only reason for using RCU-sched is
   "rcu_read_[un]lock() … are slightly more expensive than preempt_disable/enable()"

and
    "As the RCU critical sections are extremely short, using sched-RCU
    shouldn't have any latency implications."

The problem with using RCU-sched here is that it disables preemption and
the release callback (called from percpu_ref_put_many()) must not
acquire any sleeping locks like spinlock_t. This breaks PREEMPT_RT
because some of the users acquire spinlock_t locks in their callbacks.

Using rcu_read_lock() on PREEMPTION=n kernels is not any different
compared to rcu_read_lock_sched(). On PREEMPTION=y kernels there are
already performance issues due to additional preemption points.
Looking at the code, the rcu_read_lock() is just an increment and unlock
is almost just a decrement unless there is something special to do. Both
are functions while disabling preemption is inlined.
Doing a small benchmark, the minimal amount of time required was mostly
the same. The average time required was higher due to the higher MAX
value (which could be preemption). With DEBUG_PREEMPT=y it is
rcu_read_lock_sched() that takes a little longer due to the additional
debug code.

Convert back to normal RCU.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
include/linux/percpu-refcount.h