From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44E0B311968; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327400; cv=none; b=MTM4dZuy5mzmHcIYEe+1SIIuk0QwpeB5IC6ulKFOmk10C+b73F5rfDp4fRFW5VZyEoLktSfnpbrsIpYhBeJyMcxTs3/YlA1WR6BpDUK8XBySKrq0g9hSB+DejiBJ7P/gd4twEghwbiC1mDWhIx2OHhtkYZKtUmKNTaBDNky6rkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327400; c=relaxed/simple; bh=/78RXpgl8TlT0xU+DxO9fTkLja+qHCr4eJjakRnkz4Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=olmk1vnedMm4yj0XujTHNzW4Mgl/DQkbW45Ym8Kq1lTUOoCYgmDkxbWwq5zknwweRqa7SMAp0v0OeSA2TKQd9kWbwAzyqq5x7YIDTEqrcDSAZiH5hwUoe5imNG3NmIozq0Vuvi2tcR9FZfI2o7reFA1HaKQ8hvcmR+/HBaBCSZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=aRvaNWfA; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="aRvaNWfA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=etwwk+UBNIMopirHMNGCuTJ8WFzK9o2sDlIbkCU/y/E=; b=aRvaNWfAS6g+gDAu0XKjGNB84n YQ7IMDvOKksVJWTEAv76k8pTrA4D156NGn11ZgheSAgqSLPwSDwCbGi5obQxZGjJXY9Jp4i9zZQLl ghTZNGVjsmvNK5OWdJlivo4zTyQc+8thOQhStor56IpK/fc5XKmWVE1JXbVhTsTYw59LuR5i5aQmj IBvRDL0FJVgoEToceNPxDPeUOgrw+bh2PrByHPYwRO+t/e4mD43ia4CKWtDtRFaAxx2X4oaGSTbU6 zwWMtzUYp1gWNxy/Bv9IS29m1Ff9KfJ9AqniJw/eVfEVwhuZQl6CKOCK87xE48Cs+urvrpz3cEqhe ak9Ps3Vg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcx-00000003aSr-3soc; Sat, 13 Jun 2026 05:09:51 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 01/10] static kmem_cache instances for core caches: infrastructure Date: Sat, 13 Jun 2026 06:09:42 +0100 Message-ID: <20260613050951.855141-2-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" kmem_cache_create() and friends create new instances of struct kmem_cache and return pointers to those. Quite a few things in core kernel are allocated from such caches; each allocation involves dereferencing an assign-once pointer and for sufficiently hot ones that dereferencing does show in profiles. There had been patches floating around switching some of those to runtime_const infrastructure. Unfortunately, it's arch-specific and most of the architectures lack it. There's an alternative approach applicable at least to the caches that are never destroyed, which covers a lot of them. No matter what, runtime_const for pointers is not going to be faster than plain &, so if we had struct kmem_cache instances with static storage duration, we would be at least no worse off than we are with runtime_const variants. There are obstacles to doing that, but they turn out to be easy to deal with. First of all, struct kmem_cache is opaque for anything outside of a few files in mm/*; that avoids serious headache with header dependenci= es, etc., and it's not something we want to lose. Solution: struct kmem_cache_opaque, with the size and alignment identical to struct kmem_cache. Calculation of size and alignment can be done via the same mechanism we use for asm-offsets.h and rq-offsets.h, with build-time check for mismatches. With that done, we get an opaque type defined in linux/slab-static.h that can be used for declaring those caches. In linux/slab.h we add a forward declaration of kmem_cache_opaque + helper (to_kmem_cache()) converting a pointer to kmem_cache_opaque into the corresponding pointer to kmem_cache. At that point we can't actually *do* anything with those statically allocated instances - the primitives for setting them up are going to be added in the next commits. Declarations of those primitives will also go into linux/slab-static.h. Note that this header is needed only in places that define and initialize statically allocated kmem_cache instances; users of such instances need only slab.h. Signed-off-by: Al Viro --- Kbuild | 14 +++++++++++++- include/linux/slab-static.h | 13 +++++++++++++ include/linux/slab.h | 6 ++++++ mm/kmem_cache_size.c | 20 ++++++++++++++++++++ mm/slub.c | 7 +++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 include/linux/slab-static.h create mode 100644 mm/kmem_cache_size.c diff --git a/Kbuild b/Kbuild index a6a0192dea08..64f29f1f0e71 100644 --- a/Kbuild +++ b/Kbuild @@ -45,6 +45,17 @@ kernel/sched/rq-offsets.s: $(offsets-file) $(rq-offsets-file): kernel/sched/rq-offsets.s FORCE $(call filechk,offsets,__RQ_OFFSETS_H__) =20 +# generate kmem_cache_size.h + +kmem_cache_size-file :=3D include/generated/kmem_cache_size.h + +targets +=3D mm/kmem_cache_size.s + +mm/kmem_cache_size.s: $(rq-offsets-file) + +$(kmem_cache_size-file): mm/kmem_cache_size.s FORCE + $(call filechk,offsets,__KMEM_CACHE_SIZE_H__) + # Check for missing system calls =20 missing-syscalls-file :=3D .tmp_missing-syscalls$(missing_syscalls_instanc= e) @@ -58,7 +69,8 @@ $(missing-syscalls-file): scripts/checksyscalls.sh $(rq-o= ffsets-file) FORCE $(call if_changed_dep,syscalls) =20 PHONY +=3D missing-syscalls -missing-syscalls: $(missing-syscalls-file) +missing-syscalls: $(missing-syscalls-file) $(kmem_cache_size-file) + $(call cmd,syscalls) =20 # Check the manual modification of atomic headers =20 diff --git a/include/linux/slab-static.h b/include/linux/slab-static.h new file mode 100644 index 000000000000..07aca67facee --- /dev/null +++ b/include/linux/slab-static.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_SLAB_STATIC_H +#define _LINUX_SLAB_STATIC_H + +#include +#include + +/* same size and alignment as struct kmem_cache: */ +struct kmem_cache_opaque { + unsigned char opaque[KMEM_CACHE_SIZE]; +} __aligned(KMEM_CACHE_ALIGN); + +#endif diff --git a/include/linux/slab.h b/include/linux/slab.h index 2b5ab488e96b..a43d31eec06c 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -265,11 +265,17 @@ enum _slab_flag_bits { =20 struct list_lru; struct mem_cgroup; +struct kmem_cache_opaque; /* * struct kmem_cache related prototypes */ bool slab_is_available(void); =20 +static inline struct kmem_cache *to_kmem_cache(struct kmem_cache_opaque *p) +{ + return (struct kmem_cache *)p; +} + /** * struct kmem_cache_args - Less common arguments for kmem_cache_create() * diff --git a/mm/kmem_cache_size.c b/mm/kmem_cache_size.c new file mode 100644 index 000000000000..1ddbfa41a507 --- /dev/null +++ b/mm/kmem_cache_size.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Generate definitions needed by the preprocessor. + * This code generates raw asm output which is post-processed + * to extract and format the required data. + */ + +#define COMPILE_OFFSETS +#include +#include "slab.h" + +int main(void) +{ + /* The constants to put into include/generated/kmem_cache_size.h */ + DEFINE(KMEM_CACHE_SIZE, sizeof(struct kmem_cache)); + DEFINE(KMEM_CACHE_ALIGN, __alignof(struct kmem_cache)); + /* End of constants */ + + return 0; +} diff --git a/mm/slub.c b/mm/slub.c index a2bf3756ca7d..c0765173911d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -50,6 +50,7 @@ #include #include #include +#include #include =20 #include "internal.h" @@ -8484,6 +8485,12 @@ void __init kmem_cache_init(void) boot_kmem_cache_node; int node; =20 + /* verify that kmem_cache_opaque is correct */ + BUILD_BUG_ON(sizeof(struct kmem_cache) !=3D + sizeof(struct kmem_cache_opaque)); + BUILD_BUG_ON(__alignof(struct kmem_cache) !=3D + __alignof(struct kmem_cache_opaque)); + if (debug_guardpage_minorder()) slub_max_order =3D 0; =20 --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4369F30E0D5; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; cv=none; b=JjxxWS/WdLFmrq+1HJ9Z3c2ONYwoGZr5Uz7bcG7YDdjsE5lgKDnIdI+Yjr8GpfSnwz1PM+tiq6fo7WeA0m/wv43HqiKq2yZfxWCUvC/ppueC41g0u+s8AAGjHATistKufff2q1nE87c2AP+HlKEJjyoapj+3uTN5sK3I13zuFvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; c=relaxed/simple; bh=Ib7SipcND15i9Xi9CgPyc9oJ6n1ZulRP89t1kxL/qXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sPzYy/GZ/etBs+c42CXmPc+GLaT73L4zf8muUcQaUgcrkvltqiBVRoJmaqHeYviqiMDSQDlFB3HDDO7O1GVIr640sKSHCtcct5MqELMwpIiVaK2YkdyPYZv7M/54bruuQYT9F1EIYp9wqX+iPIbelv7k3cW2JZmR+9VPIMvzsPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=eEUfbi+C; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="eEUfbi+C" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=HAFIfxuSCGXbqOFSe4BmaPoZkUH2BztV4wD/Fo26Jzk=; b=eEUfbi+C0OqJpcI5jCkVeTLdCz kNmjCZWk25dQfls6lP9Zy0xGckD07nz7+gBFJTzha/Q/hkb/WIRQ0atARk1pvCx8xbTfGTeP0wXv5 a1nH0mLSZLfhCRGDZUHa74ZjVO4vnPjR7PP2Xl11PQgNKXF+hI0Z1VhUr3UP4H6PG0U2RWlG48jzL dm3rKxPLWROIFeqr0LpTjTfvC0dSzuPOJa8aZHUCPJzv6nndaCseaM0cvRBZlj8tFixjUUW5RJkJ3 ShYHOJiqkN/6Qe02uOkBbhrjO5D+Bya9L73l41DBIBVNum6J1CsS3l8SgzZan7HvbQafSoHhuWvJb lSfrfuow==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcy-00000003aSu-0WiF; Sat, 13 Jun 2026 05:09:52 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 02/10] static kmem_cache instances for core caches: setup primitives Date: Sat, 13 Jun 2026 06:09:43 +0100 Message-ID: <20260613050951.855141-3-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" Teach the real constructor of kmem_cache needs to deal with preallocated instances and provide wrappers parallel to kmem_cache_create() and friends. That turns out to be easy - we already pass an obscene amount of optional arguments via struct kmem_cache_args, so we can stash the pointer to preallocated instance in there. * add struct kmem_cache_args.preallocated - a pointer to preallocated struct kmem_cache instance into kmem_cache_args. If it's non-NULL, __kmem_cache_create_args() will set the supplied instance up instead of allocating a new one. * new struct kmem_cache.flags bit - SLAB_PREALLOCATED. Set by __kmem_cache_create_args() when it's asked to use a preallocated instance. * create_cache(): do allocation (and, in case of failure, freeing) of struct kmem_cache instance only if no preallocated one has been supplied. * __kmem_cache_alias(): don't bother with aliases when setting a preallocat= ed instance up - we want this one and no other, TYVM... Note that such instan= ce may very well be mergeable - later kmem_cache_create() might decide to retu= rn an alias for it. * sysfs_slab_add() should treat all preallocated instances as self-named - no "unique" (=3D=3D size-and-flags-derived) names for those, any symlinks from possible future aliases will use the cache's name as target. Think what happens if two preallocated kmem_cache instances are set up to have identical sizes and flags - "unique" names will be anything but. Since the preallocated instance won't go away before possible future aliases, there's no problem with using its proper name. * add new wrappers for __kmem_cache_create_args(): kmem_cache_setup(), kmem_cache_setup_usercopy(), KMEM_CACHE_SETUP(), KMEM_CACHE_SETUP_USERCOPY(= ), corresponding to kmem_cache_create(), kmem_cache_create_usercopy(), KMEM_CACHE() and KMEM_CACHE_USERCOPY() resp. A pointer to preallocated instance is passed as the first argument, followed by the arguments one would pass to corresponding kmem_cache constructor. That covers the instances that never get destroyed. Quite a few fall into that category, but there's a major exception - anything in modules must be destroyed before the module gets removed. For example, filesystems that have their inodes allocated from a private kmem_cache can't make use of that technics for their inode allocations, etc. It's not that hard to deal with, but for now let's just ban including slab-static.h from modules. Signed-off-by: Al Viro --- include/linux/slab-static.h | 53 +++++++++++++++++++++++++++++++++++++ include/linux/slab.h | 4 +++ mm/slab_common.c | 33 ++++++++++++----------- mm/slub.c | 20 +++++++------- 4 files changed, 84 insertions(+), 26 deletions(-) diff --git a/include/linux/slab-static.h b/include/linux/slab-static.h index 07aca67facee..007fc0bd4e8c 100644 --- a/include/linux/slab-static.h +++ b/include/linux/slab-static.h @@ -5,9 +5,62 @@ #include #include =20 +#ifdef MODULE +#error "can't use that in modules" +#endif + /* same size and alignment as struct kmem_cache: */ struct kmem_cache_opaque { unsigned char opaque[KMEM_CACHE_SIZE]; } __aligned(KMEM_CACHE_ALIGN); =20 +#define __KMEM_CACHE_SETUP(cache, name, size, flags, ...) \ + __kmem_cache_create_args((name), (size), \ + &(struct kmem_cache_args) { \ + .preallocated =3D (cache), \ + __VA_ARGS__}, (flags)) + +static inline int +kmem_cache_setup_usercopy(struct kmem_cache *s, + const char *name, unsigned int size, + unsigned int align, slab_flags_t flags, + unsigned int useroffset, unsigned int usersize, + void (*ctor)(void *)) +{ + struct kmem_cache *res; + res =3D __KMEM_CACHE_SETUP(s, name, size, flags, + .align =3D align, + .ctor =3D ctor, + .useroffset =3D useroffset, + .usersize =3D usersize); + if (IS_ERR(res)) + return PTR_ERR(res); + return 0; +} + +static inline int +kmem_cache_setup(struct kmem_cache *s, + const char *name, unsigned int size, + unsigned int align, slab_flags_t flags, + void (*ctor)(void *)) +{ + struct kmem_cache *res; + res =3D __KMEM_CACHE_SETUP(s, name, size, flags, + .align =3D align, + .ctor =3D ctor); + if (IS_ERR(res)) + return PTR_ERR(res); + return 0; +} + +#define KMEM_CACHE_SETUP(s, __struct, __flags) \ + __KMEM_CACHE_SETUP((s), #__struct, sizeof(struct __struct), (__flags), \ + .align =3D __alignof__(struct __struct)) + +#define KMEM_CACHE_SETUP_USERCOPY(s, __struct, __flags, __field) \ + __KMEM_CACHE_SETUP((s), #__struct, sizeof(struct __struct), (__flags), \ + .align =3D __alignof__(struct __struct), \ + .useroffset =3D offsetof(struct __struct, __field), \ + .usersize =3D sizeof_field(struct __struct, __field)) + #endif diff --git a/include/linux/slab.h b/include/linux/slab.h index a43d31eec06c..ec68aabf98df 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -62,6 +62,7 @@ enum _slab_flag_bits { #if defined(CONFIG_SLAB_OBJ_EXT) && defined(CONFIG_64BIT) _SLAB_OBJ_EXT_IN_OBJ, #endif + _SLAB_PREALLOCATED, _SLAB_FLAGS_LAST_BIT }; =20 @@ -248,6 +249,8 @@ enum _slab_flag_bits { #define SLAB_OBJ_EXT_IN_OBJ __SLAB_FLAG_UNUSED #endif =20 +#define SLAB_PREALLOCATED __SLAB_FLAG_BIT(_SLAB_PREALLOCATED) + /* * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests. * @@ -378,6 +381,7 @@ struct kmem_cache_args { * %0 means no sheaves will be created. */ unsigned int sheaf_capacity; + struct kmem_cache *preallocated; }; =20 struct kmem_cache *__kmem_cache_create_args(const char *name, diff --git a/mm/slab_common.c b/mm/slab_common.c index 8b661fff5eed..5b6aaa96d68d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -234,33 +234,30 @@ static struct kmem_cache *create_cache(const char *na= me, struct kmem_cache_args *args, slab_flags_t flags) { - struct kmem_cache *s; + struct kmem_cache *s =3D args->preallocated; int err; =20 /* If a custom freelist pointer is requested make sure it's sane. */ - err =3D -EINVAL; if (args->use_freeptr_offset && (args->freeptr_offset >=3D object_size || (!(flags & SLAB_TYPESAFE_BY_RCU) && !args->ctor) || !IS_ALIGNED(args->freeptr_offset, __alignof__(freeptr_t)))) - goto out; + return ERR_PTR(-EINVAL); =20 - err =3D -ENOMEM; - s =3D kmem_cache_zalloc(kmem_cache, GFP_KERNEL); - if (!s) - goto out; + if (!s) { + s =3D kmem_cache_zalloc(kmem_cache, GFP_KERNEL); + if (!s) + return ERR_PTR(-ENOMEM); + } err =3D do_kmem_cache_create(s, name, object_size, args, flags); - if (err) - goto out_free_cache; - + if (unlikely(err)) { + if (!args->preallocated) + kmem_cache_free(kmem_cache, s); + return ERR_PTR(err); + } s->refcount =3D 1; list_add(&s->list, &slab_caches); return s; - -out_free_cache: - kmem_cache_free(kmem_cache, s); -out: - return ERR_PTR(err); } =20 static struct kmem_cache * @@ -269,6 +266,9 @@ __kmem_cache_alias(const char *name, unsigned int size,= slab_flags_t flags, { struct kmem_cache *s; =20 + if (flags & SLAB_PREALLOCATED) // no aliases - we are using this one + return NULL; + s =3D find_mergeable(size, flags, name, args); if (s) { if (sysfs_slab_alias(s, name)) @@ -366,6 +366,9 @@ struct kmem_cache *__kmem_cache_create_args(const char = *name, object_size - args->usersize < args->useroffset)) args->usersize =3D args->useroffset =3D 0; =20 + if (args->preallocated) + flags |=3D SLAB_PREALLOCATED; + s =3D __kmem_cache_alias(name, object_size, flags, args); if (s) goto out_unlock; diff --git a/mm/slub.c b/mm/slub.c index c0765173911d..eee68e0ad7ed 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -9593,18 +9593,16 @@ static int sysfs_slab_add(struct kmem_cache *s) int err; const char *name; struct kset *kset =3D cache_kset(s); - int unmergeable =3D slab_unmergeable(s); + bool no_symlink =3D slab_unmergeable(s); =20 - if (!unmergeable && disable_higher_order_debug && + if (s->flags & SLAB_PREALLOCATED) + no_symlink =3D true; + + if (!no_symlink && disable_higher_order_debug && (slub_debug & DEBUG_METADATA_FLAGS)) - unmergeable =3D 1; + no_symlink =3D true; =20 - if (unmergeable) { - /* - * Slabcache can never be merged so we can use the name proper. - * This is typically the case for debug situations. In that - * case we can catch duplicate names easily. - */ + if (no_symlink) { sysfs_remove_link(&slab_kset->kobj, s->name); name =3D s->name; } else { @@ -9622,12 +9620,12 @@ static int sysfs_slab_add(struct kmem_cache *s) if (err) goto out; =20 - if (!unmergeable) { + if (!no_symlink) { /* Setup first alias */ sysfs_slab_alias(s, s->name); } out: - if (!unmergeable) + if (!no_symlink) kfree(name); return err; } --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EBF2369D56; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; cv=none; b=jjv1AURYfCOz7O+b+aOM/FFLNhApoqJLt/oR1MWX/xPTFJVg+pGRhgTYrxAE+4JSVJBK02EOqxKiFOxgxoiimcgvThSbQrdRnd775ztIUbHYfdHZ+KonV1Efq4NOjRJ92gp1DqOb/iTbiq1odF4T4JoVpThjAEJxkk7IV0W1CVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; c=relaxed/simple; bh=t2ustfZJko2VxR4EK6aBYqubTS+D9clSCtcK+yIT57c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A7ZmmwBy0YoBIsNGAGdsLR4SOeFApCR23KfPk/BaF+Z4X5nyerq1oCPSfOp4WKfRKvXcg44aHJlcIK95UKvIar2ExKPeQUnMspMBUd9SYvXmR+BW0Fx095WGMyMJ5nl9s/5T1PmV5tzRETWaDov+lwQuV4SbRWZoOjhJwNkDCwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=r2gupMby; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="r2gupMby" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=v5eFW2g7W1dcJNtE4gdFektrsMjBmaMLK4+5JsIr98U=; b=r2gupMbySKmfWqHfZq5g0R3ZS2 7W+4ibTEhfYBwKj2I+ajAicV076fh4vivRZ+uZEH6YvFWmJZSjlu7DaV7W8C1RaSYia07QdF0zdYj kLsgFib+h3Z67aodCxRYuO6EeZFXAwccbKa5jjt/1BnzCRTRO521+zppM73EuzLBJjATpifJl1GVZ msdUMEIffQxNn8EcSjWY0VKAdaOpmo6Hiq+nxpKdc4e7d9aaZ3bmPvs8qE7CgQT79fGvupEzevxH8 oa2oae8BiJBuPf87hdGwp4HBHYYgIRQrOklBS39V///Q9ETpfA3DwUoTrE8eMdgzII1wAQTOFVJkq 2yrgLPmg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcy-00000003aT0-1Lre; Sat, 13 Jun 2026 05:09:52 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 03/10] allow preallocated kmem_cache instances in modules Date: Sat, 13 Jun 2026 06:09:44 +0100 Message-ID: <20260613050951.855141-4-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" We need to make sure that instance in a module will get to slab_kmem_cache_release() before the module data gets freed. That's only a problem on sysfs setups - otherwise it'll definitely be finished before kmem_cache_destroy() returns. Note that modules themselves have sysfs-exposed attributes, so a similar problem already exists there. That's dealt with by having mod_sysfs_teardown() wait for refcount of module->mkobj.kobj reaching zero. Let's make use of that - have static-duration-in-module kmem_cache instances grab a reference to that kobject upon setup and drop it in the end of slab_kmem_cache_release(). Let setup helpers store the kobject to be pinned in kmem_cache_args->owner (for preallocated; if somebody manually sets it for non-preallocated case, it'll be ignored). That would be &THIS_MODULE->mkobj.kobj for a module and NULL in built-in. If sysfs is enabled and we are dealing with preallocated instance, let create_cache() grab and stash that reference in kmem_cache->owner and let slab_kmem_cache_release() drop it instead of freeing kmem_cache instance. Preallocated kmem_cache instances in modules are forcibly made non-mergable - any subsequent alias could outlive the module (and module's .data) by arbitrary long time. If you really want your (modular) cache to be mergable, just have it dynamically allocated. Signed-off-by: Al Viro --- include/linux/slab-static.h | 11 +++++++---- include/linux/slab.h | 1 + mm/slab.h | 1 + mm/slab_common.c | 19 +++++++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/linux/slab-static.h b/include/linux/slab-static.h index 007fc0bd4e8c..16d1564b4a4b 100644 --- a/include/linux/slab-static.h +++ b/include/linux/slab-static.h @@ -5,18 +5,21 @@ #include #include =20 -#ifdef MODULE -#error "can't use that in modules" -#endif - /* same size and alignment as struct kmem_cache: */ struct kmem_cache_opaque { unsigned char opaque[KMEM_CACHE_SIZE]; } __aligned(KMEM_CACHE_ALIGN); =20 +#ifdef MODULE +#define THIS_MODULE_KOBJ &THIS_MODULE->mkobj.kobj +#else +#define THIS_MODULE_KOBJ NULL +#endif + #define __KMEM_CACHE_SETUP(cache, name, size, flags, ...) \ __kmem_cache_create_args((name), (size), \ &(struct kmem_cache_args) { \ + .owner =3D THIS_MODULE_KOBJ, \ .preallocated =3D (cache), \ __VA_ARGS__}, (flags)) =20 diff --git a/include/linux/slab.h b/include/linux/slab.h index ec68aabf98df..c95ad771ece2 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -382,6 +382,7 @@ struct kmem_cache_args { */ unsigned int sheaf_capacity; struct kmem_cache *preallocated; + struct kobject *owner; }; =20 struct kmem_cache *__kmem_cache_create_args(const char *name, diff --git a/mm/slab.h b/mm/slab.h index bf2f87acf5e3..8b1db0d03226 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -219,6 +219,7 @@ struct kmem_cache { struct list_head list; /* List of slab caches */ #ifdef CONFIG_SYSFS struct kobject kobj; /* For sysfs */ + struct kobject *owner; /* keep that pinned while alive */ #endif #ifdef CONFIG_SLAB_FREELIST_HARDENED unsigned long random; diff --git a/mm/slab_common.c b/mm/slab_common.c index 5b6aaa96d68d..1717c79d92be 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -255,6 +255,12 @@ static struct kmem_cache *create_cache(const char *nam= e, kmem_cache_free(kmem_cache, s); return ERR_PTR(err); } +#ifdef CONFIG_SYSFS + if (flags & SLAB_PREALLOCATED) { + s->owner =3D args->owner; + kobject_get(s->owner); + } +#endif s->refcount =3D 1; list_add(&s->list, &slab_caches); return s; @@ -366,8 +372,11 @@ struct kmem_cache *__kmem_cache_create_args(const char= *name, object_size - args->usersize < args->useroffset)) args->usersize =3D args->useroffset =3D 0; =20 - if (args->preallocated) + if (args->preallocated) { flags |=3D SLAB_PREALLOCATED; + if (args->owner) + flags |=3D SLAB_NO_MERGE; + } =20 s =3D __kmem_cache_alias(name, object_size, flags, args); if (s) @@ -524,7 +533,13 @@ void slab_kmem_cache_release(struct kmem_cache *s) { __kmem_cache_release(s); kfree_const(s->name); - kmem_cache_free(kmem_cache, s); + if (!(s->flags & SLAB_PREALLOCATED)) { + kmem_cache_free(kmem_cache, s); + return; + } +#ifdef CONFIG_SYSFS + kobject_put(s->owner); +#endif } =20 void kmem_cache_destroy(struct kmem_cache *s) --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 464C6312819; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327400; cv=none; b=oLIR8bGIYPkdcz7/vQnZZbH8P7cujfz946p1xxHSU1i0TQ1E4P0vm9g9WmT6rvoToh7s+Z83bNKS+JJh0XtqxP9U7l3mzPwBR5qfjdrm5hy6YaO7u91KYwlTDfFob2INaZ29w11Kts2YxjN6ENvGAQDsBFLBQWsyw1BvhSfAf90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327400; c=relaxed/simple; bh=cjGMkoeVWYc4HPLQXfs6wK0Rbe8Wkfa+R4yDqEvR4vA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RkWSYS1eYlPoderhvRId0CghRh9TnALaC7I9KkdDhiG1v5MzaMXzw5L9t2tb/fGAVHwl6vuyzDwAGYQUF5Gw6RgLWUkXucR2FpAtDBaKzw5KUKLeznYEVsegfvclS9niMpoyi6iKYT5hPEnSsfEwfDU2gDkTtcXptoG9dhyinYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=myzaZMTD; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="myzaZMTD" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=cNpPMJRuzPptN3b4+pwG4kih5al6fcdrnvjIBitAll4=; b=myzaZMTD20T+4UAZkEnkfC4kib dv/f/fHmg5934MeqcRlO2CwLAZnDh1DanDfxMsauMZbpZuV3EldVcQdo+R2l+oOppcT9sTvS9bsiy z+3SdtWxjVnQYUM9tIY1KBC+mRDSSP8lPYG2M/kSaB0Rs3EmlMqTAPIUh6eykwJGsbJuHPXrPIuj3 vlzdNDZYr1qc3Gtabmros25Ble+2R7GB4yh32hDsAz5lDZtR+tjTuKds2a3uz3ajudJOVrkIV2hnt azyRwfe2Fj42LQYUbVDvQLYsA8+Ui98849VLD+/wq7QbVRNupEkQ1tTt/zSHSiPvB3EfAVr5ECcuA NwMKNSKw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcy-00000003aT5-2IA0; Sat, 13 Jun 2026 05:09:52 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 04/10] VFS caches: switch from runtime_const() machinery to slab-static.h Date: Sat, 13 Jun 2026 06:09:45 +0100 Message-ID: <20260613050951.855141-5-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" Four VFS caches are currently playing games with runtime_const() to reduce the overhead of pointer traversals - dentry, file, backing_file and filename. All of these kmem_cache instances can be allocated statically now, getting rid of runtime_const() games. Signed-off-by: Al Viro --- fs/dcache.c | 8 +++---- fs/file_table.c | 40 ++++++++++++++----------------- fs/namei.c | 16 ++++++------- include/asm-generic/vmlinux.lds.h | 6 +---- 4 files changed, 31 insertions(+), 39 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 2c61aeea41f4..e2feea82682a 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "internal.h" #include "mount.h" =20 @@ -86,8 +87,8 @@ __cacheline_aligned_in_smp DEFINE_SEQLOCK(rename_lock); =20 EXPORT_SYMBOL(rename_lock); =20 -static struct kmem_cache *__dentry_cache __ro_after_init; -#define dentry_cache runtime_const_ptr(__dentry_cache) +static struct kmem_cache_opaque __dentry_cache; +#define dentry_cache to_kmem_cache(&__dentry_cache) =20 const struct qstr empty_name =3D QSTR_INIT("", 0); EXPORT_SYMBOL(empty_name); @@ -3362,10 +3363,9 @@ static void __init dcache_init(void) * but it is probably not worth it because of the cache nature * of the dcache. */ - __dentry_cache =3D KMEM_CACHE_USERCOPY(dentry, + KMEM_CACHE_SETUP_USERCOPY(dentry_cache, dentry, SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_ACCOUNT, d_shortname.string); - runtime_const_init(ptr, __dentry_cache); =20 /* Hash may have been set up in dcache_init_early */ if (!hashdist) diff --git a/fs/file_table.c b/fs/file_table.c index 16e52e7fc2ac..3844bc9f0e0a 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -27,11 +27,10 @@ #include #include #include +#include =20 #include =20 -#include - #include "internal.h" =20 /* sysctl tunables... */ @@ -40,10 +39,10 @@ static struct files_stat_struct files_stat =3D { }; =20 /* SLAB cache for file structures */ -static struct kmem_cache *__filp_cache __ro_after_init; -#define filp_cache runtime_const_ptr(__filp_cache) -static struct kmem_cache *__bfilp_cache __ro_after_init; -#define bfilp_cache runtime_const_ptr(__bfilp_cache) +static struct kmem_cache_opaque file_cache; +static struct kmem_cache_opaque backing_file_cache; +#define filp_cache to_kmem_cache(&file_cache) +#define bfilp_cache to_kmem_cache(&backing_file_cache) =20 static struct percpu_counter nr_files __cacheline_aligned_in_smp; =20 @@ -629,22 +628,19 @@ void fput_close(struct file *file) =20 void __init files_init(void) { - struct kmem_cache_args args =3D { - .use_freeptr_offset =3D true, - .freeptr_offset =3D offsetof(struct file, f_freeptr), - }; - - __filp_cache =3D kmem_cache_create("filp", sizeof(struct file), &args, - SLAB_HWCACHE_ALIGN | SLAB_PANIC | - SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU); - runtime_const_init(ptr, __filp_cache); - - args.freeptr_offset =3D offsetof(struct backing_file, bf_freeptr); - __bfilp_cache =3D kmem_cache_create("bfilp", sizeof(struct backing_file), - &args, SLAB_HWCACHE_ALIGN | SLAB_PANIC | - SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU); - runtime_const_init(ptr, __bfilp_cache); - + __KMEM_CACHE_SETUP(filp_cache, "filp", sizeof(struct file), + SLAB_HWCACHE_ALIGN | SLAB_PANIC | + SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU, + .use_freeptr_offset =3D true, + .freeptr_offset =3D offsetof(struct file, + f_freeptr)); + + __KMEM_CACHE_SETUP(bfilp_cache, "bfilp", sizeof(struct backing_file), + SLAB_HWCACHE_ALIGN | SLAB_PANIC | + SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU, + .use_freeptr_offset =3D true, + .freeptr_offset =3D offsetof(struct backing_file, + bf_freeptr)); percpu_counter_init(&nr_files, 0, GFP_KERNEL); } =20 diff --git a/fs/namei.c b/fs/namei.c index 4787244ca4a7..13d95881e921 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -40,8 +40,7 @@ #include #include #include - -#include +#include =20 #include "internal.h" #include "mount.h" @@ -126,15 +125,16 @@ */ =20 /* SLAB cache for struct filename instances */ -static struct kmem_cache *__names_cache __ro_after_init; -#define names_cache runtime_const_ptr(__names_cache) +static struct kmem_cache_opaque __names_cache; +#define names_cache to_kmem_cache(&__names_cache) =20 void __init filename_init(void) { - __names_cache =3D kmem_cache_create_usercopy("names_cache", sizeof(struct= filename), 0, - SLAB_HWCACHE_ALIGN|SLAB_PANIC, offsetof(struct filename, iname), - EMBEDDED_NAME_MAX, NULL); - runtime_const_init(ptr, __names_cache); + kmem_cache_setup_usercopy(names_cache, "names_cache", + sizeof(struct filename), 0, + SLAB_HWCACHE_ALIGN|SLAB_PANIC, + offsetof(struct filename, iname), + EMBEDDED_NAME_MAX, NULL); } =20 static inline struct filename *alloc_filename(void) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 60c8c22fd3e4..4719269086c7 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -966,11 +966,7 @@ =20 #define RUNTIME_CONST_VARIABLES \ RUNTIME_CONST(shift, d_hash_shift) \ - RUNTIME_CONST(ptr, dentry_hashtable) \ - RUNTIME_CONST(ptr, __dentry_cache) \ - RUNTIME_CONST(ptr, __names_cache) \ - RUNTIME_CONST(ptr, __filp_cache) \ - RUNTIME_CONST(ptr, __bfilp_cache) + RUNTIME_CONST(ptr, dentry_hashtable) =20 /* Alignment must be consistent with (kunit_suite *) in include/kunit/test= .h */ #define KUNIT_TABLE() \ --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 493E031E847; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327402; cv=none; b=t7ZMDV/pvYQBSDDsXpwdCH1TL4yPI4xgm/dcfVWPHrIa0DThtTcvx4fYwWBRhTkLngbfyj6MjqmhqrwmN+4sJiUE2ePMd+GA9qPa/Q9x0p2y95crEXryQUXt0ekT46izYsswuhZZjvVPk3zq8xRqBp0WTvHy7n4aOncOpaP7B00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327402; c=relaxed/simple; bh=aVyrF6GmaUwC6jL/gHBP/nWblMEXQRCN2xDxdwa/YfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oz4gIaGTB3sKnvIvTmRTh8OuDhhctrfZbYuZlDD458FHOGTbJHrLs6RmFJMyTTD3iAdbc1pWpvBHPFgyID4eoNhwgzTgq9YMXsmn0ZBnNEMJwIrxRD76ZFGthior+YwmmWHa96eKP/HyEbEJ0sLBs12rKbkpjwWJqTssamOxw6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=gDTlF0Jp; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="gDTlF0Jp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=6f3OoggzlPIzKQe/th8iqmFArhYwFRFyJgw+Gf2/5vg=; b=gDTlF0Jp7OiugKRzAwtDz8Jfwm neDfrE+2AytAPJEGebM+9vkv8xGIEzPWzFLqaLdDuS+qGjNBPML5W4bYsKzqZQFruNy6Q2NHb2TQ+ cUxO+r8m3+1QTQfcSTteMRP5eI3oP4kikzh/m7pvN7NNTH7Q3x+VIR2oVSgGlVHhuakPNwbfeIJzK Mg7DxKAChWsErdIaxYK4TGeXWjY5m8mHOw6eD+U6lIw1+rXMScNQ+Y0hbISppLVKdbU1jSfAPYPDR 4EXK3CI+dIusUiQmPK4CrOD/KDdnbtD59Qf10pLNBVIzvyq74rejZxZhUmSetIlA5zb8bxAUI6slN jTboEJ9Q==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcy-00000003aT9-2z85; Sat, 13 Jun 2026 05:09:52 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 05/10] make inode_cache statically allocated Date: Sat, 13 Jun 2026 06:09:46 +0100 Message-ID: <20260613050951.855141-6-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" Signed-off-by: Al Viro --- fs/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 62c579a0cf7d..1c657ac99084 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #define CREATE_TRACE_POINTS #include @@ -76,7 +77,8 @@ EXPORT_SYMBOL(empty_aops); static DEFINE_PER_CPU(unsigned long, nr_inodes); static DEFINE_PER_CPU(unsigned long, nr_unused); =20 -static struct kmem_cache *inode_cachep __ro_after_init; +static struct kmem_cache_opaque inode_cache; +#define inode_cachep to_kmem_cache(&inode_cache) =20 static long get_nr_inodes(void) { @@ -2598,7 +2600,7 @@ void __init inode_init_early(void) void __init inode_init(void) { /* inode slab cache */ - inode_cachep =3D kmem_cache_create("inode_cache", + kmem_cache_setup(inode_cachep, "inode_cache", sizeof(struct inode), 0, (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC| --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D679368D43; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327400; cv=none; b=T0JtQz7hB5VHGZHK/7XTr08ZTVF3DpC1DijorzM3h1G31BZfzEIiXYC0De4J36C/9sdU0cdI7aYZjxUE2XswpHnRWgKuz+xAIkhHorJvx1uPGNaNMtlusEX+vW+1pdTxoeORw+R4ilL2luThlqzjRZH3iz/ydLVI49gizZuj8FA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327400; c=relaxed/simple; bh=E2HVMIfxxIbjX40EObccnDitdTOl46wVOtsPAveEt+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tep21mv4iecVsd8IVOa5ibU1J1m2p7rliQD27oGh3e7foZO5kGmAW7sZylNjwL/PBMAvstggP68Gk6rPA0P3UK8v0Vkh46N1Lq7deLR/ywWhhCR591RCftNocdtaSqKTw7uuZ5JxYPe3NOZmPyFk+fWrxb0MDe2phdIApXQ4hKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=oDl2Okc4; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="oDl2Okc4" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=C9rJz0S4ZvlUN8tTo22g/3aNhc0livUU3ytI37nwAhU=; b=oDl2Okc42x/lldoIdjfrsalnpk Yt7seMej/y4SVeL8gAXIzUuPUpqG6PzZWhIybTn0nMGRQ3Jjk6r3IcQlLLDlwGEdBqFA/RpHvLwAK VB2dAqlDPhN/4eLE0OX3GOOJ2tDzbKOdhN+jEfiORhqLfxKkA609cQAsRuVIjjgfdRh036/4xfXGo 3Uc9sLSV7gc5oRtFMBxfEs/5wZu1BzWFLseKfUoTturCdCuHldP7pwmiFTVC0p6ws6UAS/piS2p8T AJ1VbgenroME5//r9+44eoTrsBS83Wr+WXGtp+2TRvOVwev5qBqBDTDu2HSrrPqrQvQkj7U/D+LOO 7Rpo1/Lg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcy-00000003aTF-3TUr; Sat, 13 Jun 2026 05:09:52 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 06/10] make mnt_cache statically allocated Date: Sat, 13 Jun 2026 06:09:47 +0100 Message-ID: <20260613050951.855141-7-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" Signed-off-by: Al Viro --- fs/namespace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index f5905f4ec560..330ac43efb8d 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 #include "pnode.h" #include "internal.h" @@ -79,7 +80,8 @@ static u64 mnt_id_ctr =3D MNT_UNIQUE_ID_OFFSET; =20 static struct hlist_head *mount_hashtable __ro_after_init; static struct hlist_head *mountpoint_hashtable __ro_after_init; -static struct kmem_cache *mnt_cache __ro_after_init; +static struct kmem_cache_opaque __mnt_cache; +#define mnt_cache to_kmem_cache(&__mnt_cache) static DECLARE_RWSEM(namespace_sem); static HLIST_HEAD(unmounted); /* protected by namespace_sem */ static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */ @@ -6234,7 +6236,7 @@ void __init mnt_init(void) { int err; =20 - mnt_cache =3D kmem_cache_create("mnt_cache", sizeof(struct mount), + kmem_cache_setup(mnt_cache, "mnt_cache", sizeof(struct mount), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); =20 mount_hashtable =3D alloc_large_system_hash("Mount-cache", --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47B4A314D34; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327399; cv=none; b=M5p3mbVGesiayzfKuMICL5ZrT6FrypgP1GgtxWjOIiNZUWpjv/zbzurrXCRhlzEobkvAq9/z+/ZVsLrs5fTJW7df98slR+jfae9La2OtQgXlDz0xXSwb5+oXconuxoD1/NadKFDVD9pst7IYFT55JGNN1uzfDEnUaymf/iRNwfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327399; c=relaxed/simple; bh=KZqzhXpLuUiZO+jd6YhFthJurVT4/GGa/2WSPqEKLuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4wAtGgFun94covufV0ANQ+p8mhQP/xz5IvHMWhmvTEdyfuoq8ObWuzfXncbYnjXU8BcaHL4ZuX6Gp6LCfzfD4YVsvfGBwWndD8svd3tl6dCntJXwOvCX5NH5gh7XeuPqNTbGqe0dKCsYa9uhvZallZh43P1U2iN7vkdtt3XRXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=is2Egeu6; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="is2Egeu6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=XQVmtnuRTUVgN+XDKa4kk4jqSyJyiqHHhlvxjk0X6XI=; b=is2Egeu6/E0Y59HwEGUchJIXbu vvsTtdmBZVMK9LVkHzW5SRn8tRwn8haNo97Vx6NZxgxFEEPJVVOPdliXHTN9GexiGDWV/mqmXTcA8 vTfgF1nIfWZKBhfV5HkbwQ6FjA3hvM0e0PDElW34aUCUUTN+ozI8zgzNjOUP6Lb/LqJUxuoc/xZP4 j5XSX6SpMJjb8qlFtUdEq3mKuQhl7xoBTAm5BV08AzyNvC8aX13uRur90nerQGGkzCCQNHMpk1UTN DUgSVtPIJpFiFqEU2bgsuvMk2CEw/NOUHFF5PORb/YmV3ERUzaGFz9D7j+DtVtdMwiNs+xBPPjOuu tbCUcFWg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcy-00000003aTH-3jDL; Sat, 13 Jun 2026 05:09:52 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 07/10] make bh_cachep statically allocated Date: Sat, 13 Jun 2026 06:09:48 +0100 Message-ID: <20260613050951.855141-8-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" Signed-off-by: Al Viro --- fs/buffer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index b0b3792b1496..e834f7091f51 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -51,6 +51,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -2906,7 +2907,8 @@ EXPORT_SYMBOL(try_to_free_buffers); /* * Buffer-head allocation */ -static struct kmem_cache *bh_cachep __ro_after_init; +static struct kmem_cache_opaque bh_cache; +#define bh_cachep to_kmem_cache(&bh_cache) =20 /* * Once the number of bh's in the machine exceeds this level, we start @@ -3065,7 +3067,7 @@ void __init buffer_init(void) unsigned long nrpages; int ret; =20 - bh_cachep =3D KMEM_CACHE(buffer_head, + KMEM_CACHE_SETUP(bh_cachep, buffer_head, SLAB_RECLAIM_ACCOUNT|SLAB_PANIC); /* * Limit the bh occupancy to 10% of ZONE_NORMAL --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C0B6368958; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; cv=none; b=OJJ1Km0PHG4FKp+NEY2ZiZ4aoCY5clFFAN5iAA8mGwT0t78Lh/ZquyDlosJA393ENanKQJzXD2ZU7f1T4/yUpuFTO0Wsh+I3LktHrMuk0pjatHCgQyUIt/xuzZeLnYUu3Pn8zdgS9tlCiBjx1ZTfCXH/n5YPVsY4YEA/xuvXVtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; c=relaxed/simple; bh=JfAEM3aUjV9uUMWZEiRcOGIAaKHG0E8Tz/cn04M7Nk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZTNT/DFsqFjefgFTexQay2i/A5K68D/vylWPK7gObHIBy57OhJXyvqGG+n/MrQQ5BSztq9QMOkFnd9YMj6BVDBRDpQQMws80PKoRwGUi0gdItt5GOVayjQ1jHcMIq13xj1cKw9n5cDxHQ2UB2nEu81H6wVTs1QqiA1ek4ACSL1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=Nos2WlW4; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="Nos2WlW4" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=MZHJrCjRIjmtPr++aWYgFPkpaIkTjbAk/NLmMP37eM0=; b=Nos2WlW4avhTR8+u6YCwvP8d+s oR4tk0eASVMFp1JK9z90AsQc9iVzAv8lJ5g6Oq3V0cswhjNaSsW9udD7a0LaIfU79kijFMTINaMEw zzhY/WUIgnBhvlQgiIVZqOoJayPotZl3XKxvKhMKSlIuQWf2fMe0wR0jnBdUFSsrpmkHYzYVJfRAI 26CVSNTzEp4CASoQ1Zvj8vEFN8HewtZCSjEwHJnFUHdfUwgApdM88Cw4bjYogzaQ1m1CP/0zlSkqc cEi6Cdfuy0iAVYXFU44xyp59MDfZ1D+yM8lO0WInLgTOuZDlW34XCmuoZyv2pdoeEz/LCddifL12j IF5WbyQg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcz-00000003aTL-02av; Sat, 13 Jun 2026 05:09:53 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 08/10] make seq_file_cache statically allocated Date: Sat, 13 Jun 2026 06:09:49 +0100 Message-ID: <20260613050951.855141-9-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" Signed-off-by: Al Viro --- fs/seq_file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 4745db2a34d1..7cb40ae83f9b 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -20,11 +20,13 @@ #include #include #include +#include =20 #include #include =20 -static struct kmem_cache *seq_file_cache __ro_after_init; +static struct kmem_cache_opaque __seq_file_cache; +#define seq_file_cache to_kmem_cache(&__seq_file_cache) =20 static void seq_set_overflow(struct seq_file *m) { @@ -1140,5 +1142,5 @@ EXPORT_SYMBOL(seq_hlist_next_percpu); =20 void __init seq_file_init(void) { - seq_file_cache =3D KMEM_CACHE(seq_file, SLAB_ACCOUNT|SLAB_PANIC); + KMEM_CACHE_SETUP(seq_file_cache, seq_file, SLAB_ACCOUNT|SLAB_PANIC); } --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A9EA35B650; Sat, 13 Jun 2026 05:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327399; cv=none; b=lSjJH3nOelDj3qgVnO/BfO4KeFgTM2Ekcex2AimHD0CurlbcfypdEsoheh5czm5WiAUERjgduKriFzKa0KKFXCxhWulP18YRFKhtI2j7ntuWnKj9LQ7YIL4iEdukQY/FN4eiE0FRpR1p78qAUWB81620km9kSzidci7beWLqbWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327399; c=relaxed/simple; bh=UF2qSRY+IuRHzZU7OoQIc1QZzkeH1ip6bx9g1sIY4kY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwdYgRk7Fomn/axaAJ7Gx9ZUNWtZ9vZZxNgEhfiaowEG56Ifq0noYTcoIAJPGMiWH2e9vmjePSFkkbncId3nSnD7/SLT1VcWwV54X2NZlXZTiXVkOpb6bdLtFvmK0DYCdZz08UMJBEDJ5CyOp7WyR+p48KvBBFfFRrYzEK9eWm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=hHPcAiXH; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="hHPcAiXH" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=PgiBt+cXBNmLBpECoGiXITUCwoLXcLuCPMDzB/akGTA=; b=hHPcAiXHeVgaLLjvjpBxpyNC9E UYDBnBCLcLqoQpAPYS2U0r1DopzNQ6/LZZLMighTBBsdiawe0464cTBafMwSbIAQrm8ojuf1BAyWe u4gYy6sHmrIvCJwAoYUc56plrHPz6uTganRPD/ea7hlrL4jkoQsKcuCEM/4jyFt1ZGbaysrSldL/I bcxgROxabuXlNsbtuqdGyyUqtCk/Q5vmRDhGg9OjzUSeNoc1HTQgKoBDXUyWsDL5bHuiLGgUh6bvh XybQJJKZzMEhMYEdfc+uhGukV04XBprjV0mCl5d+stZ3sph6piCHfmCG6vxex96B6vargi4PvCLrf aI7/BtpA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcz-00000003aTT-1lVP; Sat, 13 Jun 2026 05:09:53 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 09/10] make thread component caches (fs_cachep, files_cachep, etc.) statically allocated Date: Sat, 13 Jun 2026 06:09:50 +0100 Message-ID: <20260613050951.855141-10-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" All of them are created in kernel/fork.c, might as well convert all at once... Signed-off-by: Al Viro --- include/linux/fdtable.h | 3 ++- include/linux/fs_struct.h | 3 ++- include/linux/signal.h | 3 ++- kernel/fork.c | 37 +++++++++++++++++++++---------------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index c45306a9f007..f2d553f99c58 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -113,6 +113,7 @@ int iterate_fd(struct files_struct *, unsigned, extern int close_fd(unsigned int fd); extern struct file *file_close_fd(unsigned int fd); =20 -extern struct kmem_cache *files_cachep; +extern struct kmem_cache_opaque files_cache; +#define files_cachep to_kmem_cache(&files_cache) =20 #endif /* __LINUX_FDTABLE_H */ diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h index 0070764b790a..e8c9fac5b7b7 100644 --- a/include/linux/fs_struct.h +++ b/include/linux/fs_struct.h @@ -15,7 +15,8 @@ struct fs_struct { struct path root, pwd; } __randomize_layout; =20 -extern struct kmem_cache *fs_cachep; +extern struct kmem_cache_opaque fs_struct_cache; +#define fs_cachep to_kmem_cache(&fs_struct_cache) =20 extern void exit_fs(struct task_struct *); extern void set_fs_root(struct fs_struct *, const struct path *); diff --git a/include/linux/signal.h b/include/linux/signal.h index f19816832f05..a0c7fee8b22a 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -323,7 +323,8 @@ static inline void disallow_signal(int sig) kernel_sigaction(sig, SIG_IGN); } =20 -extern struct kmem_cache *sighand_cachep; +extern struct kmem_cache_opaque sighand_cache; +#define sighand_cachep to_kmem_cache(&sighand_cache) =20 extern bool unhandled_signal(struct task_struct *tsk, int sig); =20 diff --git a/kernel/fork.c b/kernel/fork.c index 8ac38beae360..618f19bb482a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -111,6 +111,7 @@ #include #include #include +#include =20 #include #include @@ -180,7 +181,8 @@ void __weak arch_release_task_struct(struct task_struct= *tsk) { } =20 -static struct kmem_cache *task_struct_cachep; +static struct kmem_cache_opaque task_struct_cache; +#define task_struct_cachep to_kmem_cache(&task_struct_cache) =20 static inline struct task_struct *alloc_task_struct_node(int node) { @@ -425,7 +427,8 @@ static void free_thread_stack(struct task_struct *tsk) =20 #else /* !(THREAD_SIZE >=3D PAGE_SIZE) */ =20 -static struct kmem_cache *thread_stack_cache; +static struct kmem_cache_opaque __thread_stack_cache; +#define thread_stack_cache to_kmem_cache(&__thread_stack_cache) =20 static void thread_stack_free_rcu(struct rcu_head *rh) { @@ -456,29 +459,31 @@ static void free_thread_stack(struct task_struct *tsk) =20 void thread_stack_cache_init(void) { - thread_stack_cache =3D kmem_cache_create_usercopy("thread_stack", - THREAD_SIZE, THREAD_SIZE, 0, 0, + kmem_cache_setup_usercopy(thread_stack_cache, "thread_stack", + THREAD_SIZE, THREAD_SIZE, + SLAB_PANIC, 0, THREAD_SIZE, NULL); - BUG_ON(thread_stack_cache =3D=3D NULL); } =20 #endif /* THREAD_SIZE >=3D PAGE_SIZE */ #endif /* CONFIG_VMAP_STACK */ =20 /* SLAB cache for signal_struct structures (tsk->signal) */ -static struct kmem_cache *signal_cachep; +static struct kmem_cache_opaque signal_cache; +#define signal_cachep to_kmem_cache(&signal_cache) =20 /* SLAB cache for sighand_struct structures (tsk->sighand) */ -struct kmem_cache *sighand_cachep; +struct kmem_cache_opaque sighand_cache; =20 /* SLAB cache for files_struct structures (tsk->files) */ -struct kmem_cache *files_cachep; +struct kmem_cache_opaque files_cache; =20 /* SLAB cache for fs_struct structures (tsk->fs) */ -struct kmem_cache *fs_cachep; +struct kmem_cache_opaque fs_struct_cache; =20 /* SLAB cache for mm_struct structures (tsk->mm) */ -static struct kmem_cache *mm_cachep; +static struct kmem_cache_opaque mm_cache; +#define mm_cachep to_kmem_cache(&mm_cache) =20 static void account_kernel_stack(struct task_struct *tsk, int account) { @@ -859,7 +864,7 @@ void __init fork_init(void) =20 /* create a slab on which task_structs can be allocated */ task_struct_whitelist(&useroffset, &usersize); - task_struct_cachep =3D kmem_cache_create_usercopy("task_struct", + kmem_cache_setup_usercopy(task_struct_cachep, "task_struct", arch_task_struct_size, align, SLAB_PANIC|SLAB_ACCOUNT, useroffset, usersize, NULL); @@ -3079,7 +3084,7 @@ void __init mm_cache_init(void) */ mm_size =3D sizeof(struct mm_struct) + cpumask_size() + mm_cid_size(); =20 - mm_cachep =3D kmem_cache_create_usercopy("mm_struct", + kmem_cache_setup_usercopy(mm_cachep, "mm_struct", mm_size, ARCH_MIN_MMSTRUCT_ALIGN, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, offsetof(struct mm_struct, saved_auxv), @@ -3089,19 +3094,19 @@ void __init mm_cache_init(void) =20 void __init proc_caches_init(void) { - sighand_cachep =3D kmem_cache_create("sighand_cache", + kmem_cache_setup(sighand_cachep, "sighand_cache", sizeof(struct sighand_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| SLAB_ACCOUNT, sighand_ctor); - signal_cachep =3D kmem_cache_create("signal_cache", + kmem_cache_setup(signal_cachep, "signal_cache", sizeof(struct signal_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); - files_cachep =3D kmem_cache_create("files_cache", + kmem_cache_setup(files_cachep, "files_cache", sizeof(struct files_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); - fs_cachep =3D kmem_cache_create("fs_cache", + kmem_cache_setup(fs_cachep, "fs_cache", sizeof(struct fs_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); --=20 2.47.3 From nobody Mon Jun 22 04:52:06 2026 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1471A37F011; Sat, 13 Jun 2026 05:09:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; cv=none; b=CmPcaJYmYt1Z92InIjTSae1dSSkEYutypQ9xScegdYn4YFnN5YoeGMo7z/VHkBPSkHNPC/HA/loFagzmxqa8GRS3M/8UUrQ0FmQWVDDn31nCnVr9jq86fR5YwUaBVT1zQX+628WJqcbqO4vv+i4HFEy3Fo5Eu9rVlf866cnkTQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781327401; c=relaxed/simple; bh=iWGtuh7JjQqrtyc0lfzLPHywxbj0DKzoSSxXIEG81fE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BJiF/sFl+Hvo6+D3M0OyDScev6Xwem6kGuMqam7e8PNy8+m5651mBr76zOQjnSVxwbC4qWck2EK6KUsM8fBPOiBcbEEDSderwsMdVQH7EIXPdSI2RE0zC5daGA0bIuukyBDYrk/epftNTon/hXBDwVqO7cHwbPbmcKwdGZaxVsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=dyHeeylu; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="dyHeeylu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=XtXmcCiq3eJia7JzFxANPEPogqTgQiMYpvOYfxZs+RI=; b=dyHeeyluUZy0tNF1xDjbs0cye7 QUcXMQZKt43B3au7afpBnDPKDBhntdCElDqVDjY9EJQgqkojGccgFEKSF/HAeGzL7IL9UiSae5SkO F2CAOSLyLjsg/amwKum+/sSSreXBmAVZf5xM6T7xydiEEWGuUKCqusP80B+3xdQTIegxxtEklg4cg kX70DJ1Hl4m86ch4m88Oh3VMfDgTZW75wmlXoPeV6YVlTO9eNpVtvqb9rvFumP/ZCyUQBzvJ8Sp7f 3Vr289ENtvgX7U8OnsiY48SG+fbD580ulV80A/V/yssae8KDpSSxZ3bxI0qq3A5tjOmAVw5zHDutr NaedRhgg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wYGcz-00000003aTZ-2SiR; Sat, 13 Jun 2026 05:09:53 +0000 From: Al Viro To: linux-mm@kvack.org Cc: Vlastimil Babka , Harry Yoo , linux-fsdevel@vger.kernel.org, Linus Torvalds , Christian Brauner , Jan Kara , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 10/10] make ufs_inode_cache statically allocated Date: Sat, 13 Jun 2026 06:09:51 +0100 Message-ID: <20260613050951.855141-11-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260613050951.855141-1-viro@zeniv.linux.org.uk> References: <20260611171425.1671254-1-viro@zeniv.linux.org.uk> <20260613050951.855141-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Al Viro Content-Type: text/plain; charset="utf-8" A modular example I used for testing... Signed-off-by: Al Viro --- fs/ufs/super.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/ufs/super.c b/fs/ufs/super.c index c4831a8b9b3f..72053bc9c8dc 100644 --- a/fs/ufs/super.c +++ b/fs/ufs/super.c @@ -90,6 +90,7 @@ #include #include #include +#include =20 #include "ufs_fs.h" #include "ufs.h" @@ -1353,7 +1354,8 @@ static int ufs_statfs(struct dentry *dentry, struct k= statfs *buf) return 0; } =20 -static struct kmem_cache * ufs_inode_cachep; +static struct kmem_cache_opaque ufs_inode_cache; +#define ufs_inode_cachep to_kmem_cache(&ufs_inode_cache) =20 static struct inode *ufs_alloc_inode(struct super_block *sb) { @@ -1383,16 +1385,13 @@ static void init_once(void *foo) =20 static int __init init_inodecache(void) { - ufs_inode_cachep =3D kmem_cache_create_usercopy("ufs_inode_cache", + return kmem_cache_setup_usercopy(ufs_inode_cachep, "ufs_inode_cache", sizeof(struct ufs_inode_info), 0, (SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT), offsetof(struct ufs_inode_info, i_u1.i_symlink), sizeof_field(struct ufs_inode_info, i_u1.i_symlink), init_once); - if (ufs_inode_cachep =3D=3D NULL) - return -ENOMEM; - return 0; } =20 static void destroy_inodecache(void) --=20 2.47.3