Re: [PATCH RFC v1 1/2] rcu/tree: Add basic support for kfree_rcu batching
From: Paul E. McKenney
Date: Thu Aug 08 2019 - 16:51:38 EST
On Thu, Aug 08, 2019 at 04:13:33PM -0400, Joel Fernandes wrote:
> On Thu, Aug 08, 2019 at 11:11:12AM -0700, Paul E. McKenney wrote:
> > On Thu, Aug 08, 2019 at 07:26:10PM +0900, Byungchul Park wrote:
> > > On Wed, Aug 07, 2019 at 05:45:04AM -0400, Joel Fernandes wrote:
> > > > On Tue, Aug 06, 2019 at 04:56:31PM -0700, Paul E. McKenney wrote:
> > >
> > > [snip]
> > >
> > > > > On Tue, Aug 06, 2019 at 05:20:40PM -0400, Joel Fernandes (Google) wrote:
> > > > > Of course, I am hoping that a later patch uses an array of pointers built
> > > > > at kfree_rcu() time, similar to Rao's patch (with or without kfree_bulk)
> > > > > in order to reduce per-object cache-miss overhead. This would make it
> > > > > easier for callback invocation to keep up with multi-CPU kfree_rcu()
> > > > > floods.
> > > >
> > > > I think Byungchul tried an experiment with array of pointers and wasn't
> > > > immediately able to see a benefit. Perhaps his patch needs a bit more polish
> > > > or another test-case needed to show benefit due to cache-misses, and the perf
> > > > tool could be used to show if cache misses were reduced. For this initial
> > > > pass, we decided to keep it without the array optimization.
> > >
> > > I'm still seeing no improvement with kfree_bulk().
> > >
> > > I've been thinking I could see improvement with kfree_bulk() because:
> > >
> > > 1. As you guys said, the number of cache misses will be reduced.
> > > 2. We can save (N - 1) irq-disable instructions while N kfrees.
> > > 3. As Joel said, saving/restoring CPU status that kfree() does inside
> > > is not required.
> > >
> > > But even with the following patch applied, the result was same as just
> > > batching test. We might need to get kmalloc objects from random
> > > addresses to maximize the result when using kfree_bulk() and this is
> > > even closer to real practical world too.
> > >
> > > And the second and third reasons doesn't seem to work as much as I
> > > expected.
> > >
> > > Do you have any idea? Or what do you think about it?
> >
> > I would not expect kfree_batch() to help all that much unless the
> > pre-grace-period kfree_rcu() code segregated the objects on a per-slab
> > basis.
>
> You mean kfree_bulk() instead of kfree_batch() right? I agree with you, would
> be nice to do per-slab optimization in the future.
Indeed I do mean kfree_bulk()! One of those mornings, I guess...
But again, without the per-slab locality, I doubt that we will see much
improvement from kfree_bulk() over kfree().
> Also, I am thinking that whenever we do per-slab optimization, then the
> kmem_cache_free_bulk() can be optimized further. If all pointers are on the
> same slab, then we can just do virt_to_cache on the first pointer and avoid
> repeated virt_to_cache() calls. That might also give a benefit -- but I could
> be missing something.
A sort might be required to make that work nicely, which would add some
overhead. Probably not that much, though, the increased locality would
have a fighting chance of overcoming the sort's overhead.
> Right now kmem_cache_free_bulk() just looks like a kmem_cache_free() in a
> loop except the small benefit of not disabling/enabling IRQs across each
> __cache_free, and the reduced cache miss benefit of using the array.
C'mon! Show some respect for the awesome power of temporal locality!!! ;-)
Thanx, Paul