From: Sergey Senozhatsky <sergey.senozhatsky@mail.by>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: kmemleak hexdump proposal
Date: Tue, 14 Jul 2009 13:57:11 +0300 [thread overview]
Message-ID: <20090714105709.GB2929@localdomain.by> (raw)
In-Reply-To: <1247567641.28240.51.camel@pc1117.cambridge.arm.com>
[-- Attachment #1: Type: text/plain, Size: 2649 bytes --]
On (07/14/09 11:34), Catalin Marinas wrote:
> On Tue, 2009-07-14 at 13:33 +0300, Sergey Senozhatsky wrote:
> > On (07/14/09 11:07), Catalin Marinas wrote:
> > Am I understand correct that no way for user to on/off hexdump?
> > /* no need for atomic_t kmemleak_hex_dump */
>
> Yes. Two lines aren't really too much so we can always have them
> displayed.
>
Agree.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 5aabd41..f7b74ac 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -161,6 +161,15 @@ struct kmemleak_object {
/* flag set on newly allocated objects */
#define OBJECT_NEW (1 << 3)
+/* number of bytes to print per line; must be 16 or 32 */
+#define HEX_ROW_SIZE 16
+/* number of bytes to print at a time (1, 2, 4, 8) */
+#define HEX_GROUP_SIZE 1
+/* include ASCII after the hex output */
+#define HEX_ASCII 1
+/* max number of lines to be printed */
+#define HEX_MAX_LINES 2
+
/* the list of all allocated objects */
static LIST_HEAD(object_list);
/* the list of gray-colored objects (see color_gray comment below) */
@@ -254,6 +263,35 @@ static void kmemleak_disable(void);
kmemleak_disable(); \
} while (0)
+
+/*
+ * Printing of the objects hex dump to the seq file. The number on lines
+ * to be printed is limited to HEX_MAX_LINES to prevent seq file spamming.
+ * The actual number of printed bytes depends on HEX_ROW_SIZE.
+ * It must be called with the object->lock held.
+ */
+static void hex_dump_object(struct seq_file *seq,
+ struct kmemleak_object *object)
+{
+ const u8 *ptr = (const u8 *)object->pointer;
+ /* Limit the number of lines to HEX_MAX_LINES. */
+ int len = min(object->size, (size_t)(HEX_MAX_LINES * HEX_ROW_SIZE));
+ int i, remaining = len;
+ unsigned char linebuf[200];
+
+ seq_printf(seq, " hex dump (first %d bytes):\n", len);
+
+ for (i = 0; i < len; i += HEX_ROW_SIZE) {
+ int linelen = min(remaining, HEX_ROW_SIZE);
+ remaining -= HEX_ROW_SIZE;
+ hex_dump_to_buffer(ptr + i, linelen, HEX_ROW_SIZE,
+ HEX_GROUP_SIZE, linebuf,
+ sizeof(linebuf), HEX_ASCII);
+
+ seq_printf(seq, " %s\n", linebuf);
+ }
+}
+
/*
* Object colors, encoded with count and min_count:
* - white - orphan object, not enough references to it (count < min_count)
@@ -304,6 +342,9 @@ static void print_unreferenced(struct seq_file *seq,
object->pointer, object->size);
seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n",
object->comm, object->pid, object->jiffies);
+
+ hex_dump_object(seq, object);
+
seq_printf(seq, " backtrace:\n");
for (i = 0; i < object->trace_len; i++) {
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 315 bytes --]
next prev parent reply other threads:[~2009-07-14 10:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-28 17:36 Sergey Senozhatsky
2009-06-29 9:43 ` Pekka Enberg
2009-06-29 9:48 ` Catalin Marinas
2009-06-29 10:19 ` Sergey Senozhatsky
2009-06-29 10:19 ` Pekka Enberg
2009-06-29 10:38 ` Catalin Marinas
2009-06-29 10:42 ` Pekka Enberg
2009-06-29 10:52 ` Sergey Senozhatsky
2009-06-29 20:10 ` Sergey Senozhatsky
2009-07-14 10:07 ` Catalin Marinas
2009-07-14 10:33 ` Sergey Senozhatsky
2009-07-14 10:34 ` Catalin Marinas
2009-07-14 10:57 ` Sergey Senozhatsky [this message]
2009-07-14 13:39 ` Catalin Marinas
2009-07-14 14:03 ` Sergey Senozhatsky
2009-07-14 14:17 ` Catalin Marinas
2009-07-14 15:22 ` kmemleak: Printing of the objects hex dump Sergey Senozhatsky
2009-06-29 10:45 ` kmemleak hexdump proposal Sergey Senozhatsky
2009-06-29 10:58 ` Catalin Marinas
2009-06-29 11:08 ` Sergey Senozhatsky
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=20090714105709.GB2929@localdomain.by \
--to=sergey.senozhatsky@mail.by \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=penberg@cs.helsinki.fi \
/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