srcu: Use rcu_seq_done_exact() for polling API
Subsystems (2)
Joel Fernandes
maintainerPATCH v2 1/1 srcu: Use rcu_seq_done_exact() for polling API
poll_state_synchronize_srcu() uses rcu_seq_done() unlike poll_state_synchronize_rcu() which uses rcu_seq_done_exact().
The rcu_seq_done_exact() makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if the gp_seq counter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.
Fix by using the more accurate rcu_seq_done_exact() API which is exactly what straight RCU's polling does.
It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and poll_state() calls and yell if significant time has past but the grace period has still not progressed.
---v1->v2: Resend with Neeraj review tag. Rebased on rcu/dev.
kernel/rcu/srcutree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +1 -1
@@ -1589,7 +1589,7 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);bool poll_state_synchronize_srcu (struct srcu_struct *ssp,unsigned long cookie) {if (cookie !=SRCU_GET_STATE_COMPLETED && - !rcu_seq_done (&ssp->srcu_sup->srcu_gp_seq, cookie)) + !rcu_seq_done_exact (&ssp->srcu_sup->srcu_gp_seq, cookie))return false;// Ensure that the end of the SRCU grace period happens before // any subsequent code that the caller might execute.
Signature · 1 line
2.34.1
Quoted 13 lines · Joel Fernandes
poll_state_synchronize_srcu()usesrcu_seq_done()unlikepoll_state_synchronize_rcu()which usesrcu_seq_done_exact().The
rcu_seq_done_exact()makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if thegp_seqcounter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.Fix by using the more accurate
rcu_seq_done_exact()API which is exactly what straight RCU's polling does.
Quoted 7 lines
It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and
poll_state()calls and yell if significant time has past but the grace period has still not progressed.Reviewed-by Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes <[email protected]>
But we should also run this by Kent Overstreet, given that bcachefs uses this. Should be OK, given that bcachefs uses this API in the same way that it does poll_state_synchronize_rcu(), but still...
Thanx, Paul
Quoted 22 lines
---
v1->v2: Resend with Neeraj review tag. Rebased on rcu/dev.kernel/rcu/srcutree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/rcu/srcutree.c +1
-1@@ -1589,7 +1589,7 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);bool poll_state_synchronize_srcu (struct srcu_struct *ssp,unsigned long cookie) {if (cookie !=SRCU_GET_STATE_COMPLETED && - !rcu_seq_done (&ssp->srcu_sup->srcu_gp_seq, cookie)) + !rcu_seq_done_exact (&ssp->srcu_sup->srcu_gp_seq, cookie))return false;// Ensure that the end of the SRCU grace period happens before // any subsequent code that the caller might execute. Signature · 1 line
2.34.1
Joel Fernandes
maintainerQuoted 19 lines · Paul E. McKenney
Quoted 18 lines · Joel Fernandes
poll_state_synchronize_srcu()usesrcu_seq_done()unlikepoll_state_synchronize_rcu()which usesrcu_seq_done_exact().The
rcu_seq_done_exact()makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if thegp_seqcounter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.Fix by using the more accurate
rcu_seq_done_exact()API which is exactly what straight RCU's polling does.It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and
poll_state()calls and yell if significant time has past but the grace period has still not progressed.
Quoted 8 lines
Quoted 2 lines
Reviewed-by Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes <[email protected]>Reviewed-by Paul E. McKenney <[email protected]>But we should also run this by Kent Overstreet, given that bcachefs uses this. Should be OK, given that bcachefs uses this API in the same way that it does
poll_state_synchronize_rcu(), but still...
Thanks Paul! Adding Kent Overstreet to the email to raise any objections.
thanks,
- Joel
Quoted 25 lines
Thanx, Paul
Quoted 22 lines
---
v1->v2: Resend with Neeraj review tag. Rebased on rcu/dev.kernel/rcu/srcutree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/rcu/srcutree.c +1
-1@@ -1589,7 +1589,7 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);bool poll_state_synchronize_srcu (struct srcu_struct *ssp,unsigned long cookie) {if (cookie !=SRCU_GET_STATE_COMPLETED && - !rcu_seq_done (&ssp->srcu_sup->srcu_gp_seq, cookie)) + !rcu_seq_done_exact (&ssp->srcu_sup->srcu_gp_seq, cookie))return false;// Ensure that the end of the SRCU grace period happens before // any subsequent code that the caller might execute. Signature · 1 line
2.34.1
Quoted 25 lines · Joel Fernandes
Quoted 22 lines · Paul E. McKenney
Quoted 20 lines · Joel Fernandes
poll_state_synchronize_srcu()usesrcu_seq_done()unlikepoll_state_synchronize_rcu()which usesrcu_seq_done_exact().The
rcu_seq_done_exact()makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if thegp_seqcounter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.Fix by using the more accurate
rcu_seq_done_exact()API which is exactly what straight RCU's polling does.It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and
poll_state()calls and yell if significant time has past but the grace period has still not progressed.Reviewed-by Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes <[email protected]>
Quoted 7 lines
Quoted 5 lines
Reviewed-by Paul E. McKenney <[email protected]>But we should also run this by Kent Overstreet, given that bcachefs uses this. Should be OK, given that bcachefs uses this API in the same way that it does
poll_state_synchronize_rcu(), but still...Thanks Paul! Adding Kent Overstreet to the email to raise any objections.
It sounds like rcu_done_exact() is indeed what we want - bcachefs uses this for determining when objects may be reclaimed (as is typical with rcu), so we don't want objects to be stranded a "significant time past the grace period".
Is there any additional cost? I'm not seeing rcu_done_exact() in Linus's tree yet. Minor additional overhead would be totally fine; we use this from fs/bcachefs/rcu_pending.c which doesn't call it for each object.
Joel Fernandes
maintainerQuoted 32 lines · Kent Overstreet
Quoted 31 lines · Joel Fernandes
Quoted 27 lines · Paul E. McKenney
Quoted 13 lines · Joel Fernandes
poll_state_synchronize_srcu()usesrcu_seq_done()unlikepoll_state_synchronize_rcu()which usesrcu_seq_done_exact().The
rcu_seq_done_exact()makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if thegp_seqcounter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.Fix by using the more accurate
rcu_seq_done_exact()API which is exactly what straight RCU's polling does.Quoted 7 lines
It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and
poll_state()calls and yell if significant time has past but the grace period has still not progressed.Reviewed-by Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes <[email protected]>Reviewed-by Paul E. McKenney <[email protected]>But we should also run this by Kent Overstreet, given that bcachefs uses this. Should be OK, given that bcachefs uses this API in the same way that it does
poll_state_synchronize_rcu(), but still...
Quoted 6 lines
Quoted 1 line
Thanks Paul! Adding Kent Overstreet to the email to raise any objections.
It sounds like
rcu_done_exact()is indeed what we want - bcachefs uses this for determining when objects may be reclaimed (as is typical with rcu), so we don't want objects to be stranded a "significant time past the grace period".
Thanks for confirming. May I add your Reviewed-by tag as well?
Quoted 4 lines
Is there any additional cost? I'm not seeing
rcu_done_exact()in Linus's tree yet. Minor additional overhead would be totally fine; we use this fromfs/bcachefs/rcu_pending.cwhich doesn't call it for each object.
The additional overhead should be minimal. rcu_seq_done_exact() is the function.
thanks,
-Joel
Kent Overstreet
Reviewed-byQuoted 35 lines · Joel Fernandes
Quoted 32 lines · Kent Overstreet
Quoted 31 lines · Joel Fernandes
Quoted 27 lines · Paul E. McKenney
Quoted 13 lines · Joel Fernandes
poll_state_synchronize_srcu()usesrcu_seq_done()unlikepoll_state_synchronize_rcu()which usesrcu_seq_done_exact().The
rcu_seq_done_exact()makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if thegp_seqcounter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.Fix by using the more accurate
rcu_seq_done_exact()API which is exactly what straight RCU's polling does.Quoted 7 lines
It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and
poll_state()calls and yell if significant time has past but the grace period has still not progressed.Reviewed-by Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes <[email protected]>Reviewed-by Paul E. McKenney <[email protected]>But we should also run this by Kent Overstreet, given that bcachefs uses this. Should be OK, given that bcachefs uses this API in the same way that it does
poll_state_synchronize_rcu(), but still...
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Thanks Paul! Adding Kent Overstreet to the email to raise any objections.
It sounds like
rcu_done_exact()is indeed what we want - bcachefs uses this for determining when objects may be reclaimed (as is typical with rcu), so we don't want objects to be stranded a "significant time past the grace period".Thanks for confirming. May I add your Reviewed-by tag as well?
Quoted 13 lines · Joel Fernandes
poll_state_synchronize_srcu()usesrcu_seq_done()unlikepoll_state_synchronize_rcu()which usesrcu_seq_done_exact().The
rcu_seq_done_exact()makes more sense for polling API, as with this API, there is a higher chance that there is a significant delay between the get_state..() and poll_state..() calls since a cookie can be stored and reused at a later time. During such a delay, if thegp_seqcounter progresses more than ULONG_MAX/2 distance, then poll_state..() may return false for a long time unwantedly.Fix by using the more accurate
rcu_seq_done_exact()API which is exactly what straight RCU's polling does.
Quoted 7 lines
It may make sense, as future work, to add debug code here as well, where we compare a physical timestamp between get_state..() and
poll_state()calls and yell if significant time has past but the grace period has still not progressed.Reviewed-by Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes <[email protected]>
Queued for further tests and reviews, thank you all.
Regards,
Boqun
Quoted 23 lines
---
v1->v2: Resend with Neeraj review tag. Rebased on rcu/dev.kernel/rcu/srcutree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/rcu/srcutree.c +1
-1@@ -1589,7 +1589,7 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);bool poll_state_synchronize_srcu (struct srcu_struct *ssp,unsigned long cookie) {if (cookie !=SRCU_GET_STATE_COMPLETED && - !rcu_seq_done (&ssp->srcu_sup->srcu_gp_seq, cookie)) + !rcu_seq_done_exact (&ssp->srcu_sup->srcu_gp_seq, cookie))return false;// Ensure that the end of the SRCU grace period happens before // any subsequent code that the caller might execute. Signature · 1 line
2.34.1