From: "Luis R. Rodriguez" <lrodriguez@atheros.com>
To: catalin.marinas@arm.com, torvalds@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, penberg@cs.helsinki.fi,
mcgrof@gmail.com, "Luis R. Rodriguez" <lrodriguez@atheros.com>
Subject: [PATCH v2 2/5] kmemleak: add clear command support
Date: Thu, 3 Sep 2009 01:35:37 -0400 [thread overview]
Message-ID: <1251956140-5499-3-git-send-email-lrodriguez@atheros.com> (raw)
In-Reply-To: <1251956140-5499-1-git-send-email-lrodriguez@atheros.com>
In an ideal world your kmemleak output will be small,
when its not you can use the clear command to ingore previously
annotated kmemleak objects. We do this by painting them black.
You can now use 'clear'; run some critical section code you'd
like to test, and then run 'scan'.
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
---
Documentation/kmemleak.txt | 17 +++++++++++++++++
mm/kmemleak.c | 22 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt
index 8906803..235090b 100644
--- a/Documentation/kmemleak.txt
+++ b/Documentation/kmemleak.txt
@@ -27,6 +27,13 @@ To trigger an intermediate memory scan:
# echo scan > /sys/kernel/debug/kmemleak
+To clear the list of all current possible memory leaks:
+
+ # echo clear > /sys/kernel/debug/kmemleak
+
+New leaks will then come up upon reading /sys/kernel/debug/kmemleak
+again.
+
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.
@@ -35,6 +42,8 @@ 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)
+ clear - clear list of current memory leak suspects, done by
+ marking all current kmemleak objects as black.
stack=on - enable the task stacks scanning (default)
stack=off - disable the tasks stacks scanning
scan=on - start the automatic memory scanning thread (default)
@@ -79,6 +88,8 @@ The scanning algorithm steps:
gray set is finished
4. the remaining white objects are considered orphan and reported via
/sys/kernel/debug/kmemleak
+ 5. All black objects are ignored on the output of
+ /sys/kernel/debug/kmemleak
Some allocated memory blocks have pointers stored in the kernel's
internal data structures and they cannot be detected as orphans. To
@@ -86,6 +97,12 @@ avoid this, kmemleak can also store the number of values pointing to an
address inside the block address range that need to be found so that the
block is not considered a leak. One example is __vmalloc().
+Testing a sections with kmemleak
+--------------------------------
+
+You can use the 'clear' and 'scan' command over certain critical sections you
+would like to test.
+
Kmemleak API
------------
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index c6e71bb..b6bc34e 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1294,10 +1294,30 @@ static int kmemleak_release(struct inode *inode, struct file *file)
return seq_release(inode, file);
}
+static void kmemleak_clear(void)
+{
+ struct kmemleak_object *object;
+ unsigned long flags;
+
+ stop_scan_thread();
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(object, &object_list, object_list) {
+ spin_lock_irqsave(&object->lock, flags);
+ object->min_count = -1;
+ spin_unlock_irqrestore(&object->lock, flags);
+ }
+ rcu_read_unlock();
+
+ start_scan_thread();
+}
+
/*
* File write operation to configure kmemleak at run-time. The following
* commands can be written to the /sys/kernel/debug/kmemleak file:
* off - disable kmemleak (irreversible)
+ * clear - mark all current kmemleak objects as black to ingore
+ * printing them
* stack=on - enable the task stacks scanning
* stack=off - disable the tasks stacks scanning
* scan=on - start the automatic memory scanning thread
@@ -1324,6 +1344,8 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
if (strncmp(buf, "off", 3) == 0)
kmemleak_disable();
+ else if (strncmp(buf, "clear", 5) == 0)
+ kmemleak_clear();
else if (strncmp(buf, "stack=on", 8) == 0)
kmemleak_stack_scan = 1;
else if (strncmp(buf, "stack=off", 9) == 0)
--
1.6.3.3
next prev parent reply other threads:[~2009-09-03 5:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-03 5:35 [PATCH v2 0/5] kmemleak: few small cleanups and " Luis R. Rodriguez
2009-09-03 5:35 ` [PATCH v2 1/5] kmemleak: use bool for true/false questions Luis R. Rodriguez
2009-09-03 5:35 ` Luis R. Rodriguez [this message]
2009-09-03 16:52 ` [PATCH v2 2/5] kmemleak: add clear command support Catalin Marinas
2009-09-04 20:26 ` Luis R. Rodriguez
2009-09-04 22:28 ` Catalin Marinas
2009-09-03 5:35 ` [PATCH v2 3/5] kmemleak: move common painting code together Luis R. Rodriguez
2009-09-03 5:35 ` [PATCH v2 4/5] kmemleak: fix sparse warning over overshadowed flags Luis R. Rodriguez
2009-09-03 16:55 ` Catalin Marinas
2009-09-03 18:05 ` Luis R. Rodriguez
2009-09-03 5:35 ` [PATCH v2 5/5] kmemleak: fix sparse warning for static declarations Luis R. Rodriguez
2009-09-03 6:01 ` [PATCH v2 0/5] kmemleak: few small cleanups and clear command support Pekka Enberg
2009-09-03 8:30 ` Catalin Marinas
2009-09-04 19:57 ` Luis R. Rodriguez
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=1251956140-5499-3-git-send-email-lrodriguez@atheros.com \
--to=lrodriguez@atheros.com \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@gmail.com \
--cc=penberg@cs.helsinki.fi \
--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
all inboxes | Powered by JetHome®