diff options
author | Luis R. Rodriguez <lrodriguez@Atheros.com> | 2009-09-04 20:44:51 -0400 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2009-09-08 11:36:08 -0400 |
commit | 30b3710105be0ba6bbdb7d7d126af76246b02eba (patch) | |
tree | 84200b02f8230f3706744512bf4ba68341d9b889 /mm/kmemleak.c | |
parent | 4a558dd6f93d419cd318958577e25492bd09e960 (diff) |
kmemleak: add clear command support
In an ideal world your kmemleak output will be small, when its
not (usually during initial bootup) you can use the clear command
to ingore previously reported and unreferenced kmemleak objects. We
do this by painting all currently reported unreferenced objects grey.
We paint them grey instead of black to allow future scans on the same
objects as such objects could still potentially reference newly
allocated objects in the future.
To test a critical section on demand with a clean
/sys/kernel/debug/kmemleak you can do:
echo clear > /sys/kernel/debug/kmemleak
test your kernel or modules
echo scan > /sys/kernel/debug/kmemleak
Then as usual to get your report with:
cat /sys/kernel/debug/kmemleak
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'mm/kmemleak.c')
-rw-r--r-- | mm/kmemleak.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/mm/kmemleak.c b/mm/kmemleak.c index f5042b4a7b95..c17dbc76fb72 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c | |||
@@ -1421,6 +1421,28 @@ static int dump_str_object_info(const char *str) | |||
1421 | } | 1421 | } |
1422 | 1422 | ||
1423 | /* | 1423 | /* |
1424 | * We use grey instead of black to ensure we can do future scans on the same | ||
1425 | * objects. If we did not do future scans these black objects could | ||
1426 | * potentially contain references to newly allocated objects in the future and | ||
1427 | * we'd end up with false positives. | ||
1428 | */ | ||
1429 | static void kmemleak_clear(void) | ||
1430 | { | ||
1431 | struct kmemleak_object *object; | ||
1432 | unsigned long flags; | ||
1433 | |||
1434 | rcu_read_lock(); | ||
1435 | list_for_each_entry_rcu(object, &object_list, object_list) { | ||
1436 | spin_lock_irqsave(&object->lock, flags); | ||
1437 | if ((object->flags & OBJECT_REPORTED) && | ||
1438 | unreferenced_object(object)) | ||
1439 | object->min_count = 0; | ||
1440 | spin_unlock_irqrestore(&object->lock, flags); | ||
1441 | } | ||
1442 | rcu_read_unlock(); | ||
1443 | } | ||
1444 | |||
1445 | /* | ||
1424 | * File write operation to configure kmemleak at run-time. The following | 1446 | * File write operation to configure kmemleak at run-time. The following |
1425 | * commands can be written to the /sys/kernel/debug/kmemleak file: | 1447 | * commands can be written to the /sys/kernel/debug/kmemleak file: |
1426 | * off - disable kmemleak (irreversible) | 1448 | * off - disable kmemleak (irreversible) |
@@ -1431,6 +1453,8 @@ static int dump_str_object_info(const char *str) | |||
1431 | * scan=... - set the automatic memory scanning period in seconds (0 to | 1453 | * scan=... - set the automatic memory scanning period in seconds (0 to |
1432 | * disable it) | 1454 | * disable it) |
1433 | * scan - trigger a memory scan | 1455 | * scan - trigger a memory scan |
1456 | * clear - mark all current reported unreferenced kmemleak objects as | ||
1457 | * grey to ignore printing them | ||
1434 | * dump=... - dump information about the object found at the given address | 1458 | * dump=... - dump information about the object found at the given address |
1435 | */ | 1459 | */ |
1436 | static ssize_t kmemleak_write(struct file *file, const char __user *user_buf, | 1460 | static ssize_t kmemleak_write(struct file *file, const char __user *user_buf, |
@@ -1472,6 +1496,8 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf, | |||
1472 | } | 1496 | } |
1473 | } else if (strncmp(buf, "scan", 4) == 0) | 1497 | } else if (strncmp(buf, "scan", 4) == 0) |
1474 | kmemleak_scan(); | 1498 | kmemleak_scan(); |
1499 | else if (strncmp(buf, "clear", 5) == 0) | ||
1500 | kmemleak_clear(); | ||
1475 | else if (strncmp(buf, "dump=", 5) == 0) | 1501 | else if (strncmp(buf, "dump=", 5) == 0) |
1476 | ret = dump_str_object_info(buf + 5); | 1502 | ret = dump_str_object_info(buf + 5); |
1477 | else | 1503 | else |