1
0
Fork 0
alistair23-linux/scripts
Andrii Nakryiko 5f9ae91f7c kbuild: Build kernel module BTFs if BTF is enabled and pahole supports it
Detect if pahole supports split BTF generation, and generate BTF for each
selected kernel module, if it does. This is exposed to Makefiles and C code as
CONFIG_DEBUG_INFO_BTF_MODULES flag.

Kernel module BTF has to be re-generated if either vmlinux's BTF changes or
module's .ko changes. To achieve that, I needed a helper similar to
if_changed, but that would allow to filter out vmlinux from the list of
updated dependencies for .ko building. I've put it next to the only place that
uses and needs it, but it might be a better idea to just add it along the
other if_changed variants into scripts/Kbuild.include.

Each kernel module's BTF deduplication is pretty fast, as it does only
incremental BTF deduplication on top of already deduplicated vmlinux BTF. To
show the added build time, I've first ran make only just built kernel (to
establish the baseline) and then forced only BTF re-generation, without
regenerating .ko files. The build was performed with -j60 parallelization on
56-core machine. The final time also includes bzImage building, so it's not
a pure BTF overhead.

$ time make -j60
...
make -j60  27.65s user 10.96s system 782% cpu 4.933 total
$ touch ~/linux-build/default/vmlinux && time make -j60
...
make -j60  123.69s user 27.85s system 1566% cpu 9.675 total

So 4.6 seconds real time, with noticeable part spent in compressed vmlinux and
bzImage building.

To show size savings, I've built my kernel configuration with about 700 kernel
modules with full BTF per each kernel module (without deduplicating against
vmlinux) and with split BTF against deduplicated vmlinux (approach in this
patch). Below are top 10 modules with biggest BTF sizes. And total size of BTF
data across all kernel modules.

It shows that split BTF "compresses" 115MB down to 5MB total. And the biggest
kernel modules get a downsize from 500-570KB down to 200-300KB.

FULL BTF
========

$ for f in $(find . -name '*.ko'); do size -A -d $f | grep BTF | awk '{print $2}'; done | awk '{ s += $1 } END { print s }'
115710691

$ for f in $(find . -name '*.ko'); do printf "%s %d\n" $f $(size -A -d $f | grep BTF | awk '{print $2}'); done | sort -nr -k2 | head -n10
./drivers/gpu/drm/i915/i915.ko 570570
./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko 520240
./drivers/gpu/drm/radeon/radeon.ko 503849
./drivers/infiniband/hw/mlx5/mlx5_ib.ko 491777
./fs/xfs/xfs.ko 411544
./drivers/net/ethernet/intel/i40e/i40e.ko 403904
./drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko 398754
./drivers/infiniband/core/ib_core.ko 397224
./fs/cifs/cifs.ko 386249
./fs/nfsd/nfsd.ko 379738

SPLIT BTF
=========

$ for f in $(find . -name '*.ko'); do size -A -d $f | grep BTF | awk '{print $2}'; done | awk '{ s += $1 } END { print s }'
5194047

$ for f in $(find . -name '*.ko'); do printf "%s %d\n" $f $(size -A -d $f | grep BTF | awk '{print $2}'); done | sort -nr -k2 | head -n10
./drivers/gpu/drm/i915/i915.ko 293206
./drivers/gpu/drm/radeon/radeon.ko 282103
./fs/xfs/xfs.ko 222150
./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko 198503
./drivers/infiniband/hw/mlx5/mlx5_ib.ko 198356
./drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko 113444
./fs/cifs/cifs.ko 109379
./arch/x86/kvm/kvm.ko 100225
./drivers/gpu/drm/drm.ko 94827
./drivers/infiniband/core/ib_core.ko 91188

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201110011932.3201430-4-andrii@kernel.org
2020-11-10 15:25:53 -08:00
..
atomic Merge branch 'kcsan' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu into locking/core 2020-10-09 08:56:02 +02:00
basic kbuild: introduce hostprogs-always-y and userprogs-always-y 2020-08-10 01:32:59 +09:00
clang-tools Makefile: Add clang-tidy and static analyzer support to makefile 2020-08-27 00:44:33 +09:00
coccinelle Merge branch 'for-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux 2020-10-18 14:20:35 -07:00
dtc scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea121 2020-10-12 09:58:15 -05:00
dummy-tools kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig 2020-04-09 00:13:45 +09:00
gcc-plugins Kbuild updates for v5.9 2020-08-09 14:10:26 -07:00
gdb scripts/gdb/tasks: add headers and improve spacing format 2020-10-16 11:11:22 -07:00
genksyms genksyms: keywords: Use __restrict not _restrict 2020-08-18 20:16:46 +09:00
kconfig Kconfig updates for v5.10 2020-10-22 13:20:39 -07:00
ksymoops
mod Kbuild updates for v5.9 2020-08-09 14:10:26 -07:00
package kbuild: deb-pkg: clean up package name variables 2020-10-14 12:49:39 +09:00
selinux scripts/selinux,selinux: update mdp to enable policy capabilities 2020-08-17 20:42:00 -04:00
tracing treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
.gitignore kbuild: preprocess module linker script 2020-09-25 00:36:41 +09:00
Kbuild.include kbuild: remove leftover comment for filechk utility 2020-10-21 00:28:53 +09:00
Kconfig.include kconfig: unify cc-option and as-option 2020-06-17 10:38:42 +09:00
Lindent
Makefile kbuild: preprocess module linker script 2020-09-25 00:36:41 +09:00
Makefile.asm-generic kbuild: force all architectures except um to include mandatory-y 2019-03-17 12:56:32 +09:00
Makefile.build treewide: remove DISABLE_LTO 2020-10-21 00:28:53 +09:00
Makefile.clean kbuild: introduce hostprogs-always-y and userprogs-always-y 2020-08-10 01:32:59 +09:00
Makefile.dtbinst kbuild: refactor Makefile.dtbinst more 2020-03-25 10:19:43 +09:00
Makefile.extrawarn Makefile.extrawarn: Move sign-compare from W=2 to W=3 2020-08-18 01:52:08 +09:00
Makefile.gcc-plugins gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving 2020-06-24 07:48:28 -07:00
Makefile.headersinst kbuild: move headers_check rule to usr/include/Makefile 2019-11-15 00:23:10 +09:00
Makefile.host kbuild: sort hostprogs before passing it to ifneq 2020-08-10 01:32:59 +09:00
Makefile.kasan kbuild: move CFLAGS_{KASAN,UBSAN,KCSAN} exports to relevant Makefiles 2020-09-25 00:36:50 +09:00
Makefile.kcov kbuild: include scripts/Makefile.* only when relevant CONFIG is enabled 2020-08-10 01:32:59 +09:00
Makefile.kcsan Kbuild updates for v5.10 2020-10-22 13:13:57 -07:00
Makefile.lib dt-bindings: Use json for processed-schema* 2020-08-19 14:31:57 -06:00
Makefile.modfinal kbuild: Build kernel module BTFs if BTF is enabled and pahole supports it 2020-11-10 15:25:53 -08:00
Makefile.modinst kbuild: modinst: read modules.order instead of $(MODVERDIR)/*.mod 2019-07-17 22:39:27 +09:00
Makefile.modpost kbuild: remove redundant FORCE definition in scripts/Makefile.modpost 2020-08-02 23:09:16 +09:00
Makefile.modsign kbuild: modsign: read modules.order instead of $(MODVERDIR)/*.mod 2019-07-17 22:39:27 +09:00
Makefile.package kbuild: fix broken builds because of GZIP,BZIP2,LZOP variables 2020-06-11 20:14:41 +09:00
Makefile.ubsan Kbuild updates for v5.10 2020-10-22 13:13:57 -07:00
Makefile.userprogs kbuild: add infrastructure to build userspace programs 2020-05-17 18:52:01 +09:00
adjust_autoksyms.sh kbuild: split adjust_autoksyms.sh in two parts 2020-03-03 20:49:21 +09:00
asn1_compiler.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 36 2019-05-24 17:27:11 +02:00
bin2c.c kbuild: move bin2c back to scripts/ from scripts/basic/ 2018-07-18 01:18:05 +09:00
bloat-o-meter scripts/bloat-o-meter: Support comparing library archives 2020-08-07 11:33:21 -07:00
bootgraph.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 391 2019-06-05 17:37:11 +02:00
bpf_helpers_doc.py bpf: Fix bpf_redirect_neigh helper api to support supplying nexthop 2020-10-22 01:28:54 +02:00
cc-can-link.sh
check-sysctl-docs docs: add a script to check sysctl docs 2020-02-25 03:35:16 -07:00
check_extable.sh
checkincludes.pl
checkkconfigsymbols.py kconfig: remove '---help---' support 2020-08-14 13:30:03 +09:00
checkpatch.pl checkpatch: add new warnings to author signoff checks. 2020-10-16 11:11:21 -07:00
checkstack.pl scripts/checkstack.pl: fix arm sp regex 2020-05-26 00:03:16 +09:00
checksyscalls.sh checksyscalls: fix up mq_timedreceive and stat exceptions 2019-02-19 21:27:53 +01:00
checkversion.pl
clang-version.sh kbuild: update comment block of scripts/clang-version.sh 2019-03-04 22:34:54 +09:00
cleanfile
cleanpatch
coccicheck scripts: coccicheck: Change default condition for parallelism 2020-10-12 10:37:56 +02:00
config scripts/config: allow colons in option strings for sed 2020-04-23 01:10:16 +09:00
const_structs.checkpatch const_structs.checkpatch: add pinctrl_ops and pinmux_ops 2020-10-16 11:11:21 -07:00
decode_stacktrace.sh scripts/decode_stacktrace.sh: guess path to vmlinux by release name 2020-08-07 11:33:21 -07:00
decodecode scripts/decodecode: add the capability to supply the program counter 2020-10-13 18:38:26 -07:00
depmod.sh kbuild: modules_install: warn when missing System.map file 2018-09-09 09:14:07 +09:00
dev-needs.sh scripts/dev-needs: Add script to list device dependencies 2020-09-04 18:19:37 +02:00
diffconfig
documentation-file-ref-check scripts: documentation-file-ref-check: Add line break before exit 2020-04-15 15:13:13 -06:00
export_report.pl modpost: move the namespace field in Module.symvers last 2020-03-17 08:59:03 +09:00
extract-cert.c extract-cert: add static to local data 2020-08-18 20:16:46 +09:00
extract-ikconfig
extract-module-sig.pl
extract-sys-certs.pl
extract-vmlinux treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 378 2019-06-05 17:37:10 +02:00
extract_xc3028.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 339 2019-06-05 17:37:07 +02:00
faddr2line scripts/faddr2line: fix location of start_kernel in comment 2018-11-18 10:15:09 -08:00
file-size.sh
find-unused-docs.sh scripts/find-unused-docs: Fix massive false positives 2020-01-27 14:25:06 -07:00
gcc-goto.sh jump_label: move 'asm goto' support test to Kconfig 2019-01-06 09:46:51 +09:00
gcc-ld
gcc-plugin.sh gcc-plugins: drop support for GCC <= 4.7 2020-04-09 00:13:45 +09:00
gcc-version.sh kbuild: clean up scripts/gcc-version.sh 2019-03-04 22:35:04 +09:00
gcc-x86_32-has-stack-protector.sh
gcc-x86_64-has-stack-protector.sh
gen_autoksyms.sh kbuild: generate autoksyms.h early 2020-03-03 20:49:21 +09:00
gen_ksymdeps.sh kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS 2018-12-01 23:13:14 +09:00
get_abi.pl doc: ABI scripts: add a SPDX header file 2019-06-21 16:58:37 +02:00
get_dvb_firmware treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61 2019-05-24 17:36:45 +02:00
get_maintainer.pl get_maintainer: exclude MAINTAINERS file(s) from --git-fallback 2020-10-16 11:11:19 -07:00
gfp-translate treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
headerdep.pl
headers_check.pl
headers_install.sh Merge branch 'work.fdpic' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2020-08-07 13:29:39 -07:00
insert-sys-cert.c
jobserver-exec docs, parallelism: Rearrange how jobserver reservations are made 2019-11-22 10:35:18 -07:00
kallsyms.c scripts/kallsyms: skip ppc compiler stub *.long_branch.* / *.plt_branch.* 2020-09-25 00:41:54 +09:00
kernel-doc scripts: kernel-doc: try to use c:function if possible 2020-10-15 07:49:37 +02:00
ld-version.sh
leaking_addresses.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
link-vmlinux.sh Kbuild updates for v5.10 2020-10-22 13:13:57 -07:00
makelst
markup_oops.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 373 2019-06-05 17:37:10 +02:00
mkcompile_h kbuild: Use uname for LINUX_COMPILE_HOST detection 2020-10-21 00:46:04 +09:00
mkmakefile kbuild: get rid of $(realpath ...) from scripts/mkmakefile 2019-08-29 23:54:29 +09:00
mksysmap mksysmap: Fix the mismatch of '.L' symbols in System.map 2020-06-06 23:39:20 +09:00
mkuboot.sh
module.lds.S kbuild: preprocess module linker script 2020-09-25 00:36:41 +09:00
modules-check.sh kbuild: make module name conflict fatal error 2020-05-26 00:03:16 +09:00
nsdeps scripts: add dummy report mode to add_namespace.cocci 2020-07-10 14:19:58 +02:00
objdiff treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 199 2019-05-30 11:29:23 -07:00
parse-maintainers.pl parse-maintainers: Do not sort section content by default 2020-03-26 15:08:27 -07:00
patch-kernel
profile2linkerlist.pl
prune-kernel
recordmcount.c recordmcount: Fix build failure on non arm64 2020-08-10 15:22:06 +01:00
recordmcount.h recordmcount: support >64k sections 2020-06-16 21:21:00 -04:00
recordmcount.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
setlocalversion scripts/setlocalversion: make git describe output more reliable 2020-09-25 02:28:12 +09:00
show_delta treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 438 2019-06-05 17:37:17 +02:00
sign-file.c
sorttable.c s390/kernel: expand exception table logic to allow new handling options 2020-07-20 10:55:50 +02:00
sorttable.h scripts/sorttable: Implement build-time ORC unwind table sorting 2019-12-13 10:47:58 +01:00
spdxcheck-test.sh scripts: add spdxcheck.py self test 2018-12-28 12:11:44 -08:00
spdxcheck.py scripts/spdxcheck.py: handle license identifiers in XML comments 2020-10-02 11:31:26 +02:00
spelling.txt Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2020-10-15 15:11:56 -07:00
sphinx-pre-install docs: Don't push Sphinx upgrades quite so readily 2020-06-26 09:31:53 -06:00
split-man.pl
stackdelta
stackusage
subarch.include selftests: add headers_install to lib.mk 2018-09-05 08:12:09 -06:00
tags.sh Merge branch 'locking/urgent' into locking/core, to pick up fixes 2020-10-09 08:55:17 +02:00
tools-support-relr.sh scripts/tools-support-relr.sh: un-quote variables 2019-11-13 10:52:05 +00:00
unifdef.c unifdef: use memcpy instead of strncpy 2018-11-30 14:45:01 -08:00
ver_linux ver_linux: Query ld cache for versions of libc/libcpp run-time 2020-02-10 13:35:15 -08:00
xen-hypercalls.sh
xz_wrap.sh kbuild: add variables for compression tools 2020-06-06 23:42:01 +09:00