[PATCH 2/2] SLUB: Mark merged slab caches in /proc/slabinfo

From: Pekka Enberg
Date: Tue Sep 14 2010 - 13:06:17 EST


SLUB uses the name of the first slab cache for all merged slab caches. To make
the output of /proc/slabinfo more obvious, append the name of each merged slab
cache to s->name.

An example output looks like this:

bip-16,ip_dst_cache,kioctx 42 42 [snip]

Cc: Christoph Lameter <cl@xxxxxxxxx>
Cc: David Rientjes <rientjes@xxxxxxxxxx>
Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
mm/slub.c | 41 ++++++++++++++++++++++++++++++-----------
1 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 0704288..6b08256 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3149,6 +3149,34 @@ void __init kmem_cache_init_late(void)
{
}

+static int kmem_merge_names(struct kmem_cache *s, const char *name)
+{
+ size_t new_size;
+ char *new_name;
+
+ /* Don't append name to merged name more than once */
+ if (strstr(s->name, name))
+ return 0;
+
+ /* Comma separated and NULL terminated. */
+ new_size = strlen(s->name) + strlen(name) + 2;
+
+ new_name = kmalloc(new_size, GFP_KERNEL);
+ if (!new_name)
+ return -ENOMEM;
+
+ snprintf(new_name, new_size, "%s,%s", s->name, name);
+
+ if (s->flags & SLAB_DYNAMIC_NAME)
+ kfree(s->name);
+
+ s->name = new_name;
+
+ s->flags |= SLAB_DYNAMIC_NAME;
+
+ return 0;
+}
+
/*
* Find a mergeable slab cache
*/
@@ -3221,17 +3249,8 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
down_write(&slub_lock);
s = find_mergeable(size, align, flags, name, ctor);
if (s) {
- if (!(s->flags & SLAB_DYNAMIC_NAME)) {
- const char *new_name;
-
- new_name = kstrdup(s->name, GFP_KERNEL);
- if (!new_name)
- goto err;
-
- s->name = new_name;
-
- s->flags |= SLAB_DYNAMIC_NAME;
- }
+ if (kmem_merge_names(s, name))
+ goto err;

s->refcount++;
/*
--
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/