Re: [PATCH v5 4/9] percpu-refcount: Introduce percpu_ref_is_in_use()

Bart Van Assche
2018-08-09T14:32:02Z

On Wed, 2018-08-08 at 08:23 -0700, Tejun Heo wrote:
> On Tue, Aug 07, 2018 at 03:51:28PM -0700, Bart Van Assche wrote:
> > Introduce a function that allows to determine whether a per-cpu=
refcount
> > is in use. This function will be used in a later patch to deter=
mine
> > whether or not any block layer requests are being executed.
>=20
> I thought about it a bit and am having a bit of difficulty convincing
> myself this is necessary. Switching a percpu_ref to atomic mode =
isn't
> expensive - it's one spinlock cycle, a rcu wait and one sweep of the
> percpu counters. The most expensive part - the percpu sweep - needs
> to be there even with optimization, the wait doesn't really matter as
> all it'll do is slightly delaying timer based PM operation and can be
> overlayed with the propagation of set_pm_only() anyway.
>=20
> So, how about just doing the simple thing? Switch it to atomic mode
> and check the counter and switch back to percpu mode afterwards. If
> we see any issues with that, we can try to optimize it later but that
> seems unlikely to me.

Hello Tejun,

Switching to atomic mode would require me to add a serialization mechanism
against blk_freeze_queue_start() and blk_mq_unfreeze=
8-queue() since these
functions call percpu_ref_kill() and percpu_ref_reinit(). T=
hat is easy but
requires additional code. I will see whether I can implement an alternative
approach using blk_mq_queue_tag_busy_iter().

Thanks,

Bart.