Re: [PATCH] percpu-refcount: relax limit on percpu_ref_reinit()

From: Tejun Heo
Date: Tue Sep 11 2018 - 09:48:42 EST


Hello, Ming.

On Tue, Sep 11, 2018 at 08:00:50AM +0800, Ming Lei wrote:
> > > @@ -357,10 +349,11 @@ EXPORT_SYMBOL_GPL(percpu_ref_kill_and_confirm);
> > > void percpu_ref_reinit(struct percpu_ref *ref)
> > > {
> > > unsigned long flags;
> > > + unsigned long __percpu *percpu_count;
> > >
> > > spin_lock_irqsave(&percpu_ref_switch_lock, flags);
> > >
> > > - WARN_ON_ONCE(!percpu_ref_is_zero(ref));
> > > + WARN_ON_ONCE(__ref_is_percpu(ref, &percpu_count));
> >
> > Can you elaborate this part? This doesn't seem required for the
> > described change. Why is it part of the patch?
>
> The motivation of this patch is to avoid the above warning and allow
> the ref to switch back to percpu mode without dropping to zero.
>
> That is why the check has to be changed to the above way.

So, this part seems wrong. The function is called percpu_ref_reinit()
- the refcnt is expected to be in its initial state with just the base
ref once this function returns. If you're removing the restriction on
when this can be called, you should also make sure that the function
actually enforces the target state. Also, this is a separate logical
change, please put it in a separate patch.

Thanks.

--
tejun