mm/slub: introduce __kmem_cache_free_bulk() without free hooks
authorVlastimil Babka <vbabka@suse.cz>
Thu, 2 Nov 2023 15:34:39 +0000 (16:34 +0100)
committerVlastimil Babka <vbabka@suse.cz>
Thu, 7 Dec 2023 11:41:48 +0000 (12:41 +0100)
commit520a688a2edfddba97968bf9e133b9a3d7c78059
tree328235371c48e70c523eb6a3a8ebbd35ca9f2a28
parent6f3dd2c31d7d703a814c59f60daf95c57fa6a4c2
mm/slub: introduce __kmem_cache_free_bulk() without free hooks

Currently, when __kmem_cache_alloc_bulk() fails, it frees back the
objects that were allocated before the failure, using
kmem_cache_free_bulk(). Because kmem_cache_free_bulk() calls the free
hooks (KASAN etc.) and those expect objects that were processed by the
post alloc hooks, slab_post_alloc_hook() is called before
kmem_cache_free_bulk().

This is wasteful, although not a big concern in practice for the rare
error path. But in order to efficiently handle percpu array batch refill
and free in the near future, we will also need a variant of
kmem_cache_free_bulk() that avoids the free hooks. So introduce it now
and use it for the failure path.

In case of failure we however still need to perform memcg uncharge so
handle that in a new memcg_slab_alloc_error_hook(). Thanks to Chengming
Zhou for noticing the missing uncharge.

As a consequence, __kmem_cache_alloc_bulk() no longer needs the objcg
parameter, remove it.

Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c