Re: [PATCH] mm: slab: optimize memcg_slab_free_hook()

From: Muchun Song
Date: Tue Apr 26 2022 - 06:02:47 EST


On Mon, Apr 25, 2022 at 12:42:23PM -0700, David Rientjes wrote:
> On Mon, 25 Apr 2022, Muchun Song wrote:
>
> > Most callers of memcg_slab_free_hook() already know the slab, which could
> > be passed to memcg_slab_free_hook() directly to reduce the overhead of an
> > another call of virt_to_slab(). For bulk freeing of objects, the call of
> > slab_objcgs() in the loop in memcg_slab_free_hook() is redundant as well.
> > Rework memcg_slab_free_hook() and build_detached_freelist() to reduce
> > those unnecessary overhead and make memcg_slab_free_hook() can handle bulk
> > freeing in slab_free().
> >
>
> I agree that for the SLUB case the code flows better after this, but I'm
> wondering if you have any numbers to share on how much better this is once
> we've avoided the virt_to_slab() calls?
>
> IOW, I'm struggling to figure out if this is code cleanup or a performance
> optimization.
>

I think it is both. The numbers are listed in another thread [1].

[1] https://lore.kernel.org/linux-mm/Yme5zE8ZU%2FFN63Av@xxxxxxxxxxxxxxxxxxxxx/T/#m7e5c4ae3e92128781664b3396ce300c8076a5b63

Thanks.