Re: [PATCH] mm, swap: Remove unnecessary smp_rmb() in swap_type_to_swap_info()
From: Daniel Jordan
Date: Fri May 14 2021 - 16:52:19 EST
On Fri, May 14, 2021 at 02:04:14PM +0200, Peter Zijlstra wrote:
> On Thu, May 13, 2021 at 09:59:46PM -0400, Daniel Jordan wrote:
> > Yes, this does help, I didn't understand why smp_wmb stayed around in
> > the original post.
> >
> > I think the only access smp_store_release() orders is p->type. Wouldn't
> > it be kinda inconsistent to only initialize that one field before
> > publishing when many others would be done at the end of
> > alloc_swap_info() after the fact? p->type doesn't seem special. For
> > instance, get_swap_page_of_type() touches si->lock soon after it calls
> > swap_type_to_swap_info(), so there could be a small window where there's
> > a non-NULL si with an uninitialized lock.
> >
> > It's not as if this is likely to be a problem in practice, it would just
> > make it harder to understand why smp_store_release is there. Maybe all
> > we need is a WRITE_ONCE, or if it's really necessary for certain fields
> > to be set before publication then move them up and explain?
>
> You also care about the zero fill from kvzalloc(). Without the
> smp_store_release() the zero-fill from the memset() might only be
> visible 'late'.
Aha, yes, didn't consider that!
> Unless that also isn't a problem?
No, you're right, we need that for p->flags at least.