Re: [PATCH 04/10] workqueue: Move nr_active handling into helpers

From: Tejun Heo
Date: Tue Dec 26 2023 - 15:07:26 EST


On Tue, Dec 26, 2023 at 05:12:55PM +0800, Lai Jiangshan wrote:
> On Wed, Dec 20, 2023 at 3:25 PM Tejun Heo <tj@xxxxxxxxxx> wrote:
>
> > +static bool pwq_tryinc_nr_active(struct pool_workqueue *pwq)
> > {
> > - struct work_struct *work = list_first_entry(&pwq->inactive_works,
> > - struct work_struct, entry);
> > + struct workqueue_struct *wq = pwq->wq;
> > + struct worker_pool *pool = pwq->pool;
> > + bool obtained;
> >
> > - pwq_activate_work(pwq, work);
> > + lockdep_assert_held(&pool->lock);
> > +
> > + obtained = pwq->nr_active < wq->max_active;
>
> It is better to use READ_ONCE(wq->max_active) here in case
> the compiler issues code to calculate "obtained" multi-time.
>
> Theoretically, READ_ONCE(wq->max_active) is recommended
> from the patch1 in pwq_dec_nr_in_flight() and __queue_work()
> since there is no wq->mutex for them.

Yeah, good point. Lemme add WRITE/READ_ONCE() around max_active accesses.

Thanks.

--
tejun