linux/arch/arm
Kent Overstreet 0069455bcb fix missing vmalloc.h includes
Patch series "Memory allocation profiling", v6.

Overview:
Low overhead [1] per-callsite memory allocation profiling. Not just for
debug kernels, overhead low enough to be deployed in production.

Example output:
  root@moria-kvm:~# sort -rn /proc/allocinfo
   127664128    31168 mm/page_ext.c:270 func:alloc_page_ext
    56373248     4737 mm/slub.c:2259 func:alloc_slab_page
    14880768     3633 mm/readahead.c:247 func:page_cache_ra_unbounded
    14417920     3520 mm/mm_init.c:2530 func:alloc_large_system_hash
    13377536      234 block/blk-mq.c:3421 func:blk_mq_alloc_rqs
    11718656     2861 mm/filemap.c:1919 func:__filemap_get_folio
     9192960     2800 kernel/fork.c:307 func:alloc_thread_stack_node
     4206592        4 net/netfilter/nf_conntrack_core.c:2567 func:nf_ct_alloc_hashtable
     4136960     1010 drivers/staging/ctagmod/ctagmod.c:20 [ctagmod] func:ctagmod_start
     3940352      962 mm/memory.c:4214 func:alloc_anon_folio
     2894464    22613 fs/kernfs/dir.c:615 func:__kernfs_new_node
     ...

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

sysctl:
  /proc/sys/vm/mem_profiling

Runtime info:
  /proc/allocinfo

Notes:

[1]: Overhead
To measure the overhead we are comparing the following configurations:
(1) Baseline with CONFIG_MEMCG_KMEM=n
(2) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=y &&
    CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n)
(3) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=y &&
    CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=y)
(4) Enabled at runtime (CONFIG_MEM_ALLOC_PROFILING=y &&
    CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n && /proc/sys/vm/mem_profiling=1)
(5) Baseline with CONFIG_MEMCG_KMEM=y && allocating with __GFP_ACCOUNT
(6) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=y &&
    CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n)  && CONFIG_MEMCG_KMEM=y
(7) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=y &&
    CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=y) && CONFIG_MEMCG_KMEM=y

Performance overhead:
To evaluate performance we implemented an in-kernel test executing
multiple get_free_page/free_page and kmalloc/kfree calls with allocation
sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU
affinity set to a specific CPU to minimize the noise. Below are results
from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on
56 core Intel Xeon:

                        kmalloc                 pgalloc
(1 baseline)            6.764s                  16.902s
(2 default disabled)    6.793s  (+0.43%)        17.007s (+0.62%)
(3 default enabled)     7.197s  (+6.40%)        23.666s (+40.02%)
(4 runtime enabled)     7.405s  (+9.48%)        23.901s (+41.41%)
(5 memcg)               13.388s (+97.94%)       48.460s (+186.71%)
(6 def disabled+memcg)  13.332s (+97.10%)       48.105s (+184.61%)
(7 def enabled+memcg)   13.446s (+98.78%)       54.963s (+225.18%)

Memory overhead:
Kernel size:

   text           data        bss         dec         diff
(1) 26515311	      18890222    17018880    62424413
(2) 26524728	      19423818    16740352    62688898    264485
(3) 26524724	      19423818    16740352    62688894    264481
(4) 26524728	      19423818    16740352    62688898    264485
(5) 26541782	      18964374    16957440    62463596    39183

Memory consumption on a 56 core Intel CPU with 125GB of memory:
Code tags:           192 kB
PageExts:         262144 kB (256MB)
SlabExts:           9876 kB (9.6MB)
PcpuExts:            512 kB (0.5MB)

Total overhead is 0.2% of total memory.

Benchmarks:

Hackbench tests run 100 times:
hackbench -s 512 -l 200 -g 15 -f 25 -P
      baseline       disabled profiling           enabled profiling
avg   0.3543         0.3559 (+0.0016)             0.3566 (+0.0023)
stdev 0.0137         0.0188                       0.0077


hackbench -l 10000
      baseline       disabled profiling           enabled profiling
avg   6.4218         6.4306 (+0.0088)             6.5077 (+0.0859)
stdev 0.0933         0.0286                       0.0489

stress-ng tests:
stress-ng --class memory --seq 4 -t 60
stress-ng --class cpu --seq 4 -t 60
Results posted at: https://evilpiepirate.org/~kent/memalloc_prof_v4_stress-ng/

[2] https://lore.kernel.org/all/20240306182440.2003814-1-surenb@google.com/


This patch (of 37):

The next patch drops vmalloc.h from a system header in order to fix a
circular dependency; this adds it to all the files that were pulling it in
implicitly.

[kent.overstreet@linux.dev: fix arch/alpha/lib/memcpy.c]
  Link: https://lkml.kernel.org/r/20240327002152.3339937-1-kent.overstreet@linux.dev
[surenb@google.com: fix arch/x86/mm/numa_32.c]
  Link: https://lkml.kernel.org/r/20240402180933.1663992-1-surenb@google.com
[kent.overstreet@linux.dev: a few places were depending on sizes.h]
  Link: https://lkml.kernel.org/r/20240404034744.1664840-1-kent.overstreet@linux.dev
[arnd@arndb.de: fix mm/kasan/hw_tags.c]
  Link: https://lkml.kernel.org/r/20240404124435.3121534-1-arnd@kernel.org
[surenb@google.com: fix arc build]
  Link: https://lkml.kernel.org/r/20240405225115.431056-1-surenb@google.com
Link: https://lkml.kernel.org/r/20240321163705.3067592-1-surenb@google.com
Link: https://lkml.kernel.org/r/20240321163705.3067592-2-surenb@google.com
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Tested-by: Kees Cook <keescook@chromium.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andreas Hindborg <a.hindborg@samsung.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: "Björn Roy Baron" <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Gary Guo <gary@garyguo.net>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Wedson Almeida Filho <wedsonaf@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-04-25 20:55:49 -07:00
..
boot ARM: dts: imx7s-warp: Pass OV2680 link-frequencies 2024-04-03 08:50:36 +08:00
common locomo: make locomo_bus_type constant and static 2024-01-04 14:38:57 +01:00
configs - Sumanth Korikkar has taught s390 to allocate hotplug-time page frames 2024-03-14 17:43:30 -07:00
crypto crypto: arm/sha - fix function cast warnings 2024-02-24 08:41:19 +08:00
include mm/arm: remove pmd_thp_or_huge() 2024-04-25 20:55:47 -07:00
kernel fix missing vmalloc.h includes 2024-04-25 20:55:49 -07:00
lib mm/arm: remove pmd_thp_or_huge() 2024-04-25 20:55:47 -07:00
mach-actions
mach-alpine ARM: alpine: Drop unused includes 2023-08-12 10:30:59 +02:00
mach-artpec
mach-aspeed
mach-at91 ARM: at91: pm: set soc_pm.data.mode in at91_pm_secure_init() 2023-11-19 11:32:44 +02:00
mach-axxia
mach-bcm ARM: bcm: stop selecing CONFIG_TICK_ONESHOT 2024-02-28 10:32:25 -08:00
mach-berlin ARM: berlin: Drop unused includes 2023-08-12 10:30:59 +02:00
mach-clps711x
mach-davinci ARM updates for v6.8-rc1 2024-01-17 11:34:45 -08:00
mach-digicolor
mach-dove ARM: dove: Drop unused includes 2023-08-12 10:30:59 +02:00
mach-ep93xx ARM: ep93xx: Add terminator to gpiod_lookup_table 2024-02-20 17:19:49 +01:00
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi ARM: hisi: Drop unused includes 2023-07-19 06:29:04 +00:00
mach-hpe ARM: hpe: Drop unused includes 2023-08-12 10:30:59 +02:00
mach-imx ARM: imx: Remove usage of the deprecated ida_simple_xx() API 2024-02-05 17:23:28 +08:00
mach-ixp4xx
mach-keystone ARM: keystone: Merge PM function into main support file 2023-08-01 23:57:28 -05:00
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson ARM: meson: Drop unused includes 2023-07-31 11:58:18 +02:00
mach-milbeaut
mach-mmp ARM: mmp: Drop unused includes 2023-08-12 10:31:00 +02:00
mach-mstar
mach-mv78xx0
mach-mvebu ARM: mvebu: Explicitly include correct DT includes 2023-08-12 10:31:00 +02:00
mach-mxs ARM: mxs: Do not search for "fsl,clkctrl" 2023-12-06 11:21:43 +08:00
mach-nomadik ARM: nomadik: Drop unused includes 2023-08-12 10:31:00 +02:00
mach-npcm ARM: npcm: Drop unused includes 2023-08-12 10:31:00 +02:00
mach-omap1 ARM: omap1: remove duplicated 'select ARCH_OMAP' 2024-02-28 09:27:20 +02:00
mach-omap2 GPIO regression fixes for n8x0 2024-04-09 16:17:37 +02:00
mach-orion5x
mach-pxa ARM: SoC cleanups for 6.6 2023-08-30 16:49:40 -07:00
mach-qcom ARM: qcom: merge remaining subplatforms into sensible Kconfig entry 2024-02-06 15:00:02 -06:00
mach-realtek
mach-rockchip ARM: rockchip: Drop unused includes 2023-08-12 10:31:00 +02:00
mach-rpc
mach-s3c ARM: s3c64xx: make bus_type const 2024-02-12 08:28:44 +01:00
mach-s5pv210 ARM: s5pv210: fix pm.c kernel-doc warning 2024-01-22 11:44:16 +01:00
mach-sa1100 ARM: locomo: fix locomolcd_power declaration 2023-09-28 09:15:51 +02:00
mach-shmobile ARM: shmobile: sh73a0: Reserve boot area when SMP is enabled 2023-09-27 11:00:27 +02:00
mach-socfpga ARM: socfpga: Explicitly include correct DT includes 2023-07-20 14:38:38 -05:00
mach-spear ARM: spear: Explicitly include correct DT includes 2023-08-12 10:31:01 +02:00
mach-sti ARM: sti: Drop unused includes 2023-08-12 10:30:59 +02:00
mach-stm32
mach-sunxi ARM: sun9i: smp: fix return code check of of_property_match_string 2024-01-02 16:45:16 +01:00
mach-tegra
mach-ux500 ARM: ux500: Move power-domain driver to the genpd dir 2023-07-14 10:41:59 +02:00
mach-versatile ARM: Delete ARM11MPCore (ARM11 ARMv6K SMP) support 2023-12-22 11:43:16 +00:00
mach-vt8500
mach-zynq ARM: zynq: Remove clk/zynq.h header 2024-01-22 14:22:10 +01:00
mm mm/treewide: remove pXd_huge() 2024-04-25 20:55:47 -07:00
net arm32, bpf: add support for 64 bit division instruction 2023-09-15 17:16:56 -07:00
nwfpe
plat-orion
probes
tools lsm/stable-6.8 PR 20240105 2024-01-09 12:57:46 -08:00
vdso arch: vdso: consolidate gettime prototypes 2023-11-23 11:32:32 +01:00
vfp ARM: 9327/1: vfp: Add missing VFP instructions to neon_support_hook 2023-12-05 11:40:27 +00:00
xen arm/xen: fix xen_vcpu_info allocation alignment 2023-11-23 09:32:41 +01:00
Kbuild
Kconfig ARM updates for v6.9-rc1 2024-03-23 09:17:03 -07:00
Kconfig-nommu
Kconfig.assembler
Kconfig.debug ARM updates for v6.9-rc1 2024-03-23 09:17:03 -07:00
Kconfig.platforms ARM: mach-nspire: Rework support and directory structure 2023-12-22 14:23:30 +00:00
Makefile ARM: qcom: merge remaining subplatforms into sensible Kconfig entry 2024-02-06 15:00:02 -06:00