[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <806cbde4-fc0b-7bf7-d22a-2205b46eaa96@gentwo.org>
Date: Thu, 15 Jan 2026 11:10:00 -0800 (PST)
From: "Christoph Lameter (Ampere)" <cl@...two.org>
To: Al Viro <viro@...iv.linux.org.uk>
cc: linux-mm@...ck.org, Vlastimil Babka <vbabka@...e.cz>,
Harry Yoo <harry.yoo@...cle.com>, linux-fsdevel@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
Mateusz Guzik <mguzik@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH 00/15] kmem_cache instances with static storage
duration
On Thu, 15 Jan 2026, Al Viro wrote:
> > Would that an deserve a separate abstraction so it is usable by other
> > subsystems?
>
> *shrug*
>
> Probably could be done, but I don't see many applications for that.
> Note that in this case objects are either of "never destroyed at all"
> sort or "never destroyed until rmmod" one, and the latter already
> requires a pretty careful handling.
>
> If it's dynamically allocated, we have much more straightforward
> mechanisms - see e.g. struct mount vs. struct vfsmount, where most
> of the containing object is opaque for everyone outside of several
> files in fs/*.c and the public part is embedded into it.
>
> I'm not saying that no other similar cases exist, but until somebody
> comes up with other examples...
Internal functions exist in the slab allocator that do what you want if
the opaqueness requirement is dropped. F.e. for the creation of kmalloc
caches we use do_kmem_cache_create():
void __init create_boot_cache(struct kmem_cache *s, const char *name,
unsigned int size, slab_flags_t flags,
unsigned int useroffset, unsigned int usersize)
{
int err;
unsigned int align = ARCH_KMALLOC_MINALIGN;
struct kmem_cache_args kmem_args = {};
/*
* kmalloc caches guarantee alignment of at least the largest
* power-of-two divisor of the size. For power-of-two sizes,
* it is the size itself.
*/
if (flags & SLAB_KMALLOC)
align = max(align, 1U << (ffs(size) - 1));
kmem_args.align = calculate_alignment(flags, align, size);
#ifdef CONFIG_HARDENED_USERCOPY
kmem_args.useroffset = useroffset;
kmem_args.usersize = usersize;
#endif
err = do_kmem_cache_create(s, name, size, &kmem_args, flags);
if (err)
panic("Creation of kmalloc slab %s size=%u failed. Reason %d\n",
name, size, err);
s->refcount = -1; /* Exempt from merging for now */
}
Powered by blists - more mailing lists