€•’DŒ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/mm/allocation-profiling”Œ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/mm/allocation-profiling”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/it_IT/mm/allocation-profiling”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/ja_JP/mm/allocation-profiling”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/ko_KR/mm/allocation-profiling”Œ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/mm/allocation-profiling”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ SPDX-License-Identifier: GPL-2.0”h]”hŒ SPDX-License-Identifier: GPL-2.0”…””}”hh£sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1h¡hhhžhhŸŒE/var/lib/git/docbuild/linux/Documentation/mm/allocation-profiling.rst”h KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒMEMORY ALLOCATION PROFILING”h]”hŒMEMORY ALLOCATION PROFILING”…””}”(hh»hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hh¶hžhhŸh³h KubhŒ paragraph”“”)”}”(hŒmLow overhead (suitable for production) accounting of all memory allocations, tracked by file and line number.”h]”hŒmLow overhead (suitable for production) accounting of all memory allocations, tracked by file and line number.”…””}”(hhËhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hŒ4Usage: kconfig options: - CONFIG_MEM_ALLOC_PROFILING”h]”hŒ4Usage: kconfig options: - CONFIG_MEM_ALLOC_PROFILING”…””}”(hhÙhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K hh¶hžhubhŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒ.CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT ”h]”hÊ)”}”(hŒ-CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT”h]”hŒ-CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT”…””}”(hhòhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khhîubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhhéhžhhŸh³h Nubhí)”}”(hŒvCONFIG_MEM_ALLOC_PROFILING_DEBUG adds warnings for allocations that weren't accounted because of a missing annotation ”h]”hÊ)”}”(hŒuCONFIG_MEM_ALLOC_PROFILING_DEBUG adds warnings for allocations that weren't accounted because of a missing annotation”h]”hŒwCONFIG_MEM_ALLOC_PROFILING_DEBUG adds warnings for allocations that weren’t accounted because of a missing annotation”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khjubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhhéhžhhŸh³h Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1hçhŸh³h Khh¶hžhubhŒdefinition_list”“”)”}”(hhh]”(hŒdefinition_list_item”“”)”}”(hX©Boot parameter: sysctl.vm.mem_profiling={0|1|never}[,compressed] When set to "never", memory allocation profiling overhead is minimized and it cannot be enabled at runtime (sysctl becomes read-only). When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=y, default value is "1". When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=n, default value is "never". "compressed" optional parameter will try to store page tag references in a compact format, avoiding page extensions. This results in improved performance and memory consumption, however it might fail depending on system configuration. If compression fails, a warning is issued and memory allocation profiling gets disabled. ”h]”(hŒterm”“”)”}”(hŒBoot parameter:”h]”hŒBoot parameter:”…””}”(hj3hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j1hŸh³h Khj-ubhŒ definition”“”)”}”(hhh]”(hÊ)”}”(hŒ0sysctl.vm.mem_profiling={0|1|never}[,compressed]”h]”hŒ0sysctl.vm.mem_profiling={0|1|never}[,compressed]”…””}”(hjFhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KhjCubhÊ)”}”(hXfWhen set to "never", memory allocation profiling overhead is minimized and it cannot be enabled at runtime (sysctl becomes read-only). When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=y, default value is "1". When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=n, default value is "never". "compressed" optional parameter will try to store page tag references in a compact format, avoiding page extensions. This results in improved performance and memory consumption, however it might fail depending on system configuration. If compression fails, a warning is issued and memory allocation profiling gets disabled.”h]”hXvWhen set to “neverâ€, memory allocation profiling overhead is minimized and it cannot be enabled at runtime (sysctl becomes read-only). When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=y, default value is “1â€. When CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=n, default value is “neverâ€. “compressed†optional parameter will try to store page tag references in a compact format, avoiding page extensions. This results in improved performance and memory consumption, however it might fail depending on system configuration. If compression fails, a warning is issued and memory allocation profiling gets disabled.”…””}”(hjThžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KhjCubeh}”(h]”h ]”h"]”h$]”h&]”uh1jAhj-ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j+hŸh³h Khj(ubj,)”}”(hŒ#sysctl: /proc/sys/vm/mem_profiling ”h]”(j2)”}”(hŒsysctl:”h]”hŒsysctl:”…””}”(hjrhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j1hŸh³h K"hjnubjB)”}”(hhh]”hÊ)”}”(hŒ/proc/sys/vm/mem_profiling”h]”hŒ/proc/sys/vm/mem_profiling”…””}”(hjƒhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K"hj€ubah}”(h]”h ]”h"]”h$]”h&]”uh1jAhjnubeh}”(h]”h ]”h"]”h$]”h&]”uh1j+hŸh³h K"hj(hžhubj,)”}”(hŒRuntime info: /proc/allocinfo ”h]”(j2)”}”(hŒ Runtime info:”h]”hŒ Runtime info:”…””}”(hj¡hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j1hŸh³h K%hjubjB)”}”(hhh]”hÊ)”}”(hŒ/proc/allocinfo”h]”hŒ/proc/allocinfo”…””}”(hj²hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K%hj¯ubah}”(h]”h ]”h"]”h$]”h&]”uh1jAhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1j+hŸh³h K%hj(hžhubeh}”(h]”h ]”h"]”h$]”h&]”uh1j&hh¶hžhhŸh³h NubhÊ)”}”(hŒExample output::”h]”hŒExample output:”…””}”(hjÒhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K'hh¶hžhubhŒ literal_block”“”)”}”(hXroot@moria-kvm:~# sort -g /proc/allocinfo|tail|numfmt --to=iec 2.8M 22648 fs/kernfs/dir.c:615 func:__kernfs_new_node 3.8M 953 mm/memory.c:4214 func:alloc_anon_folio 4.0M 1010 drivers/staging/ctagmod/ctagmod.c:20 [ctagmod] func:ctagmod_start 4.1M 4 net/netfilter/nf_conntrack_core.c:2567 func:nf_ct_alloc_hashtable 6.0M 1532 mm/filemap.c:1919 func:__filemap_get_folio 8.8M 2785 kernel/fork.c:307 func:alloc_thread_stack_node 13M 234 block/blk-mq.c:3421 func:blk_mq_alloc_rqs 14M 3520 mm/mm_init.c:2530 func:alloc_large_system_hash 15M 3656 mm/readahead.c:247 func:page_cache_ra_unbounded 55M 4887 mm/slub.c:2259 func:alloc_slab_page 122M 31168 mm/page_ext.c:270 func:alloc_page_ext”h]”hXroot@moria-kvm:~# sort -g /proc/allocinfo|tail|numfmt --to=iec 2.8M 22648 fs/kernfs/dir.c:615 func:__kernfs_new_node 3.8M 953 mm/memory.c:4214 func:alloc_anon_folio 4.0M 1010 drivers/staging/ctagmod/ctagmod.c:20 [ctagmod] func:ctagmod_start 4.1M 4 net/netfilter/nf_conntrack_core.c:2567 func:nf_ct_alloc_hashtable 6.0M 1532 mm/filemap.c:1919 func:__filemap_get_folio 8.8M 2785 kernel/fork.c:307 func:alloc_thread_stack_node 13M 234 block/blk-mq.c:3421 func:blk_mq_alloc_rqs 14M 3520 mm/mm_init.c:2530 func:alloc_large_system_hash 15M 3656 mm/readahead.c:247 func:page_cache_ra_unbounded 55M 4887 mm/slub.c:2259 func:alloc_slab_page 122M 31168 mm/page_ext.c:270 func:alloc_page_ext”…””}”hjâsbah}”(h]”h ]”h"]”h$]”h&]”h±h²uh1jàhŸh³h K)hh¶hžhubhµ)”}”(hhh]”(hº)”}”(hŒTheory of operation”h]”hŒTheory of operation”…””}”(hjóhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hjðhžhhŸh³h K7ubhÊ)”}”(hX'Memory allocation profiling builds off of code tagging, which is a library for declaring static structs (that typically describe a file and line number in some way, hence code tagging) and then finding and operating on them at runtime, - i.e. iterating over them to print them in debugfs/procfs.”h]”hX'Memory allocation profiling builds off of code tagging, which is a library for declaring static structs (that typically describe a file and line number in some way, hence code tagging) and then finding and operating on them at runtime, - i.e. iterating over them to print them in debugfs/procfs.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K9hjðhžhubhÊ)”}”(hXTo add accounting for an allocation call, we replace it with a macro invocation, alloc_hooks(), that - declares a code tag - stashes a pointer to it in task_struct - calls the real allocation function - and finally, restores the task_struct alloc tag pointer to its previous value.”h]”hXTo add accounting for an allocation call, we replace it with a macro invocation, alloc_hooks(), that - declares a code tag - stashes a pointer to it in task_struct - calls the real allocation function - and finally, restores the task_struct alloc tag pointer to its previous value.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K>hjðhžhubhÊ)”}”(hXXThis allows for alloc_hooks() calls to be nested, with the most recent one taking effect. This is important for allocations internal to the mm/ code that do not properly belong to the outer allocation context and should be counted separately: for example, slab object extension vectors, or when the slab allocates pages from the page allocator.”h]”hXXThis allows for alloc_hooks() calls to be nested, with the most recent one taking effect. This is important for allocations internal to the mm/ code that do not properly belong to the outer allocation context and should be counted separately: for example, slab object extension vectors, or when the slab allocates pages from the page allocator.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KEhjðhžhubhÊ)”}”(hXVThus, proper usage requires determining which function in an allocation call stack should be tagged. There are many helper functions that essentially wrap e.g. kmalloc() and do a little more work, then are called in multiple places; we'll generally want the accounting to happen in the callers of these helpers, not in the helpers themselves.”h]”hXXThus, proper usage requires determining which function in an allocation call stack should be tagged. There are many helper functions that essentially wrap e.g. kmalloc() and do a little more work, then are called in multiple places; we’ll generally want the accounting to happen in the callers of these helpers, not in the helpers themselves.”…””}”(hj+hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KKhjðhžhubhÊ)”}”(hŒ‹To fix up a given helper, for example foo(), do the following: - switch its allocation call to the _noprof() version, e.g. kmalloc_noprof()”h]”hŒ‹To fix up a given helper, for example foo(), do the following: - switch its allocation call to the _noprof() version, e.g. kmalloc_noprof()”…””}”(hj9hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KQhjðhžhubhè)”}”(hhh]”(hí)”}”(hŒrename it to foo_noprof() ”h]”hÊ)”}”(hŒrename it to foo_noprof()”h]”hŒrename it to foo_noprof()”…””}”(hjNhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KThjJubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhjGhžhhŸh³h Nubhí)”}”(hŒ`define a macro version of foo() like so: #define foo(...) alloc_hooks(foo_noprof(__VA_ARGS__)) ”h]”(hÊ)”}”(hŒ(define a macro version of foo() like so:”h]”hŒ(define a macro version of foo() like so:”…””}”(hjfhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KVhjbubhÊ)”}”(hŒ5#define foo(...) alloc_hooks(foo_noprof(__VA_ARGS__))”h]”hŒ5#define foo(...) alloc_hooks(foo_noprof(__VA_ARGS__))”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KXhjbubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjGhžhhŸh³h Nubeh}”(h]”h ]”h"]”h$]”h&]”j$j%uh1hçhŸh³h KThjðhžhubhÊ)”}”(hŒRIt's also possible to stash a pointer to an alloc tag in your own data structures.”h]”hŒTIt’s also possible to stash a pointer to an alloc tag in your own data structures.”…””}”(hjŽhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KZhjðhžhubhÊ)”}”(hXDo this when you're implementing a generic data structure that does allocations "on behalf of" some other code - for example, the rhashtable code. This way, instead of seeing a large line in /proc/allocinfo for rhashtable.c, we can break it out by rhashtable type.”h]”hXDo this when you’re implementing a generic data structure that does allocations “on behalf of†some other code - for example, the rhashtable code. This way, instead of seeing a large line in /proc/allocinfo for rhashtable.c, we can break it out by rhashtable type.”…””}”(hjœhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K\hjðhžhubhÊ)”}”(hŒYTo do so: - Hook your data structure's init function, like any other allocation function.”h]”hŒ[To do so: - Hook your data structure’s init function, like any other allocation function.”…””}”(hjªhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Kahjðhžhubhè)”}”(hhh]”(hí)”}”(hŒtWithin your init function, use the convenience macro alloc_tag_record() to record alloc tag in your data structure. ”h]”hÊ)”}”(hŒsWithin your init function, use the convenience macro alloc_tag_record() to record alloc tag in your data structure.”h]”hŒsWithin your init function, use the convenience macro alloc_tag_record() to record alloc tag in your data structure.”…””}”(hj¿hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Kdhj»ubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhj¸hžhhŸh³h Nubhí)”}”(hŒkThen, use the following form for your allocations: alloc_hooks_tag(ht->your_saved_tag, kmalloc_noprof(...))”h]”hÊ)”}”(hŒkThen, use the following form for your allocations: alloc_hooks_tag(ht->your_saved_tag, kmalloc_noprof(...))”h]”hŒkThen, use the following form for your allocations: alloc_hooks_tag(ht->your_saved_tag, kmalloc_noprof(...))”…””}”(hj×hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KghjÓubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhj¸hžhhŸh³h Nubeh}”(h]”h ]”h"]”h$]”h&]”j$j%uh1hçhŸh³h Kdhjðhžhubeh}”(h]”Œtheory-of-operation”ah ]”h"]”Œtheory of operation”ah$]”h&]”uh1h´hh¶hžhhŸh³h K7ubeh}”(h]”Œmemory-allocation-profiling”ah ]”h"]”Œmemory allocation profiling”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”j$Œ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ûjöjóuŒ nametypes”}”(jþ‰jö‰uh}”(jûh¶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.