Re: [RFC PATCH] jbd2: avoid __GFP_ZERO with SLAB_TYPESAFE_BY_RCU

From: Qian Cai
Date: Wed Feb 09 2022 - 13:52:44 EST


On Wed, Feb 09, 2022 at 07:10:10PM +0100, Jan Kara wrote:
> On Wed 09-02-22 11:57:42, Qian Cai wrote:
> > Since the linux-next commit 120aa5e57479 (mm: Check for
> > SLAB_TYPESAFE_BY_RCU and __GFP_ZERO slab allocation), we will get a
> > boot warning. Avoid it by calling synchronize_rcu() before the zeroing.
> >
> > Signed-off-by: Qian Cai <quic_qiancai@xxxxxxxxxxx>
>
> No, the performance impact of this would be just horrible. Can you
> ellaborate a bit why SLAB_TYPESAFE_BY_RCU + __GFP_ZERO is a problem and why
> synchronize_rcu() would be needed here before the memset() please? I mean
> how is zeroing here any different from the memory just being used?

I'll defer to Paul and other RCU developers for more indepth explanations of
the issue with the combo. The above mentioned commit has a bit information:

Code using a SLAB_TYPESAFE_BY_RCU kmem_cache can have readers accessing
blocks of memory passed to kmem_cache_free(), and those readers might
still be accessing those blocks after kmem_cache_alloc() reallocates
those blocks. These readers are not going to take kindly to that memory
being zeroed along the way. Therefore, add a WARN_ON_ONCE() complaining
about __GFP_ZERO being passed to an allocation from a SLAB_TYPESAFE_BY_RCU
kmem_cache.