Skip to content

Commit 6705083

Browse files
joelagnelfbq
authored andcommitted
srcu: Improve comments about acceleration leak
The comments added in commit 1ef990c ("srcu: No need to advance/accelerate if no callback enqueued") are a bit confusing. The comments are describing a scenario for code that was moved and is no longer the way it was (snapshot after advancing). Improve the code comments to reflect this and also document why acceleration can never fail. Cc: Frederic Weisbecker <frederic@kernel.org> Cc: Neeraj Upadhyay <neeraj.iitr10@gmail.com> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org> Reviewed-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 7f66f09 commit 6705083

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

kernel/rcu/srcutree.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,
12341234
if (rhp)
12351235
rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
12361236
/*
1237-
* The snapshot for acceleration must be taken _before_ the read of the
1238-
* current gp sequence used for advancing, otherwise advancing may fail
1239-
* and acceleration may then fail too.
1237+
* It's crucial to capture the snapshot 's' for acceleration before
1238+
* reading the current gp_seq that is used for advancing. This is
1239+
* essential because if the acceleration snapshot is taken after a
1240+
* failed advancement attempt, there's a risk that a grace period may
1241+
* conclude and a new one may start in the interim. If the snapshot is
1242+
* captured after this sequence of events, the acceleration snapshot 's'
1243+
* could be excessively advanced, leading to acceleration failure.
1244+
* In such a scenario, an 'acceleration leak' can occur, where new
1245+
* callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment.
1246+
* Also note that encountering advancing failures is a normal
1247+
* occurrence when the grace period for RCU_WAIT_TAIL is in progress.
12401248
*
1241-
* This could happen if:
1249+
* To see this, consider the following events which occur if
1250+
* rcu_seq_snap() were to be called after advance:
12421251
*
12431252
* 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the
12441253
* RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8).
@@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,
12641273
if (rhp) {
12651274
rcu_segcblist_advance(&sdp->srcu_cblist,
12661275
rcu_seq_current(&ssp->srcu_sup->srcu_gp_seq));
1276+
/*
1277+
* Acceleration can never fail because the base current gp_seq
1278+
* used for acceleration is <= the value of gp_seq used for
1279+
* advancing. This means that RCU_NEXT_TAIL segment will
1280+
* always be able to be emptied by the acceleration into the
1281+
* RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL segments.
1282+
*/
12671283
WARN_ON_ONCE(!rcu_segcblist_accelerate(&sdp->srcu_cblist, s));
12681284
}
12691285
if (ULONG_CMP_LT(sdp->srcu_gp_seq_needed, s)) {

0 commit comments

Comments
 (0)