Lines Matching +full:memory +full:- +full:to +full:- +full:memory
1 Kernel Memory Leak Detector
4 Kmemleak provides a way of detecting possible kernel memory leaks in a
5 way similar to a `tracing garbage collector
9 Valgrind tool (``memcheck --leak-check``) to detect the memory leaks in
10 user-space applications.
13 -----
15 CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel
16 thread scans the memory every 10 minutes (by default) and prints the
20 # mount -t debugfs nodev /sys/kernel/debug/
22 To display the details of all the possible scanned memory leaks::
26 To trigger an intermediate memory scan::
30 To clear the list of all current possible memory leaks::
39 objects to be reported as orphan.
41 Memory scanning parameters can be modified at run-time by writing to the
44 - off
46 - stack=on
48 - stack=off
50 - scan=on
51 start the automatic memory scanning thread (default)
52 - scan=off
53 stop the automatic memory scanning thread
54 - scan=<secs>
55 set the automatic memory scanning period in seconds
56 (default 600, 0 to stop the automatic scanning)
57 - scan
58 trigger a memory scan
59 - clear
60 clear list of current memory leak suspects, done by
63 - dump=<addr>
66 Kmemleak can also be disabled at boot-time by passing ``kmemleak=off`` on
69 Memory may be allocated or freed before kmemleak is initialised and
77 If you are getting errors like "Error while writing to stdout" or "write_loop:
81 ---------------
83 The memory allocations via :c:func:`kmalloc`, :c:func:`vmalloc`,
90 An allocated block of memory is considered orphan if no pointer to its
91 start address or to any location inside the block can be found by
92 scanning the memory (including saved registers). This means that there
93 might be no way for the kernel to pass the address of the allocated
94 block to a freeing function and therefore the block is considered a
95 memory leak.
101 2. scan the memory starting with the data section and stacks, checking
103 a pointer to a white object is found, the object is added to the
111 Some allocated memory blocks have pointers stored in the kernel's
112 internal data structures and they cannot be detected as orphans. To
113 avoid this, kmemleak can also store the number of values pointing to an
114 address inside the block address range that need to be found so that the
118 ---------------------------------------
122 when doing development. To work around these situations you can use the
123 'clear' command to clear all reported unreferenced objects from the
128 To test a critical section on demand with a clean kmemleak do::
134 Then as usual to get your report with::
139 ---------------------------------
141 To allow access to previously found memory leaks after kmemleak has been
142 disabled by the user or due to an fatal error, internal kmemleak objects
144 a large part of physical memory.
146 In this situation, you may reclaim memory with::
151 ------------
155 - ``kmemleak_init`` - initialize kmemleak
156 - ``kmemleak_alloc`` - notify of a memory block allocation
157 - ``kmemleak_alloc_percpu`` - notify of a percpu memory block allocation
158 - ``kmemleak_vmalloc`` - notify of a vmalloc() memory allocation
159 - ``kmemleak_free`` - notify of a memory block freeing
160 - ``kmemleak_free_part`` - notify of a partial memory block freeing
161 - ``kmemleak_free_percpu`` - notify of a percpu memory block freeing
162 - ``kmemleak_update_trace`` - update object allocation stack trace
163 - ``kmemleak_not_leak`` - mark an object as not a leak
164 - ``kmemleak_ignore`` - do not scan or report an object as leak
165 - ``kmemleak_scan_area`` - add scan areas inside a memory block
166 - ``kmemleak_no_scan`` - do not scan a memory block
167 - ``kmemleak_erase`` - erase an old value in a pointer variable
168 - ``kmemleak_alloc_recursive`` - as kmemleak_alloc but checks the recursiveness
169 - ``kmemleak_free_recursive`` - as kmemleak_free but checks the recursiveness
175 - ``kmemleak_alloc_phys``
176 - ``kmemleak_free_part_phys``
177 - ``kmemleak_ignore_phys``
180 --------------------------------------
182 The false negatives are real memory leaks (orphan objects) but not
183 reported by kmemleak because values found during the memory scanning
184 point to such objects. To reduce the number of false negatives, kmemleak
189 The false positives are objects wrongly reported as being memory leaks
190 (orphan). For objects known not to be leaks, kmemleak provides the
192 the memory block is known not to contain other pointers and it will no
197 stacks. Kmemleak defines MSECS_MIN_AGE (defaulting to 1000) representing
198 the minimum age of an object to be reported as a memory leak.
201 -------------------------
203 The main drawback is the reduced performance of memory allocation and
204 freeing. To avoid other penalties, the memory scanning is only performed
209 To keep the algorithm simple, kmemleak scans for values pointing to any
210 address inside a block's address range. This may lead to an increased
211 number of false negatives. However, it is likely that a real memory leak
214 Another source of false negatives is the data stored in non-pointer
220 block doesn't need to be freed (some cases in the init_call functions),
226 Testing with kmemleak-test
227 --------------------------
229 To check if you have all set up to use kmemleak, you can use the kmemleak-test
230 module, a module that deliberately leaks memory. Set CONFIG_SAMPLE_KMEMLEAK
231 as module (it can't be used as built-in) and boot the kernel with kmemleak
234 # modprobe kmemleak-test
239 memory leaks``. Then read the file to see then::