diff options
Diffstat (limited to 'Documentation/kmemleak.txt')
-rw-r--r-- | Documentation/kmemleak.txt | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt index 0112da3b9ab8..34f6638aa5ac 100644 --- a/Documentation/kmemleak.txt +++ b/Documentation/kmemleak.txt | |||
@@ -16,13 +16,24 @@ Usage | |||
16 | ----- | 16 | ----- |
17 | 17 | ||
18 | CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel | 18 | CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel |
19 | thread scans the memory every 10 minutes (by default) and prints any new | 19 | thread scans the memory every 10 minutes (by default) and prints the |
20 | unreferenced objects found. To trigger an intermediate scan and display | 20 | number of new unreferenced objects found. To display the details of all |
21 | all the possible memory leaks: | 21 | the possible memory leaks: |
22 | 22 | ||
23 | # mount -t debugfs nodev /sys/kernel/debug/ | 23 | # mount -t debugfs nodev /sys/kernel/debug/ |
24 | # cat /sys/kernel/debug/kmemleak | 24 | # cat /sys/kernel/debug/kmemleak |
25 | 25 | ||
26 | To trigger an intermediate memory scan: | ||
27 | |||
28 | # echo scan > /sys/kernel/debug/kmemleak | ||
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 | |||
26 | 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 |
27 | 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 |
28 | objects to be reported as orphan. | 39 | objects to be reported as orphan. |
@@ -31,16 +42,24 @@ Memory scanning parameters can be modified at run-time by writing to the | |||
31 | /sys/kernel/debug/kmemleak file. The following parameters are supported: | 42 | /sys/kernel/debug/kmemleak file. The following parameters are supported: |
32 | 43 | ||
33 | off - disable kmemleak (irreversible) | 44 | off - disable kmemleak (irreversible) |
34 | stack=on - enable the task stacks scanning | 45 | stack=on - enable the task stacks scanning (default) |
35 | stack=off - disable the tasks stacks scanning | 46 | stack=off - disable the tasks stacks scanning |
36 | scan=on - start the automatic memory scanning thread | 47 | scan=on - start the automatic memory scanning thread (default) |
37 | scan=off - stop the automatic memory scanning thread | 48 | scan=off - stop the automatic memory scanning thread |
38 | scan=<secs> - set the automatic memory scanning period in seconds (0 | 49 | scan=<secs> - set the automatic memory scanning period in seconds |
39 | to disable it) | 50 | (default 600, 0 to stop the automatic scanning) |
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 | ||
54 | dump=<addr> - dump information about the object found at <addr> | ||
40 | 55 | ||
41 | 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 |
42 | the kernel command line. | 57 | the kernel command line. |
43 | 58 | ||
59 | Memory may be allocated or freed before kmemleak is initialised and | ||
60 | these actions are stored in an early log buffer. The size of this buffer | ||
61 | is configured via the CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE option. | ||
62 | |||
44 | Basic Algorithm | 63 | Basic Algorithm |
45 | --------------- | 64 | --------------- |
46 | 65 | ||
@@ -77,6 +96,27 @@ avoid this, kmemleak can also store the number of values pointing to an | |||
77 | 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 |
78 | block is not considered a leak. One example is __vmalloc(). | 97 | block is not considered a leak. One example is __vmalloc(). |
79 | 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 | |||
80 | Kmemleak API | 120 | Kmemleak API |
81 | ------------ | 121 | ------------ |
82 | 122 | ||