rpms/kernel/devel linux-2.6-kmemleak-improvements.patch, NONE, 1.1 TODO, 1.63, 1.64 kernel.spec, 1.1594, 1.1595 linux-2.6-kmemleak-scan-stack-by-default.patch, 1.1, NONE
Dave Jones
davej at fedoraproject.org
Fri Jun 26 14:42:29 UTC 2009
Author: davej
Update of /cvs/pkgs/rpms/kernel/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv17459
Modified Files:
TODO kernel.spec
Added Files:
linux-2.6-kmemleak-improvements.patch
Removed Files:
linux-2.6-kmemleak-scan-stack-by-default.patch
Log Message:
Further improvements to kmemleak
linux-2.6-kmemleak-improvements.patch:
--- NEW FILE linux-2.6-kmemleak-improvements.patch ---
>From davej Fri Jun 26 10:15:33 2009
Return-Path: Catalin.Marinas at arm.com
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
gelk.kernelslacker.org
X-Spam-Level:
X-Spam-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00,
RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.2.5
Received: from mail.corp.redhat.com [10.5.5.51]
by gelk.kernelslacker.org with IMAP (fetchmail-6.3.9)
for <davej at localhost> (single-drop); Fri, 26 Jun 2009 10:15:33 -0400 (EDT)
Received: from zmta02.collab.prod.int.phx2.redhat.com (LHLO
zmta02.collab.prod.int.phx2.redhat.com) (10.5.5.32) by
mail04.corp.redhat.com with LMTP; Fri, 26 Jun 2009 10:13:10 -0400 (EDT)
Received: from localhost (localhost.localdomain [127.0.0.1])
by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id 6C7BD9D7C6
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:10 -0400 (EDT)
Received: from zmta02.collab.prod.int.phx2.redhat.com ([127.0.0.1])
by localhost (zmta02.collab.prod.int.phx2.redhat.com [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id IbOtCT8gH9pG for <davej at redhat.com>;
Fri, 26 Jun 2009 10:13:10 -0400 (EDT)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254])
by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id 2BCB39D7C3
for <davej at mail.corp.redhat.com>; Fri, 26 Jun 2009 10:13:10 -0400 (EDT)
Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31])
by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5QED9jF000310
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:09 -0400
Received: from cam-admin0.cambridge.arm.com (cam-admin0.cambridge.arm.com [193.131.176.58])
by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n5QECtVW020483
for <davej at redhat.com>; Fri, 26 Jun 2009 10:12:56 -0400
Received: from cam-owa1.Emea.Arm.com (cam-owa1.emea.arm.com [10.1.255.62])
by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id n5QE9qZm009578;
Fri, 26 Jun 2009 15:09:52 +0100 (BST)
Received: from pc1117.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0);
Fri, 26 Jun 2009 15:12:41 +0100
Subject: [PATCH 1/4] kmemleak: Enable task stacks scanning by default
To: linux-kernel at vger.kernel.org
From: Catalin Marinas <catalin.marinas at arm.com>
Cc: Dave Jones <davej at redhat.com>, Ingo Molnar <mingo at elte.hu>,
Pekka Enberg <penberg at cs.helsinki.fi>,
Sergey Senozhatsky <sergey.senozhatsky at mail.by>
Date: Fri, 26 Jun 2009 15:12:41 +0100
Message-ID: <20090626141241.31504.48118.stgit at pc1117.cambridge.arm.com>
In-Reply-To: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
References: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
User-Agent: StGit/0.14.3.387.geb0c.dirty
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 26 Jun 2009 14:12:41.0721 (UTC) FILETIME=[2B1E5690:01C9F668]
X-RedHat-Spam-Score: -3.954
X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254
X-Scanned-By: MIMEDefang 2.63 on 172.16.48.31
Status: RO
Content-Length: 1805
Lines: 42
This is to reduce the number of false positives reported.
Signed-off-by: Catalin Marinas <catalin.marinas at arm.com>
---
Documentation/kmemleak.txt | 8 ++++----
mm/kmemleak.c | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt
index f655308..9426e94 100644
--- a/Documentation/kmemleak.txt
+++ b/Documentation/kmemleak.txt
@@ -31,12 +31,12 @@ Memory scanning parameters can be modified at run-time by writing to the
/sys/kernel/debug/kmemleak file. The following parameters are supported:
off - disable kmemleak (irreversible)
- stack=on - enable the task stacks scanning
+ stack=on - enable the task stacks scanning (default)
stack=off - disable the tasks stacks scanning
- scan=on - start the automatic memory scanning thread
+ scan=on - start the automatic memory scanning thread (default)
scan=off - stop the automatic memory scanning thread
- scan=<secs> - set the automatic memory scanning period in seconds (0
- to disable it)
+ scan=<secs> - set the automatic memory scanning period in seconds
+ (default 600, 0 to stop the automatic scanning)
Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on
the kernel command line.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 17096d1..a38418a 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -194,7 +194,7 @@ static unsigned long jiffies_min_age;
/* delay between automatic memory scannings */
static signed long jiffies_scan_wait;
/* enables or disables the task stacks scanning */
-static int kmemleak_stack_scan;
+static int kmemleak_stack_scan = 1;
/* mutex protecting the memory scanning */
static DEFINE_MUTEX(scan_mutex);
/* mutex protecting the access to the /sys/kernel/debug/kmemleak file */
>From davej Fri Jun 26 10:15:41 2009
Return-Path: Catalin.Marinas at arm.com
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
gelk.kernelslacker.org
X-Spam-Level:
X-Spam-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00,
RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.2.5
Received: from mail.corp.redhat.com [10.5.5.51]
by gelk.kernelslacker.org with IMAP (fetchmail-6.3.9)
for <davej at localhost> (single-drop); Fri, 26 Jun 2009 10:15:41 -0400 (EDT)
Received: from zmta02.collab.prod.int.phx2.redhat.com (LHLO
zmta02.collab.prod.int.phx2.redhat.com) (10.5.5.32) by
mail04.corp.redhat.com with LMTP; Fri, 26 Jun 2009 10:13:20 -0400 (EDT)
Received: from localhost (localhost.localdomain [127.0.0.1])
by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id 5D76C9D7C6
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:20 -0400 (EDT)
Received: from zmta02.collab.prod.int.phx2.redhat.com ([127.0.0.1])
by localhost (zmta02.collab.prod.int.phx2.redhat.com [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 7iR40mDJFi2U for <davej at redhat.com>;
Fri, 26 Jun 2009 10:13:20 -0400 (EDT)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254])
by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id 1DD339D7C3
for <davej at mail.corp.redhat.com>; Fri, 26 Jun 2009 10:13:20 -0400 (EDT)
Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31])
by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5QEDJ4i000372
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:19 -0400
Received: from cam-admin0.cambridge.arm.com (cam-admin0.cambridge.arm.com [193.131.176.58])
by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n5QED4oW020562
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:05 -0400
Received: from cam-owa1.Emea.Arm.com (cam-owa1.emea.arm.com [10.1.255.62])
by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id n5QE9vZm009583;
Fri, 26 Jun 2009 15:09:57 +0100 (BST)
Received: from pc1117.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0);
Fri, 26 Jun 2009 15:12:47 +0100
Subject: [PATCH 2/4] kmemleak: Simplify the reports logged by the scanning
thread
To: linux-kernel at vger.kernel.org
From: Catalin Marinas <catalin.marinas at arm.com>
Cc: Dave Jones <davej at redhat.com>, Ingo Molnar <mingo at elte.hu>,
Pekka Enberg <penberg at cs.helsinki.fi>,
Sergey Senozhatsky <sergey.senozhatsky at mail.by>
Date: Fri, 26 Jun 2009 15:12:46 +0100
Message-ID: <20090626141246.31504.74477.stgit at pc1117.cambridge.arm.com>
In-Reply-To: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
References: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
User-Agent: StGit/0.14.3.387.geb0c.dirty
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 26 Jun 2009 14:12:47.0425 (UTC) FILETIME=[2E84B310:01C9F668]
X-RedHat-Spam-Score: -3.955
X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254
X-Scanned-By: MIMEDefang 2.63 on 172.16.48.31
Status: RO
Content-Length: 5037
Lines: 146
Because of false positives, the memory scanning thread may print too
much information. This patch changes the scanning thread to only print
the number of newly suspected leaks. Further information can be read
from the /sys/kernel/debug/kmemleak file.
Signed-off-by: Catalin Marinas <catalin.marinas at arm.com>
---
Documentation/kmemleak.txt | 6 ++--
mm/kmemleak.c | 61 ++++++++++++--------------------------------
2 files changed, 19 insertions(+), 48 deletions(-)
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt
index 9426e94..c06f7ba 100644
--- a/Documentation/kmemleak.txt
+++ b/Documentation/kmemleak.txt
@@ -16,9 +16,9 @@ Usage
-----
CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel
-thread scans the memory every 10 minutes (by default) and prints any new
-unreferenced objects found. To trigger an intermediate scan and display
-all the possible memory leaks:
+thread scans the memory every 10 minutes (by default) and prints the
+number of new unreferenced objects found. To trigger an intermediate
+scan and display the details of all the possible memory leaks:
# mount -t debugfs nodev /sys/kernel/debug/
# cat /sys/kernel/debug/kmemleak
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index a38418a..4130a48 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -279,15 +279,6 @@ static int color_gray(const struct kmemleak_object *object)
}
/*
- * Objects are considered referenced if their color is gray and they have not
- * been deleted.
- */
-static int referenced_object(struct kmemleak_object *object)
-{
- return (object->flags & OBJECT_ALLOCATED) && color_gray(object);
-}
-
-/*
* Objects are considered unreferenced only if their color is white, they have
* not be deleted and have a minimum age to avoid false positives caused by
* pointers temporarily stored in CPU registers.
@@ -299,38 +290,23 @@ static int unreferenced_object(struct kmemleak_object *object)
}
/*
- * Printing of the (un)referenced objects information, either to the seq file
- * or to the kernel log. The print_referenced/print_unreferenced functions
- * must be called with the object->lock held.
+ * Printing of the unreferenced objects information to the seq file. The
+ * print_unreferenced function must be called with the object->lock held.
*/
-#define print_helper(seq, x...) do { \
- struct seq_file *s = (seq); \
- if (s) \
- seq_printf(s, x); \
- else \
- pr_info(x); \
-} while (0)
-
-static void print_referenced(struct kmemleak_object *object)
-{
- pr_info("referenced object 0x%08lx (size %zu)\n",
- object->pointer, object->size);
-}
-
static void print_unreferenced(struct seq_file *seq,
struct kmemleak_object *object)
{
int i;
- print_helper(seq, "unreferenced object 0x%08lx (size %zu):\n",
- object->pointer, object->size);
- print_helper(seq, " comm \"%s\", pid %d, jiffies %lu\n",
- object->comm, object->pid, object->jiffies);
- print_helper(seq, " backtrace:\n");
+ seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n",
+ object->pointer, object->size);
+ seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n",
+ object->comm, object->pid, object->jiffies);
+ seq_printf(seq, " backtrace:\n");
for (i = 0; i < object->trace_len; i++) {
void *ptr = (void *)object->trace[i];
- print_helper(seq, " [<%p>] %pS\n", ptr, ptr);
+ seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
}
}
@@ -571,8 +547,6 @@ static void delete_object(unsigned long ptr)
* cannot be freed when it is being scanned.
*/
spin_lock_irqsave(&object->lock, flags);
- if (object->flags & OBJECT_REPORTED)
- print_referenced(object);
object->flags &= ~OBJECT_ALLOCATED;
spin_unlock_irqrestore(&object->lock, flags);
put_object(object);
@@ -1073,33 +1047,30 @@ static int kmemleak_scan_thread(void *arg)
while (!kthread_should_stop()) {
struct kmemleak_object *object;
signed long timeout = jiffies_scan_wait;
+ int new_leaks = 0;
mutex_lock(&scan_mutex);
kmemleak_scan();
- reported_leaks = 0;
rcu_read_lock();
list_for_each_entry_rcu(object, &object_list, object_list) {
unsigned long flags;
- if (reported_leaks >= REPORTS_NR)
- break;
spin_lock_irqsave(&object->lock, flags);
- if (!(object->flags & OBJECT_REPORTED) &&
- unreferenced_object(object)) {
- print_unreferenced(NULL, object);
+ if (unreferenced_object(object) &&
+ !(object->flags & OBJECT_REPORTED)) {
object->flags |= OBJECT_REPORTED;
- reported_leaks++;
- } else if ((object->flags & OBJECT_REPORTED) &&
- referenced_object(object)) {
- print_referenced(object);
- object->flags &= ~OBJECT_REPORTED;
+ new_leaks++;
}
spin_unlock_irqrestore(&object->lock, flags);
}
rcu_read_unlock();
+ if (new_leaks)
+ pr_info("%d new suspected memory leaks (see "
+ "/sys/kernel/debug/kmemleak)\n", new_leaks);
+
mutex_unlock(&scan_mutex);
/* wait before the next scan */
while (timeout && !kthread_should_stop())
>From davej Fri Jun 26 10:15:57 2009
Return-Path: Catalin.Marinas at arm.com
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
gelk.kernelslacker.org
X-Spam-Level:
X-Spam-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00,
RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.2.5
Received: from mail.corp.redhat.com [10.5.5.51]
by gelk.kernelslacker.org with IMAP (fetchmail-6.3.9)
for <davej at localhost> (single-drop); Fri, 26 Jun 2009 10:15:57 -0400 (EDT)
Received: from zmta03.collab.prod.int.phx2.redhat.com (LHLO
zmta03.collab.prod.int.phx2.redhat.com) (10.5.5.33) by
mail04.corp.redhat.com with LMTP; Fri, 26 Jun 2009 10:13:29 -0400 (EDT)
Received: from localhost (localhost.localdomain [127.0.0.1])
by zmta03.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id 10EE24E14A
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:29 -0400 (EDT)
Received: from zmta03.collab.prod.int.phx2.redhat.com ([127.0.0.1])
by localhost (zmta03.collab.prod.int.phx2.redhat.com [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id OBMrB64oq7SH for <davej at redhat.com>;
Fri, 26 Jun 2009 10:13:28 -0400 (EDT)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254])
by zmta03.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id B88184E14D
for <davej at mail.corp.redhat.com>; Fri, 26 Jun 2009 10:13:28 -0400 (EDT)
Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31])
by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5QEDR2C000447
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:27 -0400
Received: from cam-admin0.cambridge.arm.com (cam-admin0.cambridge.arm.com [193.131.176.58])
by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n5QEDEXm020641
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:14 -0400
Received: from cam-owa1.Emea.Arm.com (cam-owa1.emea.arm.com [10.1.255.62])
by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id n5QEA3Zm009598;
Fri, 26 Jun 2009 15:10:03 +0100 (BST)
Received: from pc1117.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0);
Fri, 26 Jun 2009 15:12:53 +0100
Subject: [PATCH 3/4] kmemleak: Do not trigger a scan when reading the
debug/kmemleak file
To: linux-kernel at vger.kernel.org
From: Catalin Marinas <catalin.marinas at arm.com>
Cc: Dave Jones <davej at redhat.com>, Ingo Molnar <mingo at elte.hu>,
Pekka Enberg <penberg at cs.helsinki.fi>,
Sergey Senozhatsky <sergey.senozhatsky at mail.by>
Date: Fri, 26 Jun 2009 15:12:52 +0100
Message-ID: <20090626141252.31504.62724.stgit at pc1117.cambridge.arm.com>
In-Reply-To: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
References: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
User-Agent: StGit/0.14.3.387.geb0c.dirty
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 26 Jun 2009 14:12:53.0143 (UTC) FILETIME=[31ED3270:01C9F668]
X-RedHat-Spam-Score: -3.955
X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254
X-Scanned-By: MIMEDefang 2.63 on 172.16.48.31
Status: RO
Content-Length: 8468
Lines: 256
Since there is a kernel thread for automatically scanning the memory, it
makes sense for the debug/kmemleak file to only show its findings. This
patch also adds support for "echo scan > debug/kmemleak" to trigger an
intermediate memory scan and eliminates the kmemleak_mutex (scan_mutex
covers all the cases now).
Signed-off-by: Catalin Marinas <catalin.marinas at arm.com>
---
Documentation/kmemleak.txt | 9 +++-
mm/kmemleak.c | 90 ++++++++++++++++++++------------------------
2 files changed, 47 insertions(+), 52 deletions(-)
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt
index c06f7ba..8906803 100644
--- a/Documentation/kmemleak.txt
+++ b/Documentation/kmemleak.txt
@@ -17,12 +17,16 @@ Usage
CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel
thread scans the memory every 10 minutes (by default) and prints the
-number of new unreferenced objects found. To trigger an intermediate
-scan and display the details of all the possible memory leaks:
+number of new unreferenced objects found. To display the details of all
+the possible memory leaks:
# mount -t debugfs nodev /sys/kernel/debug/
# cat /sys/kernel/debug/kmemleak
+To trigger an intermediate memory scan:
+
+ # echo scan > /sys/kernel/debug/kmemleak
+
Note that the orphan objects are listed in the order they were allocated
and one object at the beginning of the list may cause other subsequent
objects to be reported as orphan.
@@ -37,6 +41,7 @@ Memory scanning parameters can be modified at run-time by writing to the
scan=off - stop the automatic memory scanning thread
scan=<secs> - set the automatic memory scanning period in seconds
(default 600, 0 to stop the automatic scanning)
+ scan - trigger a memory scan
Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on
the kernel command line.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 4130a48..e96e0ec 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -48,10 +48,10 @@
* scanned. This list is only modified during a scanning episode when the
* scan_mutex is held. At the end of a scan, the gray_list is always empty.
* Note that the kmemleak_object.use_count is incremented when an object is
- * added to the gray_list and therefore cannot be freed
- * - kmemleak_mutex (mutex): prevents multiple users of the "kmemleak" debugfs
- * file together with modifications to the memory scanning parameters
- * including the scan_thread pointer
+ * added to the gray_list and therefore cannot be freed. This mutex also
+ * prevents multiple users of the "kmemleak" debugfs file together with
+ * modifications to the memory scanning parameters including the scan_thread
+ * pointer
*
* The kmemleak_object structures have a use_count incremented or decremented
* using the get_object()/put_object() functions. When the use_count becomes
@@ -195,10 +195,8 @@ static unsigned long jiffies_min_age;
static signed long jiffies_scan_wait;
/* enables or disables the task stacks scanning */
static int kmemleak_stack_scan = 1;
-/* mutex protecting the memory scanning */
+/* protects the memory scanning, parameters and debug/kmemleak file access */
static DEFINE_MUTEX(scan_mutex);
-/* mutex protecting the access to the /sys/kernel/debug/kmemleak file */
-static DEFINE_MUTEX(kmemleak_mutex);
/* number of leaks reported (for limitation purposes) */
static int reported_leaks;
@@ -927,6 +925,7 @@ static void kmemleak_scan(void)
struct kmemleak_object *object, *tmp;
struct task_struct *task;
int i;
+ int new_leaks = 0;
/* prepare the kmemleak_object's */
rcu_read_lock();
@@ -1024,6 +1023,26 @@ static void kmemleak_scan(void)
object = tmp;
}
WARN_ON(!list_empty(&gray_list));
+
+ /*
+ * Scanning result reporting.
+ */
+ rcu_read_lock();
+ list_for_each_entry_rcu(object, &object_list, object_list) {
+ spin_lock_irqsave(&object->lock, flags);
+ if (unreferenced_object(object) &&
+ !(object->flags & OBJECT_REPORTED)) {
+ object->flags |= OBJECT_REPORTED;
+ new_leaks++;
+ }
+ spin_unlock_irqrestore(&object->lock, flags);
+ }
+ rcu_read_unlock();
+
+ if (new_leaks)
+ pr_info("%d new suspected memory leaks (see "
+ "/sys/kernel/debug/kmemleak)\n", new_leaks);
+
}
/*
@@ -1045,33 +1064,12 @@ static int kmemleak_scan_thread(void *arg)
}
while (!kthread_should_stop()) {
- struct kmemleak_object *object;
signed long timeout = jiffies_scan_wait;
- int new_leaks = 0;
mutex_lock(&scan_mutex);
-
kmemleak_scan();
-
- rcu_read_lock();
- list_for_each_entry_rcu(object, &object_list, object_list) {
- unsigned long flags;
-
- spin_lock_irqsave(&object->lock, flags);
- if (unreferenced_object(object) &&
- !(object->flags & OBJECT_REPORTED)) {
- object->flags |= OBJECT_REPORTED;
- new_leaks++;
- }
- spin_unlock_irqrestore(&object->lock, flags);
- }
- rcu_read_unlock();
-
- if (new_leaks)
- pr_info("%d new suspected memory leaks (see "
- "/sys/kernel/debug/kmemleak)\n", new_leaks);
-
mutex_unlock(&scan_mutex);
+
/* wait before the next scan */
while (timeout && !kthread_should_stop())
timeout = schedule_timeout_interruptible(timeout);
@@ -1084,7 +1082,7 @@ static int kmemleak_scan_thread(void *arg)
/*
* Start the automatic memory scanning thread. This function must be called
- * with the kmemleak_mutex held.
+ * with the scan_mutex held.
*/
void start_scan_thread(void)
{
@@ -1099,7 +1097,7 @@ void start_scan_thread(void)
/*
* Stop the automatic memory scanning thread. This function must be called
- * with the kmemleak_mutex held.
+ * with the scan_mutex held.
*/
void stop_scan_thread(void)
{
@@ -1119,10 +1117,8 @@ static void *kmemleak_seq_start(struct seq_file *seq, loff_t *pos)
struct kmemleak_object *object;
loff_t n = *pos;
- if (!n) {
- kmemleak_scan();
+ if (!n)
reported_leaks = 0;
- }
if (reported_leaks >= REPORTS_NR)
return NULL;
@@ -1206,13 +1202,10 @@ static int kmemleak_open(struct inode *inode, struct file *file)
if (!atomic_read(&kmemleak_enabled))
return -EBUSY;
- ret = mutex_lock_interruptible(&kmemleak_mutex);
+ ret = mutex_lock_interruptible(&scan_mutex);
if (ret < 0)
goto out;
if (file->f_mode & FMODE_READ) {
- ret = mutex_lock_interruptible(&scan_mutex);
- if (ret < 0)
- goto kmemleak_unlock;
ret = seq_open(file, &kmemleak_seq_ops);
if (ret < 0)
goto scan_unlock;
@@ -1221,8 +1214,6 @@ static int kmemleak_open(struct inode *inode, struct file *file)
scan_unlock:
mutex_unlock(&scan_mutex);
-kmemleak_unlock:
- mutex_unlock(&kmemleak_mutex);
out:
return ret;
}
@@ -1231,11 +1222,9 @@ static int kmemleak_release(struct inode *inode, struct file *file)
{
int ret = 0;
- if (file->f_mode & FMODE_READ) {
+ if (file->f_mode & FMODE_READ)
seq_release(inode, file);
- mutex_unlock(&scan_mutex);
- }
- mutex_unlock(&kmemleak_mutex);
+ mutex_unlock(&scan_mutex);
return ret;
}
@@ -1250,6 +1239,7 @@ static int kmemleak_release(struct inode *inode, struct file *file)
* scan=off - stop the automatic memory scanning thread
* scan=... - set the automatic memory scanning period in seconds (0 to
* disable it)
+ * scan - trigger a memory scan
*/
static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
size_t size, loff_t *ppos)
@@ -1287,7 +1277,9 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
jiffies_scan_wait = msecs_to_jiffies(secs * 1000);
start_scan_thread();
}
- } else
+ } else if (strncmp(buf, "scan", 4) == 0)
+ kmemleak_scan();
+ else
return -EINVAL;
/* ignore the rest of the buffer, only one command at a time */
@@ -1312,11 +1304,9 @@ static int kmemleak_cleanup_thread(void *arg)
{
struct kmemleak_object *object;
- mutex_lock(&kmemleak_mutex);
+ mutex_lock(&scan_mutex);
stop_scan_thread();
- mutex_unlock(&kmemleak_mutex);
- mutex_lock(&scan_mutex);
rcu_read_lock();
list_for_each_entry_rcu(object, &object_list, object_list)
delete_object(object->pointer);
@@ -1458,9 +1448,9 @@ static int __init kmemleak_late_init(void)
&kmemleak_fops);
if (!dentry)
pr_warning("Failed to create the debugfs kmemleak file\n");
- mutex_lock(&kmemleak_mutex);
+ mutex_lock(&scan_mutex);
start_scan_thread();
- mutex_unlock(&kmemleak_mutex);
+ mutex_unlock(&scan_mutex);
pr_info("Kernel memory leak detector initialized\n");
>From davej Fri Jun 26 10:15:49 2009
Return-Path: Catalin.Marinas at arm.com
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
gelk.kernelslacker.org
X-Spam-Level:
X-Spam-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00,
RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.2.5
Received: from mail.corp.redhat.com [10.5.5.51]
by gelk.kernelslacker.org with IMAP (fetchmail-6.3.9)
for <davej at localhost> (single-drop); Fri, 26 Jun 2009 10:15:49 -0400 (EDT)
Received: from zmta03.collab.prod.int.phx2.redhat.com (LHLO
zmta03.collab.prod.int.phx2.redhat.com) (10.5.5.33) by
mail04.corp.redhat.com with LMTP; Fri, 26 Jun 2009 10:13:28 -0400 (EDT)
Received: from localhost (localhost.localdomain [127.0.0.1])
by zmta03.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id EBFBE4E14E
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:28 -0400 (EDT)
Received: from zmta03.collab.prod.int.phx2.redhat.com ([127.0.0.1])
by localhost (zmta03.collab.prod.int.phx2.redhat.com [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 2ZDWDxKMrNmg for <davej at redhat.com>;
Fri, 26 Jun 2009 10:13:28 -0400 (EDT)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254])
by zmta03.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id B6D524E14A
for <davej at mail.corp.redhat.com>; Fri, 26 Jun 2009 10:13:28 -0400 (EDT)
Received: from mx3.redhat.com (mx3.redhat.com [172.16.48.32])
by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5QEDRO6000446
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:27 -0400
Received: from cam-admin0.cambridge.arm.com (cam-admin0.cambridge.arm.com [193.131.176.58])
by mx3.redhat.com (8.13.8/8.13.8) with ESMTP id n5QEDEhd024713
for <davej at redhat.com>; Fri, 26 Jun 2009 10:13:14 -0400
Received: from cam-owa1.Emea.Arm.com (cam-owa1.emea.arm.com [10.1.255.62])
by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id n5QEA9Zm009603;
Fri, 26 Jun 2009 15:10:09 +0100 (BST)
Received: from pc1117.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0);
Fri, 26 Jun 2009 15:12:58 +0100
Subject: [PATCH 4/4] kmemleak: Slightly change the policy on newly allocated
objects
To: linux-kernel at vger.kernel.org
From: Catalin Marinas <catalin.marinas at arm.com>
Cc: Dave Jones <davej at redhat.com>, Ingo Molnar <mingo at elte.hu>,
Pekka Enberg <penberg at cs.helsinki.fi>,
Sergey Senozhatsky <sergey.senozhatsky at mail.by>
Date: Fri, 26 Jun 2009 15:12:58 +0100
Message-ID: <20090626141258.31504.36983.stgit at pc1117.cambridge.arm.com>
In-Reply-To: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
References: <20090626140847.31504.79381.stgit at pc1117.cambridge.arm.com>
User-Agent: StGit/0.14.3.387.geb0c.dirty
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 26 Jun 2009 14:12:58.0862 (UTC) FILETIME=[3555D8E0:01C9F668]
X-RedHat-Spam-Score: -3.545
X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254
X-Scanned-By: MIMEDefang 2.63 on 172.16.48.32
Status: RO
Content-Length: 1674
Lines: 45
Newly allocated objects are more likely to be reported as false
positives. Kmemleak ignores the reporting of objects younger than 5
seconds. However, this age was calculated after the memory scanning
completed which usually takes longer than 5 seconds. This patch
make the minimum object age calculation in relation to the start of the
memory scanning.
Signed-off-by: Catalin Marinas <catalin.marinas at arm.com>
---
mm/kmemleak.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index e96e0ec..c37e8e5 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -190,7 +190,9 @@ static unsigned long max_addr;
static unsigned long next_scan_yield;
static struct task_struct *scan_thread;
static unsigned long jiffies_scan_yield;
+/* used to avoid reporting of recently allocated objects */
static unsigned long jiffies_min_age;
+static unsigned long jiffies_last_scan;
/* delay between automatic memory scannings */
static signed long jiffies_scan_wait;
/* enables or disables the task stacks scanning */
@@ -284,7 +286,8 @@ static int color_gray(const struct kmemleak_object *object)
static int unreferenced_object(struct kmemleak_object *object)
{
return (object->flags & OBJECT_ALLOCATED) && color_white(object) &&
- time_is_before_eq_jiffies(object->jiffies + jiffies_min_age);
+ time_before_eq(object->jiffies + jiffies_min_age,
+ jiffies_last_scan);
}
/*
@@ -927,6 +930,8 @@ static void kmemleak_scan(void)
int i;
int new_leaks = 0;
+ jiffies_last_scan = jiffies;
+
/* prepare the kmemleak_object's */
rcu_read_lock();
list_for_each_entry_rcu(object, &object_list, object_list) {
Index: TODO
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/TODO,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -p -r1.63 -r1.64
--- TODO 3 Jun 2009 15:42:28 -0000 1.63
+++ TODO 26 Jun 2009 14:41:59 -0000 1.64
@@ -78,3 +78,6 @@
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=126403
http://lkml.org/lkml/2006/8/2/208
+* linux-2.6-kmemleak-improvements.patch
+ will go upstream for .31
+
Index: kernel.spec
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/kernel.spec,v
retrieving revision 1.1594
retrieving revision 1.1595
diff -u -p -r1.1594 -r1.1595
--- kernel.spec 26 Jun 2009 14:35:50 -0000 1.1594
+++ kernel.spec 26 Jun 2009 14:41:59 -0000 1.1595
@@ -676,7 +676,7 @@ Patch2903: linux-2.6-revert-dvb-net-kabi
# fs fixes
Patch3000: linux-2.6-btrfs-experimental-branch.patch
-Patch4000: linux-2.6-kmemleak-scan-stack-by-default.patch
+Patch4000: linux-2.6-kmemleak-improvements.patch
#snmp fixes
Patch10000: linux-2.6-missing-rfc2465-stats.patch
@@ -1138,7 +1138,7 @@ ApplyPatch linux-2.6-execshield.patch
# btrfs
#ApplyPatch linux-2.6-btrfs-experimental-branch.patch
-ApplyPatch linux-2.6-kmemleak-scan-stack-by-default.patch
+ApplyPatch linux-2.6-kmemleak-improvements.patch
# USB
@@ -1846,6 +1846,9 @@ fi
# and build.
%changelog
+* Fri Jun 26 2009 Dave Jones <davej at redhat.com> 2.6.31-0.31.rc1.git2
+- Further improvements to kmemleak
+
* Fri Jun 26 2009 Dave Jones <davej at redhat.com> 2.6.31-0.30.rc1.git2
- 2.6.31-rc1-git2
--- linux-2.6-kmemleak-scan-stack-by-default.patch DELETED ---
More information about the fedora-extras-commits
mailing list