Skip to content

Commit 1c77e86

Browse files
committed
srcu: Document srcu_flip() memory-barrier D relation to SRCU-fast
The smp_mb() memory barrier at the end of srcu_flip() has a comment, but that comment does not make it clear that this memory barrier is an optimization, as opposed to being needed for correctness. This commit therefore adds this information and points out that it is omitted for SRCU-fast, where a much heavier weight synchronize_srcu() would be required. Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: <bpf@vger.kernel.org>
1 parent be97544 commit 1c77e86

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

kernel/rcu/srcutree.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,16 @@ static void srcu_flip(struct srcu_struct *ssp)
11681168
* counter update. Note that both this memory barrier and the
11691169
* one in srcu_readers_active_idx_check() provide the guarantee
11701170
* for __srcu_read_lock().
1171+
*
1172+
* Note that this is a performance optimization, in which we spend
1173+
* an otherwise unnecessary smp_mb() in order to reduce the number
1174+
* of full per-CPU-variable scans in srcu_readers_lock_idx() and
1175+
* srcu_readers_unlock_idx(). But this performance optimization
1176+
* is not so optimal for SRCU-fast, where we would be spending
1177+
* not smp_mb(), but rather synchronize_rcu(). At the same time,
1178+
* the overhead of the smp_mb() is in the noise, so there is no
1179+
* point in omitting it in the SRCU-fast case. So the same code
1180+
* is executed either way.
11711181
*/
11721182
smp_mb(); /* D */ /* Pairs with C. */
11731183
}

0 commit comments

Comments
 (0)