Signed-off-by: Randy Dunlap --- Documentation/mm/allocation-profiling.rst | 28 ++++++++++---------- Documentation/mm/index.rst | 1 2 files changed, 16 insertions(+), 13 deletions(-) diff -- a/Documentation/mm/allocation-profiling.rst b/Documentation/mm/allocation-profiling.rst --- a/Documentation/mm/allocation-profiling.rst +++ b/Documentation/mm/allocation-profiling.rst @@ -9,11 +9,11 @@ tracked by file and line number. Usage: kconfig options: - - CONFIG_MEM_ALLOC_PROFILING - - CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT - - CONFIG_MEM_ALLOC_PROFILING_DEBUG - adds warnings for allocations that weren't accounted because of a - missing annotation +- CONFIG_MEM_ALLOC_PROFILING +- CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT +- CONFIG_MEM_ALLOC_PROFILING_DEBUG +adds warnings for allocations that weren't accounted because of a +missing annotation Boot parameter: sysctl.vm.mem_profiling=0|1|never @@ -29,7 +29,8 @@ sysctl: Runtime info: /proc/allocinfo -Example output: +Example output:: + root@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 @@ -42,21 +43,22 @@ Example output: 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 + =================== Theory of operation =================== Memory allocation profiling builds off of code tagging, which is a library for declaring static structs (that typcially 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. +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. To 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. +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. This 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 diff -- a/Documentation/mm/index.rst b/Documentation/mm/index.rst --- a/Documentation/mm/index.rst +++ b/Documentation/mm/index.rst @@ -26,6 +26,7 @@ see the :doc:`admin guide <../admin-guid page_cache shmfs oom + allocation-profiling Legacy Documentation ====================