Re: [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder

From: Daniel Jordan
Date: Thu Jul 18 2019 - 10:25:55 EST


On Thu, Jul 18, 2019 at 11:30:08AM +0800, Herbert Xu wrote:
> On Wed, Jul 17, 2019 at 07:21:36PM -0400, Daniel Jordan wrote:
> >
> > > @@ -388,12 +336,12 @@ void padata_do_serial(struct padata_priv *padata)
> > > pqueue = per_cpu_ptr(pd->pqueue, cpu);
> > >
> > > spin_lock(&pqueue->reorder.lock);
> > > - atomic_inc(&pd->reorder_objects);
> > > list_add_tail(&padata->list, &pqueue->reorder.list);
> > > + atomic_inc(&pd->reorder_objects);
> >
> > Why switch the lines? Seems ok to not do this.
>
> This is crucial because otherwise the memory barrier won't apply
> to the list insertion. With this patch, we are now using the list
> insertion as the indicator, rather than reorder_objects.

Which memory barrier do you mean? I think you're referring to the one that
atomic_inc might provide? If so, the memory model maintainers can correct me
here, but my understanding is that RMW atomic ops that don't return values are
unordered, so switching the lines has no effect.

Besides, the smp_mb__after_atomic is what orders the list insertion with the
trylock of pd->lock.

> > > @@ -538,8 +479,6 @@ static void padata_flush_queues(struct parallel_data *pd)
> > > flush_work(&pqueue->work);
> > > }
> > >
> > > - del_timer_sync(&pd->timer);
> > > -
> >
> > > if (atomic_read(&pd->reorder_objects))
> > > padata_reorder(pd);
> >
> > I think we can do away with reorder_objects entirely by checking pd->cpu's
> > reorder queue here.
>
> As I said this will probably disappear altogether since we can't
> guarantee that padata_reorder will actually do anything if the
> jobs are stuck in async crypto processing.

Ok, makes sense.