2019-05-28 22:19:42

by Johannes Weiner

[permalink] [raw]
Subject: Re: [PATCH v5 5/7] mm: rework non-root kmem_cache lifecycle management

On Tue, May 21, 2019 at 01:07:33PM -0700, Roman Gushchin wrote:
> + arr = rcu_dereference(cachep->memcg_params.memcg_caches);
> +
> + /*
> + * Make sure we will access the up-to-date value. The code updating
> + * memcg_caches issues a write barrier to match this (see
> + * memcg_create_kmem_cache()).
> + */
> + memcg_cachep = READ_ONCE(arr->entries[kmemcg_id]);

READ_ONCE() isn't an SMP barrier, it just prevents compiler
muckery. This needs an explicit smp_rmb() to pair with the smp_wmb()
on the other side.

I realize you're only moving this code, but it would be good to fix
that up while you're there.


2019-05-28 22:30:46

by Roman Gushchin

[permalink] [raw]
Subject: Re: [PATCH v5 5/7] mm: rework non-root kmem_cache lifecycle management

On Tue, May 28, 2019 at 06:03:53PM -0400, Johannes Weiner wrote:
> On Tue, May 21, 2019 at 01:07:33PM -0700, Roman Gushchin wrote:
> > + arr = rcu_dereference(cachep->memcg_params.memcg_caches);
> > +
> > + /*
> > + * Make sure we will access the up-to-date value. The code updating
> > + * memcg_caches issues a write barrier to match this (see
> > + * memcg_create_kmem_cache()).
> > + */
> > + memcg_cachep = READ_ONCE(arr->entries[kmemcg_id]);
>
> READ_ONCE() isn't an SMP barrier, it just prevents compiler
> muckery. This needs an explicit smp_rmb() to pair with the smp_wmb()
> on the other side.

I believe rcu_dereference()/rcu_assign_pointer()/... are better replacements.

>
> I realize you're only moving this code, but it would be good to fix
> that up while you're there.

Right. I'll try to fix it with new-ish rcu API in a separate patch
preceding this one.

Thank you for looking into the series!