srcu: Add detection of boot CPU srcu_data structure's->srcu_cblist
Subsystems (2)
PATCH 1/1 srcu: Add detection of boot CPU srcu_data structure's->srcu_cblist
Before SRCU_SIZE_WAIT_CALL srcu_size_state is reached, the srcu callback only insert to boot-CPU srcu_data structure's->srcu_cblist and other CPU srcu_data structure's->srcu_cblist is always empty. so before SRCU_SIZE_WAIT_CALL is reached, need to correctly check boot-CPU pend cbs in srcu_might_be_idle().
--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/rcu/srcutree.c +5 -2
@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerQuoted 16 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0
kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1105
Quoted 10 lines
kernel/rcu/srcutree.c +5
-2@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
Thanks.
Quoted 6 lines
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Quoted 27 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +5
-2@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);
Quoted 2 lines
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
In the initial stage(SRCU_SIZE_SMALL), there is no srcu_node structures, only initialized per-CPU srcu_data structures, at this time, we only use boot-cpu srcu_data structures's ->srcu_cblist to store srcu callbacks.
if the contention of srcu_struct and srcu_data structure's->lock become busy,
transition to SRCU_SIZE_ALLOC. allocated memory for srcu_node structure at end of the SRCU grace period.
if allocated success, transition to SRCU_SIZE_WAIT_BARRIER, in this state, invoke srcu_barrier() will iterate over all possible CPUs, but we still only use boot-CPU srcu_cblist to store callbacks. the task calling call_srcu() may have access to a new srcu_node structure or may not,
because call_srcu() is protected by SRCU, we may not transition to SRCU_SIZE_WAIT_CALL quickly, need to wait in this state for a SRCU grace period to end.
After transition to SRCU_SIZE_WAIT_CALL, we enqueue srcu callbacks to own srcu_data structures's ->srcu_cblist.
Does my description make my commit more detailed?
Thanks
Zqiang
Quoted 9 lines
Thanks.
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Quoted 19 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;
kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1106
Quoted 10 lines
kernel/rcu/srcutree.c +5
-2check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);
Hi Paul,
For the convert_to_big default configuration(SRCU_SIZING_AUTO), I found that the srcu is in SRCU_SIZE_SMALL state most of the time in the system, I think this change is meaningful.
Thoughts ?
Thanks
Zqiang
Quoted 33 lines
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
In the initial
stage(SRCU_SIZE_SMALL), there is nosrcu_nodestructures, only initialized per-CPUsrcu_datastructures, at this time, we only use boot-cpusrcu_datastructures's ->srcu_cblist to store srcu callbacks.
if the contention ofsrcu_structandsrcu_datastructure's->lock become busy,
transition toSRCU_SIZE_ALLOC. allocated memory forsrcu_nodestructure at end of the SRCU grace period.
if allocated success, transition toSRCU_SIZE_WAIT_BARRIER, in this state, invokesrcu_barrier()will iterate over all possible CPUs, but we still only use boot-CPUsrcu_cblistto store callbacks. the task callingcall_srcu()may have access to a newsrcu_nodestructure or may not,
becausecall_srcu()is protected by SRCU, we may not transition toSRCU_SIZE_WAIT_CALLquickly, need to wait in this state for a SRCU grace period to end.
After transition toSRCU_SIZE_WAIT_CALL, we enqueue srcu callbacks to ownsrcu_datastructures's ->srcu_cblist.Does my description make my commit more detailed?
Thanks
ZqiangThanks.
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Paul E. McKenney
maintainerQuoted 32 lines · On Wed, Nov 23, 2022 at 02:01:50AM +0000, Zhang, Qiang1 wrote:
Quoted 19 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1106
Quoted 10 lines
kernel/rcu/srcutree.c +5
-2check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);Hi Paul,
Quoted 4 lines
For the
convert_to_bigdefaultconfiguration(SRCU_SIZING_AUTO), I found that the srcu is inSRCU_SIZE_SMALLstate most of the time in the system, I think this change is meaningful.Thoughts ?
You are right that this change might make srcu_might_be_idle() return a more accurate value in the common case. As things are now, some other CPU might just now have added a callback, but might not yet have started that new grace period. In that case, we might expedite an SRCU grace period when we would not have otherwise done so. However, this change would also increase contention on the get_boot_cpu_id() CPU's srcu_data structure's ->lock.
So the result of that inaccurate return value is that the first two SRCU grace periods in a burst might be expedited instead of only the first one, and even then only if we hit a very narrow race window.
Besides, this same thing can happen if two CPUs do synchronize_srcu() at the same time after a long-enough pause between grace periods. Both see no callbacks, so both ask for an expedited grace period. So again, the first two grace periods are expedited.
As a result, I am having a very hard time justifying the increased lock contention.
Am I missing something here?
Thanx, Paul
Quoted 37 lines
Thanks
ZqiangQuoted 33 lines
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
In the initial
stage(SRCU_SIZE_SMALL), there is nosrcu_nodestructures, only initialized per-CPUsrcu_datastructures, at this time, we only use boot-cpusrcu_datastructures's ->srcu_cblist to store srcu callbacks.
if the contention ofsrcu_structandsrcu_datastructure's->lock become busy,
transition toSRCU_SIZE_ALLOC. allocated memory forsrcu_nodestructure at end of the SRCU grace period.
if allocated success, transition toSRCU_SIZE_WAIT_BARRIER, in this state, invokesrcu_barrier()will iterate over all possible CPUs, but we still only use boot-CPUsrcu_cblistto store callbacks. the task callingcall_srcu()may have access to a newsrcu_nodestructure or may not,
becausecall_srcu()is protected by SRCU, we may not transition toSRCU_SIZE_WAIT_CALLquickly, need to wait in this state for a SRCU grace period to end.
After transition toSRCU_SIZE_WAIT_CALL, we enqueue srcu callbacks to ownsrcu_datastructures's ->srcu_cblist.Does my description make my commit more detailed?
Thanks
ZqiangThanks.
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Quoted 49 lines · On Wed, Nov 23, 2022 at 02:01:50AM +0000, Zhang, Qiang1 wrote:
Quoted 19 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1106
Quoted 10 lines
kernel/rcu/srcutree.c +5
-2check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);Hi Paul,
For the
convert_to_bigdefaultconfiguration(SRCU_SIZING_AUTO), I found that the srcu is inSRCU_SIZE_SMALLstate most of the time in the system, I think this change is meaningful.Thoughts ?
You are right that this change might make
srcu_might_be_idle()return a more accurate value in the common case. As things are now, some other CPU might just now have added a callback, but might not yet have started that new grace period. In that case, we might expedite an SRCU grace period when we would not have otherwise done so. However, this change would also increase contention on theget_boot_cpu_id()CPU'ssrcu_datastructure's ->lock.So the result of that inaccurate return value is that the first two SRCU grace periods in a burst might be expedited instead of only the first one, and even then only if we hit a very narrow race window.
Quoted 7 lines
Besides, this same thing can happen if two CPUs do
synchronize_srcu()at the same time after a long-enough pause between grace periods. Both see no callbacks, so both ask for an expedited grace period. So again, the first two grace periods are expedited.As a result, I am having a very hard time justifying the increased lock contention.
Thanks reply, I have another question, Is this srcu_data structure's->lock necessary? the rcu_segcblist_pend_cbs() only check *tails[RCU_DONE_TAIL] is empty.
or can use rcu_segcblist_get_seglen(RCU_WAIT_TAIL + RCU_NEXT_READY_TAIL + RCU_NEXT_TAIL) instead of rcu_segcblist_pend_cbs() to avoid locking? (although this is also inaccurate)
Thanks
Zqiang
Quoted 42 lines
Am I missing something here?
Thanx, Paul
Thanks
ZqiangQuoted 33 lines
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
In the initial
stage(SRCU_SIZE_SMALL), there is nosrcu_nodestructures, only initialized per-CPUsrcu_datastructures, at this time, we only use boot-cpusrcu_datastructures's ->srcu_cblist to store srcu callbacks.
if the contention ofsrcu_structandsrcu_datastructure's->lock become busy,
transition toSRCU_SIZE_ALLOC. allocated memory forsrcu_nodestructure at end of the SRCU grace period.
if allocated success, transition toSRCU_SIZE_WAIT_BARRIER, in this state, invokesrcu_barrier()will iterate over all possible CPUs, but we still only use boot-CPUsrcu_cblistto store callbacks. the task callingcall_srcu()may have access to a newsrcu_nodestructure or may not,
becausecall_srcu()is protected by SRCU, we may not transition toSRCU_SIZE_WAIT_CALLquickly, need to wait in this state for a SRCU grace period to end.
After transition toSRCU_SIZE_WAIT_CALL, we enqueue srcu callbacks to ownsrcu_datastructures's ->srcu_cblist.Does my description make my commit more detailed?
Thanks
ZqiangThanks.
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Paul E. McKenney
maintainerQuoted 55 lines · On Thu, Nov 24, 2022 at 01:43:42AM +0000, Zhang, Qiang1 wrote:
Quoted 54 lines · On Wed, Nov 23, 2022 at 02:01:50AM +0000, Zhang, Qiang1 wrote:
Quoted 19 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1106
Quoted 10 lines
kernel/rcu/srcutree.c +5
-2check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);Hi Paul,
For the
convert_to_bigdefaultconfiguration(SRCU_SIZING_AUTO), I found that the srcu is inSRCU_SIZE_SMALLstate most of the time in the system, I think this change is meaningful.Thoughts ?
You are right that this change might make
srcu_might_be_idle()return a more accurate value in the common case. As things are now, some other CPU might just now have added a callback, but might not yet have started that new grace period. In that case, we might expedite an SRCU grace period when we would not have otherwise done so. However, this change would also increase contention on theget_boot_cpu_id()CPU'ssrcu_datastructure's ->lock.So the result of that inaccurate return value is that the first two SRCU grace periods in a burst might be expedited instead of only the first one, and even then only if we hit a very narrow race window.
Besides, this same thing can happen if two CPUs do
synchronize_srcu()at the same time after a long-enough pause between grace periods. Both see no callbacks, so both ask for an expedited grace period. So again, the first two grace periods are expedited.
Quoted 7 lines
Quoted 2 lines
As a result, I am having a very hard time justifying the increased lock contention.
Thanks reply, I have another question, Is this
srcu_datastructure's->lock necessary? thercu_segcblist_pend_cbs()only check *tails[RCU_DONE_TAIL] is empty.
or can usercu_segcblist_get_seglen(RCU_WAIT_TAIL + RCU_NEXT_READY_TAIL + RCU_NEXT_TAIL)instead ofrcu_segcblist_pend_cbs()to avoid locking? (although this is also inaccurate)
That extra "*" means that the lock must be acquired. Otherwise, the pointed-to callback might even be unmapped between the time we fetched the pointer and the time we dereferenced it.
Thanx, Paul.
Quoted 45 lines
Thanks
ZqiangQuoted 42 lines
Am I missing something here?
Thanx, Paul
Thanks
ZqiangQuoted 33 lines
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
In the initial
stage(SRCU_SIZE_SMALL), there is nosrcu_nodestructures, only initialized per-CPUsrcu_datastructures, at this time, we only use boot-cpusrcu_datastructures's ->srcu_cblist to store srcu callbacks.
if the contention ofsrcu_structandsrcu_datastructure's->lock become busy,
transition toSRCU_SIZE_ALLOC. allocated memory forsrcu_nodestructure at end of the SRCU grace period.
if allocated success, transition toSRCU_SIZE_WAIT_BARRIER, in this state, invokesrcu_barrier()will iterate over all possible CPUs, but we still only use boot-CPUsrcu_cblistto store callbacks. the task callingcall_srcu()may have access to a newsrcu_nodestructure or may not,
becausecall_srcu()is protected by SRCU, we may not transition toSRCU_SIZE_WAIT_CALLquickly, need to wait in this state for a SRCU grace period to end.
After transition toSRCU_SIZE_WAIT_CALL, we enqueue srcu callbacks to ownsrcu_datastructures's ->srcu_cblist.Does my description make my commit more detailed?
Thanks
ZqiangThanks.
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Quoted 58 lines · On Thu, Nov 24, 2022 at 01:43:42AM +0000, Zhang, Qiang1 wrote:
Quoted 49 lines · On Wed, Nov 23, 2022 at 02:01:50AM +0000, Zhang, Qiang1 wrote:
Quoted 19 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1106
Quoted 10 lines
kernel/rcu/srcutree.c +5
-2check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);Hi Paul,
For the
convert_to_bigdefaultconfiguration(SRCU_SIZING_AUTO), I found that the srcu is inSRCU_SIZE_SMALLstate most of the time in the system, I think this change is meaningful.Thoughts ?
You are right that this change might make
srcu_might_be_idle()return a more accurate value in the common case. As things are now, some other CPU might just now have added a callback, but might not yet have started that new grace period. In that case, we might expedite an SRCU grace period when we would not have otherwise done so. However, this change would also increase contention on theget_boot_cpu_id()CPU'ssrcu_datastructure's ->lock.So the result of that inaccurate return value is that the first two SRCU grace periods in a burst might be expedited instead of only the first one, and even then only if we hit a very narrow race window.
Quoted 7 lines
Besides, this same thing can happen if two CPUs do
synchronize_srcu()at the same time after a long-enough pause between grace periods. Both see no callbacks, so both ask for an expedited grace period. So again, the first two grace periods are expedited.As a result, I am having a very hard time justifying the increased lock contention.
Quoted 8 lines
Thanks reply, I have another question, Is this
srcu_datastructure's->lock necessary? thercu_segcblist_pend_cbs()only check *tails[RCU_DONE_TAIL] is empty.
or can usercu_segcblist_get_seglen(RCU_WAIT_TAIL + RCU_NEXT_READY_TAIL + RCU_NEXT_TAIL)instead ofrcu_segcblist_pend_cbs()to avoid locking? (although this is also inaccurate)That extra "*" means that the lock must be acquired. Otherwise, the pointed-to callback might even be unmapped between the time we fetched the pointer and the time we dereferenced it.
Thanks for detailed explanation , learn more😊.
Quoted 48 lines
Thanx, Paul.
Thanks
ZqiangQuoted 42 lines
Am I missing something here?
Thanx, Paul
Thanks
ZqiangQuoted 33 lines
While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
In the initial
stage(SRCU_SIZE_SMALL), there is nosrcu_nodestructures, only initialized per-CPUsrcu_datastructures, at this time, we only use boot-cpusrcu_datastructures's ->srcu_cblist to store srcu callbacks.
if the contention ofsrcu_structandsrcu_datastructure's->lock become busy,
transition toSRCU_SIZE_ALLOC. allocated memory forsrcu_nodestructure at end of the SRCU grace period.
if allocated success, transition toSRCU_SIZE_WAIT_BARRIER, in this state, invokesrcu_barrier()will iterate over all possible CPUs, but we still only use boot-CPUsrcu_cblistto store callbacks. the task callingcall_srcu()may have access to a newsrcu_nodestructure or may not,
becausecall_srcu()is protected by SRCU, we may not transition toSRCU_SIZE_WAIT_CALLquickly, need to wait in this state for a SRCU grace period to end.
After transition toSRCU_SIZE_WAIT_CALL, we enqueue srcu callbacks to ownsrcu_datastructures's ->srcu_cblist.Does my description make my commit more detailed?
Thanks
ZqiangThanks.
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1
Quoted 19 lines · Frederic Weisbecker
Quoted 18 lines · Zqiang
Before
SRCU_SIZE_WAIT_CALLsrcu_size_stateis reached, the srcu callback only insert to boot-CPUsrcu_datastructure's->srcu_cblist and other CPUsrcu_datastructure's->srcu_cblist is always empty. so beforeSRCU_SIZE_WAIT_CALLis reached, need to correctly check boot-CPU pend cbs insrcu_might_be_idle().Signed-off-by Zqiang <[email protected]>--- kernel/rcu/srcutree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/rcu/srcutree.c +0
-0@@ -1098,8 +1098,11 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)unsigned long tlast;
Quoted 12 lines
kernel/rcu/srcutree.c static bool srcu_might_be_idle(struct srcu_struct *ssp) · line 1105
Quoted 8 lines
kernel/rcu/srcutree.c +5
-2check_init_srcu_struct (ssp); -/* If the local srcu_data structure has callbacks, not idle. */ - sdp =raw_cpu_ptr (ssp->sda); +/* If the boot CPU or local srcu_data structure has callbacks, not idle. */ +if (smp_load_acquire (&ssp->srcu_size_state) <SRCU_SIZE_WAIT_CALL ) + sdp =per_cpu_ptr (ssp->sda,get_boot_cpu_id ()); +else + sdp =raw_cpu_ptr (ssp->sda);While at it if someone is interested in documenting/commenting on the meaning of all these SRCU_SIZE_* things, it would be much appreciated!
Due to a conflict understanding to the code, once hesitate to jump in. But anyway, just bold to move ahead.
I have send a series "[PATCH 0/3] srcu: shrink the num of srcu_size_state", which opens the discussion. (Have Cced you and Zqiang)
Please have a look.
Thanks,
Pingfan
Quoted 8 lines
Thanks.
Quoted 6 lines
kernel/rcu/srcutree.c +0
-0spin_lock_irqsave_rcu_node (sdp, flags);if (rcu_segcblist_pend_cbs (&sdp->srcu_cblist)) {spin_unlock_irqrestore_rcu_node (sdp, flags);Signature · 1 line
2.25.1