public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: torvalds@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Pekka Enberg <penberg@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>
Subject: [PATCH v2 2/2] SLUB: Mark merged slab caches in /proc/slabinfo
Date: Tue, 14 Sep 2010 21:48:21 +0300	[thread overview]
Message-ID: <1284490101-2362-2-git-send-email-penberg@kernel.org> (raw)
In-Reply-To: <1284490101-2362-1-git-send-email-penberg@kernel.org>

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 of /proc/slabinfo with this patch looks like this:

  kmalloc-8192         544    544   8192    4    8 : tunables    0
  kmalloc-4096+names_cache+biovec-256+sgpool-128+ecryptfs_headers
  kmalloc-2048+biovec-128+sgpool-64    400    416   2048   16    8
  kmalloc-1024+biovec-64+sgpool-32    436    496   1024   16    4 :
  kmalloc-512+task_xstate+skbuff_fclone_cache+sgpool-16   1060   10
  kmalloc-256+mnt_cache+skbuff_head_cache+biovec-16+sgpool-8+arp_   [ snip ]
  kmalloc-128+pid+bip-1+eventpoll_epi+request_sock_TCP+ip_mrt_cac
  kmalloc-64+fs_cache+biovec-4+blkdev_ioc+inet_peer_cache+tcp_bin
  kmalloc-32+ip_fib_alias+dnotify_struct+inotify_event_private_da
  kmalloc-16+biovec-1+ecryptfs_file_cache+dm_rq_clone_bio_info+dm
  kmalloc-8           5119   5120      8  512    1 : tunables    0
  kmalloc-192+cred_jar+key_jar+filp+bip-4+bio-0+request_sock_TCPv
  kmalloc-96           924   1008     96   42    1 : tunables    0
  kmem_cache_node      128    128     64   64    1 : tunables    0

Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 mm/slub.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index a31c033..77e4438 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3161,6 +3161,40 @@ void __init kmem_cache_init_late(void)
 }
 
 /*
+ * This limit is part of /proc/slabinfo ABI. It has never been enforced by the
+ * kernel but userspace programs such as "slabtop" expect it.
+ */
+#define MAX_SLAB_NAME_LEN	63
+
+static int kmem_merge_names(struct kmem_cache *s, const char *name)
+{
+	size_t new_size;
+	char *new_name;
+
+	if (strlen(s->name) >= MAX_SLAB_NAME_LEN)
+		return 0;
+
+	/* Don't append name to merged name more than once */
+	if (strstr(s->name, name))
+		return 0;
+
+	new_size = strlen(s->name) + strlen(name) + 2;
+	if (new_size > (MAX_SLAB_NAME_LEN + 1))
+		new_size = MAX_SLAB_NAME_LEN + 1;	/* NULL terminate */
+
+	new_name = kmalloc(new_size, GFP_KERNEL);
+	if (!new_name)
+		return -ENOMEM;
+
+	snprintf(new_name, new_size, "%s+%s", s->name, name);
+
+	kfree(s->name);
+	s->name = new_name;
+
+	return 0;
+}
+
+/*
  * Find a mergeable slab cache
  */
 static int slab_unmergeable(struct kmem_cache *s)
@@ -3233,6 +3267,9 @@ 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 (kmem_merge_names(s, name))
+			goto err;
+
 		s->refcount++;
 		/*
 		 * Adjust the object sizes so that we clear
-- 
1.6.3.3


  reply	other threads:[~2010-09-14 18:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-14 18:48 [PATCH v2 1/2] SLUB: Fix merged slab cache names Pekka Enberg
2010-09-14 18:48 ` Pekka Enberg [this message]
2010-09-14 20:00   ` [PATCH v2 2/2] SLUB: Mark merged slab caches in /proc/slabinfo David Rientjes
2010-09-14 20:05     ` Linus Torvalds
2010-09-14 20:11       ` Pekka Enberg
2010-09-14 20:56         ` Linus Torvalds
2010-09-14 20:56       ` David Rientjes
2010-09-14 21:00         ` Pekka Enberg
2010-09-15  0:02           ` David Rientjes
2010-09-15 11:16             ` Theodore Tso
2010-09-15 20:33               ` David Rientjes
2010-09-15 22:25                 ` Ted Ts'o
2010-09-15 22:53                   ` David Rientjes
2010-09-16 17:39                     ` Christoph Lameter
2010-09-16 17:49                       ` Linus Torvalds
2010-09-16 22:08                         ` Tony Luck
2010-09-14 18:59 ` [PATCH v2 1/2] SLUB: Fix merged slab cache names Christoph Lameter
2010-09-14 19:32   ` Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284490101-2362-2-git-send-email-penberg@kernel.org \
    --to=penberg@kernel.org \
    --cc=cl@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox