Skip to contentSkip to conversation

Consolidate creation of kmem caches with "calculated" names

PATCH In review Pavel Emelyanov 2 participants 2 messages Oct 17, 2007 – Oct 18, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Consolidate creation of kmem caches with "calculated" names

Some places in network (like protocol registration and dccp) generate the kmem cache name with snprintf() to create caches for several protocols with similar names.

Make the routine that makes this in one place. Possibly, this is better to be put in mm/sl[uoa]b.c, but I haven't found any other places in kernel that require such functionality, so put this code (temporary?) in net/core/util.c

---

include/net/sock.h +4 -0
index 453c79d..8040d59 100644
@@ -601,6 +601,10 @@ struct proto {
 extern int proto_register(struct proto *prot, int alloc_slab);
 extern void proto_unregister(struct proto *prot);
 
+struct kmem_cache *kmem_cache_create_va(int size, unsigned long flags,
+		char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
+void kmem_cache_destroy_va(struct kmem_cache *);
+
 #ifdef SOCK_REFCNT_DEBUG
 static inline void sk_refcnt_debug_inc(struct sock *sk)
 {
net/core/sock.c +17 -39

89 lines not on this page · raw message

net/core/utils.c +38 -0
index 0bf17da..eccc71b 100644
@@ -293,3 +293,41 @@ out:
 }
 
 EXPORT_SYMBOL(in6_pton);
+
+struct kmem_cache *kmem_cache_create_va(int size, unsigned long flags,
+		char *fmt, ...)
+{
+	char *name, str[64];
+	struct kmem_cache *c;
+	va_list args;
+
+	va_start(args, fmt);
+	vsnprintf(str, sizeof(str), fmt, args);
+	va_end(args);
+
+	name = kstrdup(str, GFP_KERNEL);
+	if (name == NULL)
+		goto err_name;
+
+	c = kmem_cache_create(name, size, 0, flags, NULL);
+	if (c == NULL)
+		goto err_cache;
+
+	return c;
+
+err_cache:
+	kfree(name);
+err_name:
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(kmem_cache_create_va);
+
+void kmem_cache_destroy_va(struct kmem_cache *c)
+{
+	const char *name;
+
+	name = kmem_cache_name(c);
+	kmem_cache_destroy(c);
+	kfree(name);
+}
+EXPORT_SYMBOL_GPL(kmem_cache_destroy_va);
net/dccp/ccid.c +11 -40

83 lines not on this page · raw message

maintainer
#1 lore raw

From: Pavel Emelyanov <[email protected]>
Date: Wed, 17 Oct 2007 17:09:30 +0400

Quoted 10 lines

Some places in network (like protocol registration and dccp) generate the kmem cache name with snprintf() to create caches for several protocols with similar names.

Make the routine that makes this in one place. Possibly, this is better to be put in mm/sl[uoa]b.c, but I haven't found any other places in kernel that require such functionality, so put this code (temporary?) in net/core/util.c

I don't think we should be putting kmem_*() interfaces in a place like net/core/utils.c, please submit that seperately to the SLAB and/or SLUB maintainers, and once that it in we can add the uses to the networking.

Tanks.