diff options
| -rw-r--r-- | Documentation/kmemleak.txt | 30 | ||||
| -rw-r--r-- | mm/kmemleak.c | 26 |
2 files changed, 56 insertions, 0 deletions
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt index c223785339b5..34f6638aa5ac 100644 --- a/Documentation/kmemleak.txt +++ b/Documentation/kmemleak.txt | |||
| @@ -27,6 +27,13 @@ To trigger an intermediate memory scan: | |||
| 27 | 27 | ||
| 28 | # echo scan > /sys/kernel/debug/kmemleak | 28 | # echo scan > /sys/kernel/debug/kmemleak |
| 29 | 29 | ||
| 30 | To clear the list of all current possible memory leaks: | ||
| 31 | |||
| 32 | # echo clear > /sys/kernel/debug/kmemleak | ||
| 33 | |||
| 34 | New leaks will then come up upon reading /sys/kernel/debug/kmemleak | ||
| 35 | again. | ||
| 36 | |||
| 30 | Note that the orphan objects are listed in the order they were allocated | 37 | Note that the orphan objects are listed in the order they were allocated |
| 31 | and one object at the beginning of the list may cause other subsequent | 38 | and one object at the beginning of the list may cause other subsequent |
| 32 | objects to be reported as orphan. | 39 | objects to be reported as orphan. |
| @@ -42,6 +49,8 @@ Memory scanning parameters can be modified at run-time by writing to the | |||
| 42 | scan=<secs> - set the automatic memory scanning period in seconds | 49 | scan=<secs> - set the automatic memory scanning period in seconds |
| 43 | (default 600, 0 to stop the automatic scanning) | 50 | (default 600, 0 to stop the automatic scanning) |
| 44 | scan - trigger a memory scan | 51 | scan - trigger a memory scan |
| 52 | clear - clear list of current memory leak suspects, done by | ||
| 53 | marking all current reported unreferenced objects grey | ||
| 45 | dump=<addr> - dump information about the object found at <addr> | 54 | dump=<addr> - dump information about the object found at <addr> |
| 46 | 55 | ||
| 47 | Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on | 56 | Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on |
| @@ -87,6 +96,27 @@ avoid this, kmemleak can also store the number of values pointing to an | |||
| 87 | address inside the block address range that need to be found so that the | 96 | address inside the block address range that need to be found so that the |
| 88 | block is not considered a leak. One example is __vmalloc(). | 97 | block is not considered a leak. One example is __vmalloc(). |
| 89 | 98 | ||
| 99 | Testing specific sections with kmemleak | ||
| 100 | --------------------------------------- | ||
| 101 | |||
| 102 | Upon initial bootup your /sys/kernel/debug/kmemleak output page may be | ||
| 103 | quite extensive. This can also be the case if you have very buggy code | ||
| 104 | when doing development. To work around these situations you can use the | ||
| 105 | 'clear' command to clear all reported unreferenced objects from the | ||
| 106 | /sys/kernel/debug/kmemleak output. By issuing a 'scan' after a 'clear' | ||
| 107 | you can find new unreferenced objects; this should help with testing | ||
| 108 | specific sections of code. | ||
| 109 | |||
| 110 | To test a critical section on demand with a clean kmemleak do: | ||
| 111 | |||
| 112 | # echo clear > /sys/kernel/debug/kmemleak | ||
| 113 | ... test your kernel or modules ... | ||
| 114 | # echo scan > /sys/kernel/debug/kmemleak | ||
| 115 | |||
| 116 | Then as usual to get your report with: | ||
| 117 | |||
| 118 | # cat /sys/kernel/debug/kmemleak | ||
| 119 | |||
| 90 | Kmemleak API | 120 | Kmemleak API |
| 91 | ------------ | 121 | ------------ |
| 92 | 122 | ||
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 |
