mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] kmemleak: Store object reverse references for debugging purposes
Date: Mon, 19 Oct 2009 15:49:34 +0100	[thread overview]
Message-ID: <20091019144934.14221.31614.stgit@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <20091019144602.14221.27128.stgit@pc1117.cambridge.arm.com>

There are some memory leak reports which come and go but are hard to
identify whether they are false positives or not. This patch stores up
to 4 reverse references in an object so that once a leak disappeared,
using "echo dump=<ptr> > debug/kmemleak" would list where an object is
referenced from.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
 mm/kmemleak.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 9610635..998162f 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -110,6 +110,7 @@
 #define SECS_SCAN_WAIT		600	/* subsequent auto scanning delay */
 #define GRAY_LIST_PASSES	25	/* maximum number of gray list scans */
 #define MAX_SCAN_SIZE		4096	/* maximum size of a scanned block */
+#define MAX_REV_REF		4	/* number of reverse references */
 
 #define BYTES_PER_POINTER	sizeof(void *)
 
@@ -156,6 +157,7 @@ struct kmemleak_object {
 	unsigned long jiffies;		/* creation timestamp */
 	pid_t pid;			/* pid of the current task */
 	char comm[TASK_COMM_LEN];	/* executable name */
+	void *rev_ref[MAX_REV_REF];	/* reverse references */
 };
 
 /* flag representing the memory block allocation status */
@@ -379,6 +381,13 @@ static void dump_object_info(struct kmemleak_object *object)
 	pr_notice("  min_count = %d\n", object->min_count);
 	pr_notice("  count = %d\n", object->count);
 	pr_notice("  flags = 0x%lx\n", object->flags);
+	if (object->count) {
+		int i;
+		pr_notice("  referred from:");
+		for (i = 0; i < object->count; i++)
+			printk(" 0x%p", object->rev_ref[i]);
+		printk("\n");
+	}
 	pr_notice("  backtrace:\n");
 	print_stack_trace(&trace, 4);
 }
@@ -1011,8 +1020,12 @@ static void scan_block(void *_start, void *_end,
 		 */
 		spin_lock_irqsave_nested(&object->lock, flags,
 					 SINGLE_DEPTH_NESTING);
+		if (object->count < MAX_REV_REF)
+			object->rev_ref[object->count] = ptr;
+
 		if (!color_white(object)) {
 			/* non-orphan, ignored or new */
+			object->count++;
 			spin_unlock_irqrestore(&object->lock, flags);
 			put_object(object);
 			continue;
@@ -1416,7 +1429,7 @@ static int dump_str_object_info(const char *str)
 	unsigned long addr;
 
 	addr= simple_strtoul(str, NULL, 0);
-	object = find_and_get_object(addr, 0);
+	object = find_and_get_object(addr, 1);
 	if (!object) {
 		pr_info("Unknown object at 0x%08lx\n", addr);
 		return -EINVAL;


  parent reply	other threads:[~2009-10-19 14:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-19 14:49 [PATCH 0/4] Kmemleak patches for 2.6.33 Catalin Marinas
2009-10-19 14:49 ` [PATCH 1/4] kmemleak: Simplify the kmemleak_scan_area() function prototype Catalin Marinas
2009-10-19 14:49 ` [PATCH 2/4] kmemleak: Scan the _ftrace_events section in modules Catalin Marinas
2009-10-20  0:54   ` Rusty Russell
2009-10-20  8:39     ` Catalin Marinas
2009-10-21  0:17       ` Rusty Russell
2009-10-19 14:49 ` Catalin Marinas [this message]
2009-10-19 14:49 ` [PATCH 4/4] kmemleak: Allow two scanning passes before reported an object as leak Catalin Marinas

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=20091019144934.14221.31614.stgit@pc1117.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®