freenode
Kernel & Low-Level

BPF series makes vmlinux BTF an on-demand module

Jay Wang’s patches let distributions keep CO-RE and related features without forcing roughly 5.4 MB of type data into every system’s RAM from boot.

A patch series from Jay Wang at Amazon proposes turning CONFIG_DEBUG_INFO_BTF into a tristate option so the vmlinux BTF can ship as a loadable module instead of living in the kernel image. On a typical distribution config that change reclaims about 5.4 MB of RAM on machines that never use the data; systems that do need it load the module automatically on first use and then behave as they do today with the built-in option.

BTF is no longer optional debug information. CO-RE, fentry/fexit, kfuncs, struct_ops, sched_ext and bpf-lsm all depend on it. Distributors therefore cannot simply set the option to n for the many small instances that never load a BPF program that needs kernel types; they ship one kernel for everyone. Embedding the BTF from boot wastes memory on those systems. Building it as module btf_vmlinux keeps the features available while charging the memory cost only when something actually asks for the types.

The series leaves the =y path untouched. With =m the BTF is generated exactly as before, packed into the module, and brought in by the kernel the first time a program or helper needs kernel types. Pure socket filters and other programs that never touch those types never trigger the load. Sysfs readers of /sys/kernel/btf/vmlinux likewise pull the module in on open or mmap, using build-time size metadata so the first bpftool dump or libbpf load sees a complete file rather than an empty placeholder.

Review on the BPF list and automated CI flagged several gaps: missing fetch sites for program-context types and the BTF printf helpers, module-BTF publication ordering, kbuild rules that could have relinked every module against vmlinux, and boot-time request_module failure modes. Wang’s later revisions address those points, ensure a failed parse is not cached when the data is modular, and note that btf_vmlinux.ko may need to sit in the initramfs if early boot code can request it before the root filesystem is mounted. For users who never touch BTF, the memory stays free; for everyone else the first use is intended to be invisible.