Message ID | 1680161497-19817-1-git-send-email-ziwei.dai@unisoc.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | rcu: Make sure new krcp free business is handled after the wanted rcu grace period. | expand |
On Thu, Mar 30, 2023 at 03:31:37PM +0800, Ziwei Dai wrote: > From: 代子为 (Ziwei Dai) <ziwei.dai@ziwei-lenovo.spreadtrum.com> > > In kfree_rcu_monitor(), new free business at krcp is attached to any free > channel at krwp. kfree_rcu_monitor() is responsible to make sure new free > business is handled after the rcu grace period. But if there is any none-free > channel at krwp already, that means there is an on-going rcu work, > which will cause the kvfree_call_rcu()-triggered free business is done > before the wanted rcu grace period ends. > Right. There have to be a "Fixes:" tag. > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index 8e880c0..4fe3c53 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -3107,15 +3107,16 @@ static void kfree_rcu_monitor(struct work_struct *work) > for (i = 0; i < KFREE_N_BATCHES; i++) { > struct kfree_rcu_cpu_work *krwp = &(krcp->krw_arr[i]); > > - // Try to detach bulk_head or head and attach it over any > - // available corresponding free channel. It can be that > - // a previous RCU batch is in progress, it means that > - // immediately to queue another one is not possible so > - // in that case the monitor work is rearmed. > - if ((!list_empty(&krcp->bulk_head[0]) && list_empty(&krwp->bulk_head_free[0])) || > - (!list_empty(&krcp->bulk_head[1]) && list_empty(&krwp->bulk_head_free[1])) || > - (READ_ONCE(krcp->head) && !krwp->head_free)) { > - > + // Try to detach bulk_head or head and attach it, only when > + // all channels are free. Any channel is not free means at krwp > + // there is on-going rcu work to handle krwp's free business. > + if (!list_empty(&krwp->bulk_head_free[0]) || > + !list_empty(&krwp->bulk_head_free[1]) || > + !krwp->head_free) > + continue; > + if (!list_empty(&krcp->bulk_head[0]) || > + !list_empty(&krcp->bulk_head[1]) || > + READ_ONCE(krcp->head)) { > // Channel 1 corresponds to the SLAB-pointer bulk path. > // Channel 2 corresponds to vmalloc-pointer bulk path. > for (j = 0; j < FREE_N_CHANNELS; j++) { > -- > 1.9.1 > Give me some time to have a look at your change closer. It seems it can trigger a rcu_work even though krcp is empty. But it is from a first glance. Thanks! -- Uladzislau Rezki
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 8e880c0..4fe3c53 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3107,15 +3107,16 @@ static void kfree_rcu_monitor(struct work_struct *work) for (i = 0; i < KFREE_N_BATCHES; i++) { struct kfree_rcu_cpu_work *krwp = &(krcp->krw_arr[i]); - // Try to detach bulk_head or head and attach it over any - // available corresponding free channel. It can be that - // a previous RCU batch is in progress, it means that - // immediately to queue another one is not possible so - // in that case the monitor work is rearmed. - if ((!list_empty(&krcp->bulk_head[0]) && list_empty(&krwp->bulk_head_free[0])) || - (!list_empty(&krcp->bulk_head[1]) && list_empty(&krwp->bulk_head_free[1])) || - (READ_ONCE(krcp->head) && !krwp->head_free)) { - + // Try to detach bulk_head or head and attach it, only when + // all channels are free. Any channel is not free means at krwp + // there is on-going rcu work to handle krwp's free business. + if (!list_empty(&krwp->bulk_head_free[0]) || + !list_empty(&krwp->bulk_head_free[1]) || + !krwp->head_free) + continue; + if (!list_empty(&krcp->bulk_head[0]) || + !list_empty(&krcp->bulk_head[1]) || + READ_ONCE(krcp->head)) { // Channel 1 corresponds to the SLAB-pointer bulk path. // Channel 2 corresponds to vmalloc-pointer bulk path. for (j = 0; j < FREE_N_CHANNELS; j++) {