€•v¼Œsphinx.addnodes”Œdocument”“”)�”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)�”}”(hhh]”(hŒ pending_xref”“”)�”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…”�”}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ&/translations/zh_CN/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ&/translations/zh_TW/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ&/translations/it_IT/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ&/translations/ja_JP/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ&/translations/ko_KR/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ&/translations/pt_BR/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ&/translations/sp_SP/dev-tools/kmemleak”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)�”}”(hhh]”(hŒtitle”“”)�”}”(hŒKernel Memory Leak Detector”h]”hŒKernel Memory Leak Detector”…”�”}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³Œ@/var/lib/git/docbuild/linux/Documentation/dev-tools/kmemleak.rst”h´KubhŒ paragraph”“”)�”}”(hX�Kmemleak provides a way of detecting possible kernel memory leaks in a way similar to a `tracing garbage collector `_, with the difference that the orphan objects are not freed but only reported via /sys/kernel/debug/kmemleak. A similar method is used by the Valgrind tool (``memcheck --leak-check``) to detect the memory leaks in user-space applications.”h]”(hŒXKmemleak provides a way of detecting possible kernel memory leaks in a way similar to a ”…”�”}”(hhÍh²hh³Nh´NubhŒ reference”“”)�”}”(hŒW`tracing garbage collector `_”h]”hŒtracing garbage collector”…”�”}”(hh×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œname”Œtracing garbage collector”Œrefuri”Œ8https://en.wikipedia.org/wiki/Tracing_garbage_collection”uh1hÕhhÍubhŒtarget”“”)�”}”(hŒ; ”h]”h}”(h]”Œtracing-garbage-collector”ah ]”h"]”Œtracing garbage collector”ah$]”h&]”Œrefuri”hèuh1héŒ referenced”KhhÍubhŒ�, with the difference that the orphan objects are not freed but only reported via /sys/kernel/debug/kmemleak. A similar method is used by the Valgrind tool (”…”�”}”(hhÍh²hh³Nh´NubhŒliteral”“”)�”}”(hŒ``memcheck --leak-check``”h]”hŒmemcheck --leak-check”…”�”}”(hhÿh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhhÍubhŒ8) to detect the memory leaks in user-space applications.”…”�”}”(hhÍh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒUsage”h]”hŒUsage”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K ubhÌ)�”}”(hŒëCONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel thread scans the memory every 10 minutes (by default) and prints the number of new unreferenced objects found. If the ``debugfs`` isn't already mounted, mount with::”h]”(hŒÀCONFIG_DEBUG_KMEMLEAK in “Kernel hackingâ€� has to be enabled. A kernel thread scans the memory every 10 minutes (by default) and prints the number of new unreferenced objects found. If the ”…”�”}”(hj(h²hh³Nh´Nubhþ)�”}”(hŒ ``debugfs``”h]”hŒdebugfs”…”�”}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj(ubhŒ% isn’t already mounted, mount with:”…”�”}”(hj(h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjh²hubhŒ literal_block”“”)�”}”(hŒ+# mount -t debugfs nodev /sys/kernel/debug/”h]”hŒ+# mount -t debugfs nodev /sys/kernel/debug/”…”�”}”hjJsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jHh³hÊh´Khjh²hubhÌ)�”}”(hŒATo display the details of all the possible scanned memory leaks::”h]”hŒ@To display the details of all the possible scanned memory leaks:”…”�”}”(hjZh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjh²hubjI)�”}”(hŒ # cat /sys/kernel/debug/kmemleak”h]”hŒ # cat /sys/kernel/debug/kmemleak”…”�”}”hjhsbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´Khjh²hubhÌ)�”}”(hŒ(To trigger an intermediate memory scan::”h]”hŒ'To trigger an intermediate memory scan:”…”�”}”(hjvh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjh²hubjI)�”}”(hŒ(# echo scan > /sys/kernel/debug/kmemleak”h]”hŒ(# echo scan > /sys/kernel/debug/kmemleak”…”�”}”hj„sbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´Khjh²hubhÌ)�”}”(hŒ8To clear the list of all current possible memory leaks::”h]”hŒ7To clear the list of all current possible memory leaks:”…”�”}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjh²hubjI)�”}”(hŒ)# echo clear > /sys/kernel/debug/kmemleak”h]”hŒ)# echo clear > /sys/kernel/debug/kmemleak”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´K hjh²hubhÌ)�”}”(hŒNNew leaks will then come up upon reading ``/sys/kernel/debug/kmemleak`` again.”h]”(hŒ)New leaks will then come up upon reading ”…”�”}”(hj®h²hh³Nh´Nubhþ)�”}”(hŒ``/sys/kernel/debug/kmemleak``”h]”hŒ/sys/kernel/debug/kmemleak”…”�”}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj®ubhŒ again.”…”�”}”(hj®h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K"hjh²hubhÌ)�”}”(hŒ±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.”h]”hŒ±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.”…”�”}”(hjÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K%hjh²hubhÌ)�”}”(hŒ•Memory scanning parameters can be modified at run-time by writing to the ``/sys/kernel/debug/kmemleak`` file. The following parameters are supported:”h]”(hŒIMemory scanning parameters can be modified at run-time by writing to the ”…”�”}”(hjÜh²hh³Nh´Nubhþ)�”}”(hŒ``/sys/kernel/debug/kmemleak``”h]”hŒ/sys/kernel/debug/kmemleak”…”�”}”(hjäh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjÜubhŒ. file. The following parameters are supported:”…”�”}”(hjÜh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K)hjh²hubhŒ bullet_list”“”)�”}”(hhh]”(hŒ list_item”“”)�”}”(hŒ%off disable kmemleak (irreversible)”h]”hŒdefinition_list”“”)�”}”(hhh]”hŒdefinition_list_item”“”)�”}”(hŒ#off disable kmemleak (irreversible)”h]”(hŒterm”“”)�”}”(hŒoff”h]”hŒoff”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K,hjubhŒ definition”“”)�”}”(hhh]”hÌ)�”}”(hŒdisable kmemleak (irreversible)”h]”hŒdisable kmemleak (irreversible)”…”�”}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K-hj$ubah}”(h]”h ]”h"]”h$]”h&]”uh1j"hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K,hj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþh²hh³Nh´Nubj)�”}”(hŒ4stack=on enable the task stacks scanning (default)”h]”j)�”}”(hhh]”j )�”}”(hŒ2stack=on enable the task stacks scanning (default)”h]”(j)�”}”(hŒstack=on”h]”hŒstack=on”…”�”}”(hjXh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K.hjTubj#)�”}”(hhh]”hÌ)�”}”(hŒ)enable the task stacks scanning (default)”h]”hŒ)enable the task stacks scanning (default)”…”�”}”(hjih²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K/hjfubah}”(h]”h ]”h"]”h$]”h&]”uh1j"hjTubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K.hjQubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjMubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþh²hh³Nh´Nubj)�”}”(hŒ-stack=off disable the tasks stacks scanning”h]”j)�”}”(hhh]”j )�”}”(hŒ+stack=off disable the tasks stacks scanning”h]”(j)�”}”(hŒ stack=off”h]”hŒ stack=off”…”�”}”(hjšh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K0hj–ubj#)�”}”(hhh]”hÌ)�”}”(hŒ!disable the tasks stacks scanning”h]”hŒ!disable the tasks stacks scanning”…”�”}”(hj«h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K1hj¨ubah}”(h]”h ]”h"]”h$]”h&]”uh1j"hj–ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K0hj“ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj�ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþh²hh³Nh´Nubj)�”}”(hŒ>scan=on start the automatic memory scanning thread (default)”h]”j)�”}”(hhh]”j )�”}”(hŒ set the automatic memory scanning period in seconds (default 600, 0 to stop the automatic scanning)”h]”j)�”}”(hhh]”j )�”}”(hŒoscan= set the automatic memory scanning period in seconds (default 600, 0 to stop the automatic scanning)”h]”(j)�”}”(hŒ scan=”h]”hŒ scan=”…”�”}”(hj`h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K7hj\ubj#)�”}”(hhh]”hÌ)�”}”(hŒcset the automatic memory scanning period in seconds (default 600, 0 to stop the automatic scanning)”h]”hŒcset the automatic memory scanning period in seconds (default 600, 0 to stop the automatic scanning)”…”�”}”(hjqh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K7hjnubah}”(h]”h ]”h"]”h$]”h&]”uh1j"hj\ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K7hjYubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjUubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþh²hh³Nh´Nubj)�”}”(hŒscan trigger a memory scan”h]”j)�”}”(hhh]”j )�”}”(hŒscan trigger a memory scan”h]”(j)�”}”(hŒscan”h]”hŒscan”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K9hjžubj#)�”}”(hhh]”hÌ)�”}”(hŒtrigger a memory scan”h]”hŒtrigger a memory scan”…”�”}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K:hj°ubah}”(h]”h ]”h"]”h$]”h&]”uh1j"hjžubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K9hj›ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj—ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþh²hh³Nh´Nubj)�”}”(hŒ³clear clear list of current memory leak suspects, done by marking all current reported unreferenced objects grey, or free all kmemleak objects if kmemleak has been disabled.”h]”j)�”}”(hhh]”j )�”}”(hŒ­clear clear list of current memory leak suspects, done by marking all current reported unreferenced objects grey, or free all kmemleak objects if kmemleak has been disabled.”h]”(j)�”}”(hŒclear”h]”hŒclear”…”�”}”(hjäh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K=hjàubj#)�”}”(hhh]”hÌ)�”}”(hŒ§clear list of current memory leak suspects, done by marking all current reported unreferenced objects grey, or free all kmemleak objects if kmemleak has been disabled.”h]”hŒ§clear list of current memory leak suspects, done by marking all current reported unreferenced objects grey, or free all kmemleak objects if kmemleak has been disabled.”…”�”}”(hjõh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K dump information about the object found at ”h]”j)�”}”(hhh]”j )�”}”(hŒ>dump= dump information about the object found at ”h]”(j)�”}”(hŒ dump=”h]”hŒ dump=”…”�”}”(hj&h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´K@hj"ubj#)�”}”(hhh]”hÌ)�”}”(hŒ1dump information about the object found at ”h]”hŒ1dump information about the object found at ”…”�”}”(hj7h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K@hj4ubah}”(h]”h ]”h"]”h$]”h&]”uh1j"hj"ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j h³hÊh´K@hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjþh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jüh³hÊh´K,hjh²hubhÌ)�”}”(hŒbKmemleak can also be disabled at boot-time by passing ``kmemleak=off`` on the kernel command line.”h]”(hŒ6Kmemleak can also be disabled at boot-time by passing ”…”�”}”(hjeh²hh³Nh´Nubhþ)�”}”(hŒ``kmemleak=off``”h]”hŒ kmemleak=off”…”�”}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjeubhŒ on the kernel command line.”…”�”}”(hjeh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KBhjh²hubhÌ)�”}”(hŒÎMemory may be allocated or freed before kmemleak is initialised and these actions are stored in an early log buffer. The size of this buffer is configured via the CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE option.”h]”hŒÎMemory may be allocated or freed before kmemleak is initialised and these actions are stored in an early log buffer. The size of this buffer is configured via the CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE option.”…”�”}”(hj…h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KEhjh²hubhÌ)�”}”(hŒŸIf CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF are enabled, the kmemleak is disabled by default. Passing ``kmemleak=on`` on the kernel command line enables the function.”h]”(hŒ_If CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF are enabled, the kmemleak is disabled by default. Passing ”…”�”}”(hj“h²hh³Nh´Nubhþ)�”}”(hŒ``kmemleak=on``”h]”hŒ kmemleak=on”…”�”}”(hj›h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj“ubhŒ1 on the kernel command line enables the function.”…”�”}”(hj“h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KIhjh²hubhÌ)�”}”(hŒ‰If you are getting errors like "Error while writing to stdout" or "write_loop: Invalid argument", make sure kmemleak is properly enabled.”h]”hŒ‘If you are getting errors like “Error while writing to stdoutâ€� or “write_loop: Invalid argumentâ€�, make sure kmemleak is properly enabled.”…”�”}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KMhjh²hubeh}”(h]”Œusage”ah ]”h"]”Œusage”ah$]”h&]”uh1hµhh·h²hh³hÊh´K ubh¶)�”}”(hhh]”(h»)�”}”(hŒBasic Algorithm”h]”hŒBasic Algorithm”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÉh²hh³hÊh´KQubhÌ)�”}”(hXMThe memory allocations via :c:func:`kmalloc`, :c:func:`vmalloc`, :c:func:`kmem_cache_alloc` and friends are traced and the pointers, together with additional information like size and stack trace, are stored in a rbtree. The corresponding freeing function calls are tracked and the pointers removed from the kmemleak data structures.”h]”(hŒThe memory allocations via ”…”�”}”(hjÚh²hh³Nh´Nubh)�”}”(hŒ:c:func:`kmalloc`”h]”hþ)�”}”(hjäh]”hŒ kmalloc()”…”�”}”(hjæh²hh³Nh´Nubah}”(h]”h ]”(Œxref”Œc”Œc-func”eh"]”h$]”h&]”uh1hýhjâubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”Œdev-tools/kmemleak”Œ refdomain”jñŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰Œ reftarget”Œkmalloc”uh1hh³hÊh´KShjÚubhŒ, ”…”�”}”(hjÚh²hh³Nh´Nubh)�”}”(hŒ:c:func:`vmalloc`”h]”hþ)�”}”(hj h]”hŒ vmalloc()”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”(jðjñŒc-func”eh"]”h$]”h&]”uh1hýhj ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jýŒ refdomain”jñŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰jŒvmalloc”uh1hh³hÊh´KShjÚubhŒ, ”…”�”}”(hjÚh²hh³Nh´Nubh)�”}”(hŒ:c:func:`kmem_cache_alloc`”h]”hþ)�”}”(hj.h]”hŒkmem_cache_alloc()”…”�”}”(hj0h²hh³Nh´Nubah}”(h]”h ]”(jðjñŒc-func”eh"]”h$]”h&]”uh1hýhj,ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jýŒ refdomain”jñŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰jŒkmem_cache_alloc”uh1hh³hÊh´KShjÚubhŒò and friends are traced and the pointers, together with additional information like size and stack trace, are stored in a rbtree. The corresponding freeing function calls are tracked and the pointers removed from the kmemleak data structures.”…”�”}”(hjÚh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KShjÉh²hubhÌ)�”}”(hXdAn allocated block of memory is considered orphan if no pointer to its start address or to any location inside the block can be found by scanning the memory (including saved registers). This means that there might be no way for the kernel to pass the address of the allocated block to a freeing function and therefore the block is considered a memory leak.”h]”hXdAn allocated block of memory is considered orphan if no pointer to its start address or to any location inside the block can be found by scanning the memory (including saved registers). This means that there might be no way for the kernel to pass the address of the allocated block to a freeing function and therefore the block is considered a memory leak.”…”�”}”(hjUh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KZhjÉh²hubhÌ)�”}”(hŒThe scanning algorithm steps:”h]”hŒThe scanning algorithm steps:”…”�”}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KahjÉh²hubhŒ block_quote”“”)�”}”(hX31. mark all objects as white (remaining white objects will later be considered orphan) 2. scan the memory starting with the data section and stacks, checking the values against the addresses stored in the rbtree. If a pointer to a white object is found, the object is added to the gray list 3. scan the gray objects for matching addresses (some white objects can become gray and added at the end of the gray list) until the gray set is finished 4. the remaining white objects are considered orphan and reported via /sys/kernel/debug/kmemleak ”h]”hŒenumerated_list”“”)�”}”(hhh]”(j)�”}”(hŒSmark all objects as white (remaining white objects will later be considered orphan)”h]”hÌ)�”}”(hŒSmark all objects as white (remaining white objects will later be considered orphan)”h]”hŒSmark all objects as white (remaining white objects will later be considered orphan)”…”�”}”(hj€h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kchj|ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjyubj)�”}”(hŒÈscan the memory starting with the data section and stacks, checking the values against the addresses stored in the rbtree. If a pointer to a white object is found, the object is added to the gray list”h]”hÌ)�”}”(hŒÈscan the memory starting with the data section and stacks, checking the values against the addresses stored in the rbtree. If a pointer to a white object is found, the object is added to the gray list”h]”hŒÈscan the memory starting with the data section and stacks, checking the values against the addresses stored in the rbtree. If a pointer to a white object is found, the object is added to the gray list”…”�”}”(hj˜h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kehj”ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjyubj)�”}”(hŒ–scan the gray objects for matching addresses (some white objects can become gray and added at the end of the gray list) until the gray set is finished”h]”hÌ)�”}”(hŒ–scan the gray objects for matching addresses (some white objects can become gray and added at the end of the gray list) until the gray set is finished”h]”hŒ–scan the gray objects for matching addresses (some white objects can become gray and added at the end of the gray list) until the gray set is finished”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kihj¬ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjyubj)�”}”(hŒ^the remaining white objects are considered orphan and reported via /sys/kernel/debug/kmemleak ”h]”hÌ)�”}”(hŒ]the remaining white objects are considered orphan and reported via /sys/kernel/debug/kmemleak”h]”hŒ]the remaining white objects are considered orphan and reported via /sys/kernel/debug/kmemleak”…”�”}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KlhjÄubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjyubeh}”(h]”h ]”h"]”h$]”h&]”Œenumtype”Œarabic”Œprefix”hŒsuffix”Œ.”uh1jwhjsubah}”(h]”h ]”h"]”h$]”h&]”uh1jqh³hÊh´KchjÉh²hubhÌ)�”}”(hXRSome allocated memory blocks have pointers stored in the kernel's internal data structures and they cannot be detected as orphans. To 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().”h]”hXTSome allocated memory blocks have pointers stored in the kernel’s internal data structures and they cannot be detected as orphans. To 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().”…”�”}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KohjÉh²hubeh}”(h]”Œbasic-algorithm”ah ]”h"]”Œbasic algorithm”ah$]”h&]”uh1hµhh·h²hh³hÊh´KQubh¶)�”}”(hhh]”(h»)�”}”(hŒ'Testing specific sections with kmemleak”h]”hŒ'Testing specific sections with kmemleak”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´KvubhÌ)�”}”(hXÀUpon initial bootup your /sys/kernel/debug/kmemleak output page may be quite extensive. This can also be the case if you have very buggy code when doing development. To work around these situations you can use the 'clear' command to clear all reported unreferenced objects from the /sys/kernel/debug/kmemleak output. By issuing a 'scan' after a 'clear' you can find new unreferenced objects; this should help with testing specific sections of code.”h]”hXÌUpon initial bootup your /sys/kernel/debug/kmemleak output page may be quite extensive. This can also be the case if you have very buggy code when doing development. To work around these situations you can use the ‘clear’ command to clear all reported unreferenced objects from the /sys/kernel/debug/kmemleak output. By issuing a ‘scan’ after a ‘clear’ you can find new unreferenced objects; this should help with testing specific sections of code.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kxhjh²hubhÌ)�”}”(hŒ?To test a critical section on demand with a clean kmemleak do::”h]”hŒ>To test a critical section on demand with a clean kmemleak do:”…”�”}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K€hjh²hubjI)�”}”(hŒv# echo clear > /sys/kernel/debug/kmemleak ... test your kernel or modules ... # echo scan > /sys/kernel/debug/kmemleak”h]”hŒv# echo clear > /sys/kernel/debug/kmemleak ... test your kernel or modules ... # echo scan > /sys/kernel/debug/kmemleak”…”�”}”hj0sbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´K‚hjh²hubhÌ)�”}”(hŒ'Then as usual to get your report with::”h]”hŒ&Then as usual to get your report with:”…”�”}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K†hjh²hubjI)�”}”(hŒ # cat /sys/kernel/debug/kmemleak”h]”hŒ # cat /sys/kernel/debug/kmemleak”…”�”}”hjLsbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´Kˆhjh²hubeh}”(h]”Œ'testing-specific-sections-with-kmemleak”ah ]”h"]”Œ'testing specific sections with kmemleak”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kvubh¶)�”}”(hhh]”(h»)�”}”(hŒ!Freeing kmemleak internal objects”h]”hŒ!Freeing kmemleak internal objects”…”�”}”(hjeh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjbh²hh³hÊh´K‹ubhÌ)�”}”(hŒùTo allow access to previously found memory leaks after kmemleak has been disabled by the user or due to an fatal error, internal kmemleak objects won't be freed when kmemleak is disabled, and those objects may occupy a large part of physical memory.”h]”hŒûTo allow access to previously found memory leaks after kmemleak has been disabled by the user or due to an fatal error, internal kmemleak objects won’t be freed when kmemleak is disabled, and those objects may occupy a large part of physical memory.”…”�”}”(hjsh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K�hjbh²hubhÌ)�”}”(hŒ0In this situation, you may reclaim memory with::”h]”hŒ/In this situation, you may reclaim memory with:”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K’hjbh²hubjI)�”}”(hŒ)# echo clear > /sys/kernel/debug/kmemleak”h]”hŒ)# echo clear > /sys/kernel/debug/kmemleak”…”�”}”hj�sbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´K”hjbh²hubeh}”(h]”Œ!freeing-kmemleak-internal-objects”ah ]”h"]”Œ!freeing kmemleak internal objects”ah$]”h&]”uh1hµhh·h²hh³hÊh´K‹ubh¶)�”}”(hhh]”(h»)�”}”(hŒ Kmemleak API”h]”hŒ Kmemleak API”…”�”}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¥h²hh³hÊh´K—ubhÌ)�”}”(hŒDSee the include/linux/kmemleak.h header for the functions prototype.”h]”hŒDSee the include/linux/kmemleak.h header for the functions prototype.”…”�”}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K™hj¥h²hubjý)�”}”(hhh]”(j)�”}”(hŒ4``kmemleak_init`` - initialize kmemleak”h]”hÌ)�”}”(hjÉh]”(hþ)�”}”(hŒ``kmemleak_init``”h]”hŒ kmemleak_init”…”�”}”(hjÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjËubhŒ# - initialize kmemleak”…”�”}”(hjËh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K›hjÇubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒD``kmemleak_alloc`` - notify of a memory block allocation”h]”hÌ)�”}”(hjîh]”(hþ)�”}”(hŒ``kmemleak_alloc``”h]”hŒkmemleak_alloc”…”�”}”(hjóh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjðubhŒ2 - notify of a memory block allocation”…”�”}”(hjðh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kœhjìubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒK``kmemleak_alloc_percpu`` - notify of a percpu memory block allocation”h]”hÌ)�”}”(hjh]”(hþ)�”}”(hŒ``kmemleak_alloc_percpu``”h]”hŒkmemleak_alloc_percpu”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjubhŒ2 - notify of a percpu memory block allocation”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K�hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒH``kmemleak_vmalloc`` - notify of a vmalloc() memory allocation”h]”hÌ)�”}”(hj8h]”(hþ)�”}”(hŒ``kmemleak_vmalloc``”h]”hŒkmemleak_vmalloc”…”�”}”(hj=h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj:ubhŒ4 - notify of a vmalloc() memory allocation”…”�”}”(hj:h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kžhj6ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒA``kmemleak_free`` - notify of a memory block freeing”h]”hÌ)�”}”(hj]h]”(hþ)�”}”(hŒ``kmemleak_free``”h]”hŒ kmemleak_free”…”�”}”(hjbh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj_ubhŒ0 - notify of a memory block freeing”…”�”}”(hj_h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KŸhj[ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒI``kmemleak_free_part`` - notify of a partial memory block freeing”h]”hÌ)�”}”(hj‚h]”(hþ)�”}”(hŒ``kmemleak_free_part``”h]”hŒkmemleak_free_part”…”�”}”(hj‡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj„ubhŒ3 - notify of a partial memory block freeing”…”�”}”(hj„h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hj€ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒH``kmemleak_free_percpu`` - notify of a percpu memory block freeing”h]”hÌ)�”}”(hj§h]”(hþ)�”}”(hŒ``kmemleak_free_percpu``”h]”hŒkmemleak_free_percpu”…”�”}”(hj¬h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj©ubhŒ0 - notify of a percpu memory block freeing”…”�”}”(hj©h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¡hj¥ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒE``kmemleak_update_trace`` - update object allocation stack trace”h]”hÌ)�”}”(hjÌh]”(hþ)�”}”(hŒ``kmemleak_update_trace``”h]”hŒkmemleak_update_trace”…”�”}”(hjÑh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjÎubhŒ, - update object allocation stack trace”…”�”}”(hjÎh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¢hjÊubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒ5``kmemleak_not_leak`` - mark an object as not a leak”h]”hÌ)�”}”(hjñh]”(hþ)�”}”(hŒ``kmemleak_not_leak``”h]”hŒkmemleak_not_leak”…”�”}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjóubhŒ - mark an object as not a leak”…”�”}”(hjóh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K£hjïubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒC``kmemleak_transient_leak`` - mark an object as a transient leak”h]”hÌ)�”}”(hjh]”(hþ)�”}”(hŒ``kmemleak_transient_leak``”h]”hŒkmemleak_transient_leak”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjubhŒ( - mark an object as a transient leak”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¤hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒH``kmemleak_ignore`` - do not scan or report an object as leak”h]”hÌ)�”}”(hj;h]”(hþ)�”}”(hŒ``kmemleak_ignore``”h]”hŒkmemleak_ignore”…”�”}”(hj@h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj=ubhŒ5 - do not scan or report an object as leak”…”�”}”(hj=h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¥hj9ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒE``kmemleak_scan_area`` - add scan areas inside a memory block”h]”hÌ)�”}”(hj`h]”(hþ)�”}”(hŒ``kmemleak_scan_area``”h]”hŒkmemleak_scan_area”…”�”}”(hjeh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjbubhŒ/ - add scan areas inside a memory block”…”�”}”(hjbh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¦hj^ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒ3``kmemleak_no_scan`` - do not scan a memory block”h]”hÌ)�”}”(hj…h]”(hþ)�”}”(hŒ``kmemleak_no_scan``”h]”hŒkmemleak_no_scan”…”�”}”(hjŠh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj‡ubhŒ - do not scan a memory block”…”�”}”(hj‡h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K§hjƒubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒI``kmemleak_erase`` - erase an old value in a pointer variable”h]”hÌ)�”}”(hjªh]”(hþ)�”}”(hŒ``kmemleak_erase``”h]”hŒkmemleak_erase”…”�”}”(hj¯h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj¬ubhŒ7 - erase an old value in a pointer variable”…”�”}”(hj¬h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¨hj¨ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒM``kmemleak_alloc_recursive`` - as kmemleak_alloc but checks the recursiveness”h]”hÌ)�”}”(hjÏh]”(hþ)�”}”(hŒ``kmemleak_alloc_recursive``”h]”hŒkmemleak_alloc_recursive”…”�”}”(hjÔh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjÑubhŒ1 - as kmemleak_alloc but checks the recursiveness”…”�”}”(hjÑh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K©hjÍubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubj)�”}”(hŒO``kmemleak_free_recursive`` - as kmemleak_free but checks the recursiveness ”h]”hÌ)�”}”(hŒN``kmemleak_free_recursive`` - as kmemleak_free but checks the recursiveness”h]”(hþ)�”}”(hŒ``kmemleak_free_recursive``”h]”hŒkmemleak_free_recursive”…”�”}”(hjúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjöubhŒ3 - as kmemleak_free but checks the recursiveness”…”�”}”(hjöh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kªhjòubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÄh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jcjduh1jüh³hÊh´K›hj¥h²hubhÌ)�”}”(hŒ”The following functions take a physical address as the object pointer and only perform the corresponding action if the address has a lowmem mapping:”h]”hŒ”The following functions take a physical address as the object pointer and only perform the corresponding action if the address has a lowmem mapping:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¬hj¥h²hubjý)�”}”(hhh]”(j)�”}”(hŒ``kmemleak_alloc_phys``”h]”hÌ)�”}”(hj1 h]”hþ)�”}”(hj1 h]”hŒkmemleak_alloc_phys”…”�”}”(hj6 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj3 ubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K°hj/ ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj, h²hh³hÊh´Nubj)�”}”(hŒ``kmemleak_free_part_phys``”h]”hÌ)�”}”(hjQ h]”hþ)�”}”(hjQ h]”hŒkmemleak_free_part_phys”…”�”}”(hjV h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjS ubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K±hjO ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj, h²hh³hÊh´Nubj)�”}”(hŒ``kmemleak_ignore_phys`` ”h]”hÌ)�”}”(hŒ``kmemleak_ignore_phys``”h]”hþ)�”}”(hju h]”hŒkmemleak_ignore_phys”…”�”}”(hjw h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjs ubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K²hjo ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj, h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”jcjduh1jüh³hÊh´K°hj¥h²hubeh}”(h]”Œ kmemleak-api”ah ]”h"]”Œ kmemleak api”ah$]”h&]”uh1hµhh·h²hh³hÊh´K—ubh¶)�”}”(hhh]”(h»)�”}”(hŒ&Dealing with false positives/negatives”h]”hŒ&Dealing with false positives/negatives”…”�”}”(hj¡ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjž h²hh³hÊh´KµubhÌ)�”}”(hX§The false negatives are real memory leaks (orphan objects) but not reported by kmemleak because values found during the memory scanning point to such objects. To reduce the number of false negatives, kmemleak provides the kmemleak_ignore, kmemleak_scan_area, kmemleak_no_scan and kmemleak_erase functions (see above). The task stacks also increase the amount of false negatives and their scanning is not enabled by default.”h]”hX§The false negatives are real memory leaks (orphan objects) but not reported by kmemleak because values found during the memory scanning point to such objects. To reduce the number of false negatives, kmemleak provides the kmemleak_ignore, kmemleak_scan_area, kmemleak_no_scan and kmemleak_erase functions (see above). The task stacks also increase the amount of false negatives and their scanning is not enabled by default.”…”�”}”(hj¯ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K·hjž h²hubhÌ)�”}”(hX)The false positives are objects wrongly reported as being memory leaks (orphan). For objects known not to be leaks, kmemleak provides the kmemleak_not_leak function. The kmemleak_ignore could also be used if the memory block is known not to contain other pointers and it will no longer be scanned.”h]”hX)The false positives are objects wrongly reported as being memory leaks (orphan). For objects known not to be leaks, kmemleak provides the kmemleak_not_leak function. The kmemleak_ignore could also be used if the memory block is known not to contain other pointers and it will no longer be scanned.”…”�”}”(hj½ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¾hjž h²hubhÌ)�”}”(hX Some of the reported leaks are only transient, especially on SMP systems, because of pointers temporarily stored in CPU registers or stacks. Kmemleak defines MSECS_MIN_AGE (defaulting to 1000) representing the minimum age of an object to be reported as a memory leak.”h]”hX Some of the reported leaks are only transient, especially on SMP systems, because of pointers temporarily stored in CPU registers or stacks. Kmemleak defines MSECS_MIN_AGE (defaulting to 1000) representing the minimum age of an object to be reported as a memory leak.”…”�”}”(hjË h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÄhjž h²hubhÌ)�”}”(hXSThe ``min_unref_scans`` module parameter requires an object to be seen unreferenced in that many consecutive scans before it is reported. It defaults to 2 when CONFIG_DEBUG_KMEMLEAK_VERBOSE is enabled, where the periodic scan thread confirms a leak on its own, and to 1 otherwise. A value of 1 preserves the historical behaviour; higher values filter the transient false positives described above, at the cost of delaying genuine reports by up to that many scans. It can be set at boot with ``kmemleak.min_unref_scans=`` or at run-time via ``/sys/module/kmemleak/parameters/min_unref_scans``.”h]”(hŒThe ”…”�”}”(hjÙ h²hh³Nh´Nubhþ)�”}”(hŒ``min_unref_scans``”h]”hŒmin_unref_scans”…”�”}”(hjá h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjÙ ubhXÔ module parameter requires an object to be seen unreferenced in that many consecutive scans before it is reported. It defaults to 2 when CONFIG_DEBUG_KMEMLEAK_VERBOSE is enabled, where the periodic scan thread confirms a leak on its own, and to 1 otherwise. A value of 1 preserves the historical behaviour; higher values filter the transient false positives described above, at the cost of delaying genuine reports by up to that many scans. It can be set at boot with ”…”�”}”(hjÙ h²hh³Nh´Nubhþ)�”}”(hŒ ``kmemleak.min_unref_scans=``”h]”hŒkmemleak.min_unref_scans=”…”�”}”(hjó h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjÙ ubhŒ or at run-time via ”…”�”}”(hjÙ h²hh³Nh´Nubhþ)�”}”(hŒ3``/sys/module/kmemleak/parameters/min_unref_scans``”h]”hŒ//sys/module/kmemleak/parameters/min_unref_scans”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjÙ ubhŒ.”…”�”}”(hjÙ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÉhjž h²hubeh}”(h]”Œ&dealing-with-false-positives-negatives”ah ]”h"]”Œ&dealing with false positives/negatives”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kµubh¶)�”}”(hhh]”(h»)�”}”(hŒLimitations and Drawbacks”h]”hŒLimitations and Drawbacks”…”�”}”(hj( h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj% h²hh³hÊh´KÔubhÌ)�”}”(hX8The main drawback is the reduced performance of memory allocation and freeing. To avoid other penalties, the memory scanning is only performed when the /sys/kernel/debug/kmemleak file is read. Anyway, this tool is intended for debugging purposes where the performance might not be the most important requirement.”h]”hX8The main drawback is the reduced performance of memory allocation and freeing. To avoid other penalties, the memory scanning is only performed when the /sys/kernel/debug/kmemleak file is read. Anyway, this tool is intended for debugging purposes where the performance might not be the most important requirement.”…”�”}”(hj6 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÖhj% h²hubhÌ)�”}”(hŒöTo keep the algorithm simple, kmemleak scans for values pointing to any address inside a block's address range. This may lead to an increased number of false negatives. However, it is likely that a real memory leak will eventually become visible.”h]”hŒøTo keep the algorithm simple, kmemleak scans for values pointing to any address inside a block’s address range. This may lead to an increased number of false negatives. However, it is likely that a real memory leak will eventually become visible.”…”�”}”(hjD h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÜhj% h²hubhÌ)�”}”(hŒõAnother source of false negatives is the data stored in non-pointer values. In a future version, kmemleak could only scan the pointer members in the allocated structures. This feature would solve many of the false negative cases described above.”h]”hŒõAnother source of false negatives is the data stored in non-pointer values. In a future version, kmemleak could only scan the pointer members in the allocated structures. This feature would solve many of the false negative cases described above.”…”�”}”(hjR h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Káhj% h²hubhÌ)�”}”(hXThe tool can report false positives. These are cases where an allocated block doesn't need to be freed (some cases in the init_call functions), the pointer is calculated by other methods than the usual container_of macro or the pointer is stored in a location not scanned by kmemleak.”h]”hXThe tool can report false positives. These are cases where an allocated block doesn’t need to be freed (some cases in the init_call functions), the pointer is calculated by other methods than the usual container_of macro or the pointer is stored in a location not scanned by kmemleak.”…”�”}”(hj` h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kæhj% h²hubhÌ)�”}”(hŒ-Page allocations and ioremap are not tracked.”h]”hŒ-Page allocations and ioremap are not tracked.”…”�”}”(hjn h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Këhj% h²hubeh}”(h]”Œlimitations-and-drawbacks”ah ]”h"]”Œlimitations and drawbacks”ah$]”h&]”uh1hµhh·h²hh³hÊh´KÔubh¶)�”}”(hhh]”(h»)�”}”(hŒTesting with kmemleak-test”h]”hŒTesting with kmemleak-test”…”�”}”(hj‡ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj„ h²hh³hÊh´KîubhÌ)�”}”(hXTo check if you have all set up to use kmemleak, you can use the kmemleak-test module, a module that deliberately leaks memory. Set CONFIG_SAMPLE_KMEMLEAK as module (it can't be used as built-in) and boot the kernel with kmemleak enabled. Load the module and perform a scan with::”h]”hXTo check if you have all set up to use kmemleak, you can use the kmemleak-test module, a module that deliberately leaks memory. Set CONFIG_SAMPLE_KMEMLEAK as module (it can’t be used as built-in) and boot the kernel with kmemleak enabled. Load the module and perform a scan with:”…”�”}”(hj• h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kðhj„ h²hubjI)�”}”(hŒA# modprobe kmemleak-test # echo scan > /sys/kernel/debug/kmemleak”h]”hŒA# modprobe kmemleak-test # echo scan > /sys/kernel/debug/kmemleak”…”�”}”hj£ sbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´Kõhj„ h²hubhÌ)�”}”(hŒËNote that the you may not get results instantly or on the first scanning. When kmemleak gets results, it'll log ``kmemleak: new suspected memory leaks``. Then read the file to see then::”h]”(hŒrNote that the you may not get results instantly or on the first scanning. When kmemleak gets results, it’ll log ”…”�”}”(hj± h²hh³Nh´Nubhþ)�”}”(hŒ9``kmemleak: new suspected memory leaks``”h]”hŒ5kmemleak: new suspected memory leaks”…”�”}”(hj¹ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhj± ubhŒ!. Then read the file to see then:”…”�”}”(hj± h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Køhj„ h²hubjI)�”}”(hX¾# cat /sys/kernel/debug/kmemleak unreferenced object 0xffff89862ca702e8 (size 32): comm "modprobe", pid 2088, jiffies 4294680594 (age 375.486s) hex dump (first 32 bytes): 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk. backtrace: [<00000000e0a73ec7>] 0xffffffffc01d2036 [<000000000c5d2a46>] do_one_initcall+0x41/0x1df [<0000000046db7e0a>] do_init_module+0x55/0x200 [<00000000542b9814>] load_module+0x203c/0x2480 [<00000000c2850256>] __do_sys_finit_module+0xba/0xe0 [<000000006564e7ef>] do_syscall_64+0x43/0x110 [<000000007c873fa6>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 ...”h]”hX¾# cat /sys/kernel/debug/kmemleak unreferenced object 0xffff89862ca702e8 (size 32): comm "modprobe", pid 2088, jiffies 4294680594 (age 375.486s) hex dump (first 32 bytes): 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk. backtrace: [<00000000e0a73ec7>] 0xffffffffc01d2036 [<000000000c5d2a46>] do_one_initcall+0x41/0x1df [<0000000046db7e0a>] do_init_module+0x55/0x200 [<00000000542b9814>] load_module+0x203c/0x2480 [<00000000c2850256>] __do_sys_finit_module+0xba/0xe0 [<000000006564e7ef>] do_syscall_64+0x43/0x110 [<000000007c873fa6>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 ...”…”�”}”hjÑ sbah}”(h]”h ]”h"]”h$]”h&]”jXjYuh1jHh³hÊh´Kühj„ h²hubhÌ)�”}”(hŒ[Removing the module with ``rmmod kmemleak_test`` should also trigger some kmemleak results.”h]”(hŒRemoving the module with ”…”�”}”(hjß h²hh³Nh´Nubhþ)�”}”(hŒ``rmmod kmemleak_test``”h]”hŒrmmod kmemleak_test”…”�”}”(hjç h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýhjß ubhŒ+ should also trigger some kmemleak results.”…”�”}”(hjß h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M hj„ h²hubeh}”(h]”Œtesting-with-kmemleak-test”ah ]”h"]”Œtesting with kmemleak-test”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kîubeh}”(h]”Œkernel-memory-leak-detector”ah ]”h"]”Œkernel memory leak detector”ah$]”h&]”uh1hµhhh²hh³hÊh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÊuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)�”}”(hºNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”j2 Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÊŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(j j hôhñjÆjÃjjýj_j\j¢jŸj› j˜ j" j j� j~ j j uŒ nametypes”}”(j ‰hôˆjƉj‰j_‰j¢‰j› ‰j" ‰j� ‰j ‰uh}”(j h·hñhëjÃjjýjÉj\jjŸjbj˜ j¥j jž j~ j% j j„ uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.