]> git.ipfire.org Git - thirdparty/linux.git/commit
slab: prevent recursive kmalloc() in alloc_empty_sheaf()
authorVlastimil Babka <vbabka@suse.cz>
Wed, 5 Nov 2025 09:05:33 +0000 (10:05 +0100)
committerVlastimil Babka <vbabka@suse.cz>
Fri, 7 Nov 2025 08:59:15 +0000 (09:59 +0100)
commit4c0a17e28340e458627d672564200406e220d6a3
tree7c2fa4bda3acd2559f5c9fecf798175583e420bb
parent31e0886fd57d426d18a239dd55e176032c9c1cb0
slab: prevent recursive kmalloc() in alloc_empty_sheaf()

We want to expand usage of sheaves to all non-boot caches, including
kmalloc caches. Since sheaves themselves are also allocated by
kmalloc(), we need to prevent excessive or infinite recursion -
depending on sheaf size, the sheaf can be allocated from smaller, same
or larger kmalloc size bucket, there's no particular constraint.

This is similar to allocating the objext arrays so let's just reuse the
existing mechanisms for those. __GFP_NO_OBJ_EXT in alloc_empty_sheaf()
will prevent a nested kmalloc() from allocating a sheaf itself - it will
either have sheaves already, or fallback to a non-sheaf-cached
allocation (so bootstrap of sheaves in a kmalloc cache that allocates
sheaves from its own size bucket is possible). Additionally, reuse
OBJCGS_CLEAR_MASK to clear unwanted gfp flags from the nested
allocation.

Link: https://patch.msgid.link/20251105-sheaves-cleanups-v1-5-b8218e1ac7ef@suse.cz
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
include/linux/gfp_types.h
mm/slub.c