Re: [PATCH] mm, swap: Remove unnecessary smp_rmb() in swap_type_to_swap_info()
From: Daniel Jordan
Date: Fri May 14 2021 - 16:50:26 EST
On Fri, May 14, 2021 at 12:02:05PM +0800, Huang, Ying wrote:
> Daniel Jordan <daniel.m.jordan@xxxxxxxxxx> writes:
> > 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?
>
> In addition to p->type, *p is zeroed via kvzalloc().
So it is, good point.
> > 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.
>
> We usually check the state of swap_info_struct before other operations.
> For example, we check si->swap_map in swap_start().
Yes, we usually do.
> > 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?
>
> I think we have initialized all fields before publication :-).
Probably all the ones that matter in practice, yes :-)
Still feeling slightly uneasy about the theoretical p->lock, but that
was possible before this change too so it's out of scope.
A comment explaining the pairing and that we care mostly about the zero
init would be nice.