bpf: remove the cgroup -> bpf header dependecy
Subsystems (11)
Jakub Kicinski
maintainerv5 cover bpf: remove the cgroup -> bpf header dependecy
Changes to bpf.h tend to clog up our build systems. The netdev/bpf build bot does incremental builds to save time (reusing the build directory to only rebuild changed objects).
This is the rough breakdown of how many objects needs to be rebuilt based on file touched:
kernel.h 40633 bpf.h 17881 bpf-cgroup.h 17875 skbuff.h 10696 bpf-netns.h 7604 netdevice.h 7452 filter.h 5003 sock.h 4959 tcp.h 4048
As the stats show touching bpf.h is _very_ expensive.
Bulk of the objects get rebuilt because MM includes cgroup headers. Luckily bpf-cgroup.h does not fundamentally depend on bpf.h so we can break that dependency and reduce the number of objects.
With the patches applied touching bpf.h causes 5019 objects to be rebuilt (17881 / 5019 = 3.56x). That's pretty much down to filter.h plus noise.
v2:
Try to make the new headers wider in scope. Collapse bpf-link and bpf-cgroup-types into one header, which may serve as "BPF kernel API" header in the future if needed. Rename bpf-cgroup-storage.h to bpf-inlines.h.
Add a fix for the s390 build issue.
v3: https://lore.kernel.org/all/[email protected]/
Merge bpf-includes.h into bpf.h.
v4: https://lore.kernel.org/all/[email protected]/
Change course - break off cgroup instead of breaking off bpf.
v5:
Add forward declaration of struct bpf_prog to perf_event.h when !CONFIG_BPF_SYSCALL (kbuild bot).
Jakub Kicinski (3):
add includes masked by cgroup -> bpf dependency
add missing bpf-cgroup.h includes
bpf: remove the cgroup -> bpf header dependecy
arch/s390/mm/hugetlbpage.c | 1 + include/linux/bpf-cgroup-defs.h | 70 +++++++++++++++++++++++++++++++++ include/linux/bpf-cgroup.h | 57 +-------------------------- include/linux/cgroup-defs.h | 2 +- include/linux/perf_event.h | 1 + kernel/bpf/helpers.c | 1 + kernel/bpf/syscall.c | 1 + kernel/bpf/verifier.c | 1 + kernel/cgroup/cgroup.c | 1 + kernel/trace/trace_kprobe.c | 1 + kernel/trace/trace_uprobe.c | 1 + net/ipv4/udp.c | 1 + net/ipv6/udp.c | 1 + net/socket.c | 1 + security/device_cgroup.c | 1 + 15 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 include/linux/bpf-cgroup-defs.h
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v5 1/3 add includes masked by cgroup -> bpf dependency
cgroup pulls in BPF which pulls in a lot of includes. We're about to break that chain so fix those who were depending on it.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- arch/s390/mm/hugetlbpage.c | 1 + include/linux/perf_event.h | 1 + 2 files changed, 2 insertions(+)
arch/s390/mm/hugetlbpage.c +1 -0
@@ -9,6 +9,7 @@#define KMSG_COMPONENT "hugetlb"#define pr_fmt (fmt) KMSG_COMPONENT ": " fmt +#include <asm/pgalloc.h> #include <linux/mm.h> #include <linux/hugetlb.h> #include <linux/mman.h>
include/linux/perf_event.h +1 -0
@@ -611,6 +611,7 @@ struct swevent_hlist {#define PERF_ATTACH_SCHED_CB 0x20#define PERF_ATTACH_CHILD 0x40 +struct bpf_prog ;struct perf_cgroup ;struct perf_buffer ;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v5 2/3 add missing bpf-cgroup.h includes
In reply to Jakub KicinskiWe're about to break the cgroup-defs.h -> bpf-cgroup.h dependency, make sure those who actually need more than the definition of struct cgroup_bpf include bpf-cgroup.h explicitly.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- kernel/bpf/helpers.c | 1 + kernel/bpf/syscall.c | 1 + kernel/bpf/verifier.c | 1 + kernel/cgroup/cgroup.c | 1 + kernel/trace/trace_kprobe.c | 1 + kernel/trace/trace_uprobe.c | 1 + net/ipv4/udp.c | 1 + net/ipv6/udp.c | 1 + net/socket.c | 1 + security/device_cgroup.c | 1 + 10 files changed, 10 insertions(+)
kernel/bpf/helpers.c +1 -0
@@ -2,6 +2,7 @@/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com */ #include <linux/bpf.h> +#include <linux/bpf-cgroup.h> #include <linux/rcupdate.h> #include <linux/random.h> #include <linux/smp.h>
kernel/bpf/syscall.c +1 -0
@@ -2,6 +2,7 @@/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com */ #include <linux/bpf.h> +#include <linux/bpf-cgroup.h> #include <linux/bpf_trace.h> #include <linux/bpf_lirc.h> #include <linux/bpf_verifier.h>
kernel/bpf/verifier.c +1 -0
@@ -4,6 +4,7 @@* Copyright (c) 2018 Covalent IO, Inc. http://covalent.io */ #include <uapi/linux/btf.h> +#include <linux/bpf-cgroup.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/slab.h>
kernel/cgroup/cgroup.c +1 -0
@@ -30,6 +30,7 @@#include "cgroup-internal.h" +#include <linux/bpf-cgroup.h> #include <linux/cred.h> #include <linux/errno.h> #include <linux/init_task.h>
kernel/trace/trace_kprobe.c +1 -0
@@ -7,6 +7,7 @@*/ #define pr_fmt (fmt) "trace_kprobe: " fmt +#include <linux/bpf-cgroup.h> #include <linux/security.h> #include <linux/module.h> #include <linux/uaccess.h>
kernel/trace/trace_uprobe.c +1 -0
@@ -7,6 +7,7 @@*/ #define pr_fmt (fmt) "trace_uprobe: " fmt +#include <linux/bpf-cgroup.h> #include <linux/security.h> #include <linux/ctype.h> #include <linux/module.h>
net/ipv4/udp.c +1 -0
@@ -74,6 +74,7 @@#define pr_fmt (fmt) "UDP: " fmt +#include <linux/bpf-cgroup.h> #include <linux/uaccess.h> #include <asm/ioctls.h> #include <linux/memblock.h>
net/ipv6/udp.c +1 -0
@@ -17,6 +17,7 @@* YOSHIFUJI Hideaki @USAGI: convert /proc/net/udp6 to seq_file. */ +#include <linux/bpf-cgroup.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/socket.h>
net/socket.c +1 -0
@@ -52,6 +52,7 @@* Based upon Swansea University Computer Society NET3.039 */ +#include <linux/bpf-cgroup.h> #include <linux/ethtool.h> #include <linux/mm.h> #include <linux/socket.h>
security/device_cgroup.c +1 -0
@@ -5,6 +5,7 @@* Copyright 2007 IBM Corp */ +#include <linux/bpf-cgroup.h> #include <linux/device_cgroup.h> #include <linux/cgroup.h> #include <linux/ctype.h>
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v5 3/3 bpf: remove the cgroup -> bpf header dependecy
In reply to Jakub KicinskiRemove the dependency from cgroup-defs.h to bpf-cgroup.h and bpf.h. This reduces the incremental build size of x86 allmodconfig after bpf.h was touched from ~17k objects rebuilt to ~5k objects. bpf.h is 2.2kLoC and is modified relatively often.
We need a new header with just the definition of struct cgroup_bpf and enum cgroup_bpf_attach_type, this is akin to cgroup-defs.h.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- include/linux/bpf-cgroup-defs.h | 70 +++++++++++++++++++++++++++++++++ include/linux/bpf-cgroup.h | 57 +-------------------------- include/linux/cgroup-defs.h | 2 +- 3 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 include/linux/bpf-cgroup-defs.h
include/linux/bpf-cgroup-defs.h new file +70 -0
@@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BPF_CGROUP_DEFS_H +#define _BPF_CGROUP_DEFS_H + +#ifdef CONFIG_CGROUP_BPF + +#include <linux/list.h> +#include <linux/percpu-refcount.h> +#include <linux/workqueue.h> + +struct bpf_prog_array ; + +enum cgroup_bpf_attach_type { +CGROUP_BPF_ATTACH_TYPE_INVALID =-1 , +CGROUP_INET_INGRESS =0 , +CGROUP_INET_EGRESS , +CGROUP_INET_SOCK_CREATE , +CGROUP_SOCK_OPS , +CGROUP_DEVICE , +CGROUP_INET4_BIND , +CGROUP_INET6_BIND , +CGROUP_INET4_CONNECT , +CGROUP_INET6_CONNECT , +CGROUP_INET4_POST_BIND , +CGROUP_INET6_POST_BIND , +CGROUP_UDP4_SENDMSG , +CGROUP_UDP6_SENDMSG , +CGROUP_SYSCTL , +CGROUP_UDP4_RECVMSG , +CGROUP_UDP6_RECVMSG , +CGROUP_GETSOCKOPT , +CGROUP_SETSOCKOPT , +CGROUP_INET4_GETPEERNAME , +CGROUP_INET6_GETPEERNAME , +CGROUP_INET4_GETSOCKNAME , +CGROUP_INET6_GETSOCKNAME , +CGROUP_INET_SOCK_RELEASE , +MAX_CGROUP_BPF_ATTACH_TYPE +}; + +struct cgroup_bpf { +/* array of effective progs in this cgroup */ +struct bpf_prog_array __rcu *effective[MAX_CGROUP_BPF_ATTACH_TYPE ]; + +/* attached progs to this cgroup and attach flags +* when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will +* have either zero or one element +* when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS +*/ +struct list_head progs[MAX_CGROUP_BPF_ATTACH_TYPE ]; +u32 flags[MAX_CGROUP_BPF_ATTACH_TYPE ]; + +/* list of cgroup shared storages */ +struct list_head storages; + +/* temp storage for effective prog array used by prog_attach/detach */ +struct bpf_prog_array *inactive; + +/* reference counter used to detach bpf programs after cgroup removal */ +struct percpu_ref refcnt; + +/* cgroup_bpf is released using a work queue */ +struct work_struct release_work; +}; + +#else /* CONFIG_CGROUP_BPF */ +struct cgroup_bpf {}; +#endif /* CONFIG_CGROUP_BPF */ + +#endif
include/linux/bpf-cgroup.h +1 -56
84 lines not on this page · raw message
include/linux/cgroup-defs.h +1 -1
@@ -19,7 +19,7 @@#include <linux/percpu-rwsem.h> #include <linux/u64_stats_sync.h> #include <linux/workqueue.h> -#include <linux/bpf-cgroup.h> +#include <linux/bpf-cgroup-defs.h> #include <linux/psi_types.h> #ifdef CONFIG_CGROUPS
Signature · 1 line
2.31.1
Alexei Starovoitov
AppliedQuoted 38 lines · Jakub Kicinski
Changes to
bpf.htend to clog up our build systems. The netdev/bpf build bot does incremental builds to save time (reusing the build directory to only rebuild changed objects).This is the rough breakdown of how many objects needs to be rebuilt based on file touched:
kernel.h 40633 bpf.h 17881 bpf-cgroup.h 17875 skbuff.h 10696 bpf-netns.h 7604 netdevice.h 7452 filter.h 5003 sock.h 4959 tcp.h 4048As the stats show touching
bpf.his _very_ expensive.Bulk of the objects get rebuilt because MM includes cgroup headers. Luckily
bpf-cgroup.hdoes not fundamentally depend onbpf.hso we can break that dependency and reduce the number of objects.With the patches applied touching
bpf.hcauses 5019 objects to be rebuilt (17881 / 5019 = 3.56x). That's pretty much down tofilter.hplus noise.v2:
Try to make the new headers wider in scope. Collapse bpf-link and bpf-cgroup-types into one header, which may serve as "BPF kernel API" header in the future if needed. Renamebpf-cgroup-storage.htobpf-inlines.h.Add a fix for the s390 build issue.
v3: https://lore.kernel.org/all/[email protected]/
Mergebpf-includes.hintobpf.h.
Quoted 6 lines
v4: https://lore.kernel.org/all/[email protected]/
Change course - break off cgroup instead of breaking off bpf.v5:
Add forward declaration of structbpf_progtoperf_event.hwhen !CONFIG_BPF_SYSCALL (kbuild bot).
Applied. Thanks
Jakub Kicinski
maintainerQuoted 19 lines · On Thu, 16 Dec 2021 15:05:00 -0800 Alexei Starovoitov wrote:
Quoted 8 lines · Jakub Kicinski
Changes to
bpf.htend to clog up our build systems. The netdev/bpf build bot does incremental builds to save time (reusing the build directory to only rebuild changed objects).This is the rough breakdown of how many objects needs to be rebuilt based on file touched:
Quoted 9 lines
kernel.h 40633 bpf.h 17881 bpf-cgroup.h 17875 skbuff.h 10696 bpf-netns.h 7604 netdevice.h 7452 filter.h 5003 sock.h 4959 tcp.h 4048
Quoted 1 line
Applied. Thanks
Thanks! I got another patch to get to 1k objects, by taking filter.h include out of sock.h but I'll give it a week for the dust to settle here.