SlideShare a Scribd company logo
1 of 37
Download to read offline
BPF at Facebook
Alexei Starovoitov
3
1) kernel upgrades
2) BPF in the datacenter
3) BPF evolution
4) where you can help
Agenda
Kernel upgrades in FB
4
•- "Upstream first" philosophy.
•- Close to zero private patches.
•- As soon as practical kernel team:
• . takes the latest upstream kernel
• . stabilizes it
• . rolls it across the fleet
• . backports relevant features until the cycle repeats
•- It used to take months to upgrade. Now few weeks. Days when necessary.
•
move fast
Kernel version by count
5
•- As of September 2019.
•- It will be different tomorrow.
- One kernel version on most servers.
- Many 4.16.x flavors due to long tail.
- Challenging environment for user space.
- Even more challenging for BPF based tracing.
Do not break user space
6
•- Must not change kernel ABI.
•- Must not cause performance regressions.
•- Must not change user space behavior.
- Investigate all differences.
. Either unexpected improvement or regression.
. Team work is necessary to root cause.
"The first rule" of kernel programming... multiplied by FB scale.
Do you use BPF?
7
•- Run this command on your laptop:
•
• sudo bpftool prog show | grep name | wc -l
•
•- What number does it print?
- Don't have bpftool ? Run this:
ls -la /proc/*/fd | grep bpf-prog | wc -l
BPF at Facebook
8
•- ~40 BPF programs active on every server.
•- ~100 BPF programs loaded on demand for short period of time.
•- Mainly used by daemons that run on every server.
•- Many teams are writing and deploying them.
BPF program distribution by type
9
Kernel team is involved in lots of investigations.
10
BPF?
BPF?
BPF?
BPF?
BPF?
•It's not true, but I often feel this way :)
Example 1: packet capture daemon
11
- This daemon is using SCHED_CLS BPF program.
- The program is attached to TC ingress and runs on every packet.
- With 1 out of million probability it does bpf_perf_event_output(skb).
- On new kernel this daemon causes 1% cpu regression.
- Disabling the daemon makes the regression go away.
- Is it BPF?
Example 1: packet capture daemon (resolved)
12
- Turned out the daemon is loading KPROBE BPF program as well for unrelated logic.
- kprobe-d function doesn't exist in new kernel.
- Daemon decides that BPF is unusable and falls back to NFLOG-based packet
capture.
- nflog loads iptable modules and causes 1% cpu regression.
Takeaway for developers
13
- kprobe is not a stable ABI.
- Everytime kernel developers change the code some kernel developers pay the price.
Example 2: performance profiling daemon
14
- The daemon is using BPF tracepoints, kprobes in the scheduler and task execution.
- It collects kernel and user stack traces, walks python user stacks inside BPF
program and aggregates across the fleet.
- This daemon is #1 tool for performance analysis.
- On new kernel it causes 2% cpu regression.
- Higher softirq times. Slower user apps.
- Disabling the daemon makes the regression go away.
- Is it BPF?
Example 2: performance profiling daemon (resolved)
15
- Turned out that simply installing kprobe makes 5.2 kernel remap kernel .text from
2M huge pages into 4k.
- That caused more I-TLB misses.
- Making BPF execution in the kernel slower and user space as well.
Takeaway
16
- kprobe is essential part of kernel functionality.
Example 3: security monitoring daemon
17
- The daemon is using 3 kprobes and 1 kretprobe.
- Its BPF program code just over 200 lines of C.
- It runs with low priority.
- It wakes up every few seconds, consumes 0.01% of one cpu and 0.01% of memory.
- Yet it causes large P99 latency regression for database server that runs on all other
cpus and consumes many Gbytes of memory.
- Throughput of the database is not affected.
- Disabling the daemon makes the regression go away.
- Is it BPF?
Investigation
18
Facts:
- Occasionally memcpy() in a database gets stuck for 1/4 of a second.
- The daemon is rarely reading /proc/pid/environ.
Guesses:
- Is database waiting on kernel to handle page fault ?
- While kernel is blocked on mmap_sem ?
- but "top" and others read /proc way more often. Why that daemon is special?
- Dive into kernel code
fs/proc/base.c
environ_read()
access_remote_vm()
down_read(&mm->mmap_sem)
funclatency.py - Time functions and print latency as a
histogram
19
# funclatency.py -d100 -m __access_remote_vm
Tracing 1 functions for "__access_remote_vm"... Hit Ctrl-C to end.
msecs : count distribution
0 -> 1 : 21938 |****************************************|
2 -> 3 : 0 | |
4 -> 7 : 0 | |
8 -> 15 : 0 | |
16 -> 31 : 0 | |
32 -> 63 : 0 | |
64 -> 127 : 0 | |
128 -> 255 : 7 | |
256 -> 511 : 3 | |
Detaching...
This histogram shows that over the last 100 seconds there
were 3 events where reading /proc took more than 256 ms.
funcslower.py - Dump kernel and user stack when given
kernel function was slower than threshold
20
# funcslower.py -m 200 -KU __access_remote_vm
Tracing function calls slower than 200 ms... Ctrl+C to quit.
COMM PID LAT(ms) RVAL FUNC
security_daemon 1720415 399.02 605 __access_remote_vm
kretprobe_trampoline
read
facebook::...::readBytes(folly::File const&)
...
This was the kernel+user stack trace when our security
daemon was stuck in sys_read() for 399 ms.
Yes. It's that daemon causing database latency spikes.
Collect more stack traces with offwaketime.py ...
21
finish_task_switch
__schedule
preempt_schedule_common
_cond_resched
__get_user_pages
get_user_pages_remote
__access_remote_vm
proc_pid_cmdline_read
__vfs_read
vfs_read
sys_read
do_syscall_64
read
facebook::...::readBytes(folly::File const&)
The task reading from /proc/pid/cmdline can go to sleep without releasing
mmap_sem of mm of that pid.
The page fault in that pid will be blocked until this task finishes reading /proc.
Root cause
22
- The daemon is using 3 kprobes and 1 kretprobe.
- Its BPF program code just over 200 lines of C.
- It runs with low priority.
- It wakes up every few seconds, consumes 0.01% of one cpu and 0.01% of memory.
Low CPU quota for the daemon coupled with aggressive sysctl kernel.sched_*
tweaks were responsible.
Takeaway
23
- BPF tracing tools are the best to tackle BPF regression.
BPF BPF
Another kind of BPF investigations
24
- Many kernels run in the datacenter.
- Daemons (and their BPF programs) need to work on all of them.
- BPF program works on developer server, but fails in production.
On developer server
25
On production server
26
- Embedded LLVM is safer than standalone LLVM.
- LLVM takes 70 Mb on disk. 20 Mb of memory at steady state. More at peak.
- Dependency on system kernel headers. Subsystem internal headers are missing.
- Compilation errors captured at runtime.
- Compilation on production server disturbs the main workload.
- And the other way around. llvm may take minutes to compile 100 lines of C.
BPF CO-RE (Compile Once Run Everywhere)
27
- Compile BPF program into "Run Everywhere" .o file (BPF assembly + extra).
- Test it on developer server against many "kernels".
- Adjust .o file on production server by libbpf.
- No compilation on production server.
BTF (BPF Type Format)
28
- BTF describes types, relocations, source code.
- LLVM compiles BPF program C code into BPF assembler and BTF.
- gcc+pahole compiles kernel C code into vmlinux binary and BTF.
- libbpf compares prog's BTF with vmlinux's BTF and adjusts BPF assembly before
loading into the kernel.
- Developers can compile and test for kprobe and kernel data structure
compatibility on a single server at build time instead of on N servers at run-time.
trace_kfree_skb today
29
PARM2 typo will "work" too
six bpf_probe_read() calls
Any type cast is allowed
clang -I/path_to_kernel_headers/ -I/path_to_user/
trace_kfree_skb today
30
trace_kfree_skb with CO-RE
31
Works with any raw tracepoint
Same kernel helper as in networking programs
If skb and location are accidentally swapped
the verifier will catch it
Define kernel structs by hand instead of
including vmlinux.h
BPF verifier giant leaps in 2019
32
- Bounded loops
- bpf_spin_lock
- Dead code elimination
- Scalar precision tracking
BPF
BPF verifier is smarter than llvm
33
- The verifier removes dead code after it was optimized by llvm -O2.
- Developers cannot cheat by type casting integer to pointer or removing 'const'.
- LLVM goal -> optimize the code.
- The verifier goal -> analyze the code.
- Different takes on data flow analysis.
- The verifier data flow analysis must be precise.
BPF verifier 2.0
34
- The verifier cannot tell what "r2 = *(u64*)(r1 + 8)" assembly instruction is doing.
- Unless r1 is a builtin type and +8 is checked by is_valid_access().
- The verifier cannot trust user space hints to verify BPF program assembly code.
- In-kernel BTF is trusted.
- With BTF the verifier data flow analysis enters into new realm of possibilities.
35
Every program type implements its own
is_valid_access() and convert_ctx_access().
#1 cause for code bloat.
Bug prone code.
None of it is needed with BTF.
Will be able to remove 1000s of lines.*
* when BTF kconfig is on.
How you can help
36
We need you
to hack.
to talk.
to invent.
BPF development is 100% use case driven.
Your requests, complains, sharing of success stories are shaping the future kernel.
JUST DO BPF.
37

More Related Content

What's hot

XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareC4Media
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPThomas Graf
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumScyllaDB
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingViller Hsiao
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and moreBrendan Gregg
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
Linux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFLinux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFBrendan Gregg
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)shimosawa
 
[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOS[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOSAkihiro Suda
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDPDaniel T. Lee
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KernelThomas Graf
 
OpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image LifecycleOpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image LifecycleMihai Criveti
 
Administration des services réseaux
Administration des services réseauxAdministration des services réseaux
Administration des services réseauxFethi Kiwa
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VRISC-V International
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedAnne Nicolas
 
[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅NAVER D2
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmicsDenys Haryachyy
 

What's hot (20)

Intro to docker
Intro to dockerIntro to docker
Intro to docker
 
XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @Cloudflare
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracing
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Linux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFLinux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPF
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOS[KubeCon EU 2022] Running containerd and k3s on macOS
[KubeCon EU 2022] Running containerd and k3s on macOS
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux Kernel
 
OpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image LifecycleOpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image Lifecycle
 
Administration des services réseaux
Administration des services réseauxAdministration des services réseaux
Administration des services réseaux
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 

Similar to Kernel Recipes 2019 - BPF at Facebook

Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug huntingAndrea Righi
 
story_of_bpf-1.pdf
story_of_bpf-1.pdfstory_of_bpf-1.pdf
story_of_bpf-1.pdfhegikip775
 
Developing MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack RoutersDeveloping MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack RoutersOnur Alanbel
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and InsightsGlobalLogic Ukraine
 
Testing Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with SherlockTesting Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with SherlockScyllaDB
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF SuperpowersBrendan Gregg
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machineAlexei Starovoitov
 
Dataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsDataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsStefano Salsano
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPFAlex Maestretti
 
OpenPOWER Application Optimization
OpenPOWER Application Optimization OpenPOWER Application Optimization
OpenPOWER Application Optimization Ganesan Narayanasamy
 
Multi-threaded Performance Pitfalls
Multi-threaded Performance PitfallsMulti-threaded Performance Pitfalls
Multi-threaded Performance PitfallsCiaran McHale
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitAndrea Righi
 
Andrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitAndrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitlinuxlab_conf
 
”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016Kuniyasu Suzaki
 
Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack eurobsdcon
 
Best Practices and Performance Studies for High-Performance Computing Clusters
Best Practices and Performance Studies for High-Performance Computing ClustersBest Practices and Performance Studies for High-Performance Computing Clusters
Best Practices and Performance Studies for High-Performance Computing ClustersIntel® Software
 
AIX Advanced Administration Knowledge Share
AIX Advanced Administration Knowledge ShareAIX Advanced Administration Knowledge Share
AIX Advanced Administration Knowledge Share.Gastón. .Bx.
 
Not breaking userspace: the evolving Linux ABI
Not breaking userspace: the evolving Linux ABINot breaking userspace: the evolving Linux ABI
Not breaking userspace: the evolving Linux ABIAlison Chaiken
 
DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthFelipe Prado
 

Similar to Kernel Recipes 2019 - BPF at Facebook (20)

Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug hunting
 
story_of_bpf-1.pdf
story_of_bpf-1.pdfstory_of_bpf-1.pdf
story_of_bpf-1.pdf
 
Developing MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack RoutersDeveloping MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack Routers
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and Insights
 
Testing Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with SherlockTesting Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with Sherlock
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF Superpowers
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 
Dataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsDataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and tools
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPF
 
OpenPOWER Application Optimization
OpenPOWER Application Optimization OpenPOWER Application Optimization
OpenPOWER Application Optimization
 
Multi-threaded Performance Pitfalls
Multi-threaded Performance PitfallsMulti-threaded Performance Pitfalls
Multi-threaded Performance Pitfalls
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profit
 
Andrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitAndrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profit
 
”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016
 
Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack
 
Best Practices and Performance Studies for High-Performance Computing Clusters
Best Practices and Performance Studies for High-Performance Computing ClustersBest Practices and Performance Studies for High-Performance Computing Clusters
Best Practices and Performance Studies for High-Performance Computing Clusters
 
AIX Advanced Administration Knowledge Share
AIX Advanced Administration Knowledge ShareAIX Advanced Administration Knowledge Share
AIX Advanced Administration Knowledge Share
 
Not breaking userspace: the evolving Linux ABI
Not breaking userspace: the evolving Linux ABINot breaking userspace: the evolving Linux ABI
Not breaking userspace: the evolving Linux ABI
 
DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depth
 

More from Anne Nicolas

Kernel Recipes 2019 - Driving the industry toward upstream first
Kernel Recipes 2019 - Driving the industry toward upstream firstKernel Recipes 2019 - Driving the industry toward upstream first
Kernel Recipes 2019 - Driving the industry toward upstream firstAnne Nicolas
 
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIKernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIAnne Nicolas
 
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernelKernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernelAnne Nicolas
 
Kernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyKernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyAnne Nicolas
 
Kernel Recipes 2019 - Kernel documentation: past, present, and future
Kernel Recipes 2019 - Kernel documentation: past, present, and futureKernel Recipes 2019 - Kernel documentation: past, present, and future
Kernel Recipes 2019 - Kernel documentation: past, present, and futureAnne Nicolas
 
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...Anne Nicolas
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataAnne Nicolas
 
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Anne Nicolas
 
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxEmbedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxAnne Nicolas
 
Embedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialEmbedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialAnne Nicolas
 
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconEmbedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconAnne Nicolas
 
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureEmbedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureAnne Nicolas
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayAnne Nicolas
 
Embedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerEmbedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerAnne Nicolas
 
Embedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationEmbedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationAnne Nicolas
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingAnne Nicolas
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaAnne Nicolas
 
Kernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPKernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPAnne Nicolas
 
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Anne Nicolas
 
Kernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyKernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyAnne Nicolas
 

More from Anne Nicolas (20)

Kernel Recipes 2019 - Driving the industry toward upstream first
Kernel Recipes 2019 - Driving the industry toward upstream firstKernel Recipes 2019 - Driving the industry toward upstream first
Kernel Recipes 2019 - Driving the industry toward upstream first
 
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIKernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
 
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernelKernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
 
Kernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyKernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are money
 
Kernel Recipes 2019 - Kernel documentation: past, present, and future
Kernel Recipes 2019 - Kernel documentation: past, present, and futureKernel Recipes 2019 - Kernel documentation: past, present, and future
Kernel Recipes 2019 - Kernel documentation: past, present, and future
 
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
 
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxEmbedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
 
Embedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialEmbedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less special
 
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconEmbedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
 
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureEmbedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops way
 
Embedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerEmbedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmaker
 
Embedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationEmbedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integration
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debugging
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
 
Kernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPKernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDP
 
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
 
Kernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyKernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easy
 

Recently uploaded

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 

Recently uploaded (20)

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 

Kernel Recipes 2019 - BPF at Facebook

  • 1.
  • 3. 3 1) kernel upgrades 2) BPF in the datacenter 3) BPF evolution 4) where you can help Agenda
  • 4. Kernel upgrades in FB 4 •- "Upstream first" philosophy. •- Close to zero private patches. •- As soon as practical kernel team: • . takes the latest upstream kernel • . stabilizes it • . rolls it across the fleet • . backports relevant features until the cycle repeats •- It used to take months to upgrade. Now few weeks. Days when necessary. • move fast
  • 5. Kernel version by count 5 •- As of September 2019. •- It will be different tomorrow. - One kernel version on most servers. - Many 4.16.x flavors due to long tail. - Challenging environment for user space. - Even more challenging for BPF based tracing.
  • 6. Do not break user space 6 •- Must not change kernel ABI. •- Must not cause performance regressions. •- Must not change user space behavior. - Investigate all differences. . Either unexpected improvement or regression. . Team work is necessary to root cause. "The first rule" of kernel programming... multiplied by FB scale.
  • 7. Do you use BPF? 7 •- Run this command on your laptop: • • sudo bpftool prog show | grep name | wc -l • •- What number does it print? - Don't have bpftool ? Run this: ls -la /proc/*/fd | grep bpf-prog | wc -l
  • 8. BPF at Facebook 8 •- ~40 BPF programs active on every server. •- ~100 BPF programs loaded on demand for short period of time. •- Mainly used by daemons that run on every server. •- Many teams are writing and deploying them.
  • 10. Kernel team is involved in lots of investigations. 10 BPF? BPF? BPF? BPF? BPF? •It's not true, but I often feel this way :)
  • 11. Example 1: packet capture daemon 11 - This daemon is using SCHED_CLS BPF program. - The program is attached to TC ingress and runs on every packet. - With 1 out of million probability it does bpf_perf_event_output(skb). - On new kernel this daemon causes 1% cpu regression. - Disabling the daemon makes the regression go away. - Is it BPF?
  • 12. Example 1: packet capture daemon (resolved) 12 - Turned out the daemon is loading KPROBE BPF program as well for unrelated logic. - kprobe-d function doesn't exist in new kernel. - Daemon decides that BPF is unusable and falls back to NFLOG-based packet capture. - nflog loads iptable modules and causes 1% cpu regression.
  • 13. Takeaway for developers 13 - kprobe is not a stable ABI. - Everytime kernel developers change the code some kernel developers pay the price.
  • 14. Example 2: performance profiling daemon 14 - The daemon is using BPF tracepoints, kprobes in the scheduler and task execution. - It collects kernel and user stack traces, walks python user stacks inside BPF program and aggregates across the fleet. - This daemon is #1 tool for performance analysis. - On new kernel it causes 2% cpu regression. - Higher softirq times. Slower user apps. - Disabling the daemon makes the regression go away. - Is it BPF?
  • 15. Example 2: performance profiling daemon (resolved) 15 - Turned out that simply installing kprobe makes 5.2 kernel remap kernel .text from 2M huge pages into 4k. - That caused more I-TLB misses. - Making BPF execution in the kernel slower and user space as well.
  • 16. Takeaway 16 - kprobe is essential part of kernel functionality.
  • 17. Example 3: security monitoring daemon 17 - The daemon is using 3 kprobes and 1 kretprobe. - Its BPF program code just over 200 lines of C. - It runs with low priority. - It wakes up every few seconds, consumes 0.01% of one cpu and 0.01% of memory. - Yet it causes large P99 latency regression for database server that runs on all other cpus and consumes many Gbytes of memory. - Throughput of the database is not affected. - Disabling the daemon makes the regression go away. - Is it BPF?
  • 18. Investigation 18 Facts: - Occasionally memcpy() in a database gets stuck for 1/4 of a second. - The daemon is rarely reading /proc/pid/environ. Guesses: - Is database waiting on kernel to handle page fault ? - While kernel is blocked on mmap_sem ? - but "top" and others read /proc way more often. Why that daemon is special? - Dive into kernel code fs/proc/base.c environ_read() access_remote_vm() down_read(&mm->mmap_sem)
  • 19. funclatency.py - Time functions and print latency as a histogram 19 # funclatency.py -d100 -m __access_remote_vm Tracing 1 functions for "__access_remote_vm"... Hit Ctrl-C to end. msecs : count distribution 0 -> 1 : 21938 |****************************************| 2 -> 3 : 0 | | 4 -> 7 : 0 | | 8 -> 15 : 0 | | 16 -> 31 : 0 | | 32 -> 63 : 0 | | 64 -> 127 : 0 | | 128 -> 255 : 7 | | 256 -> 511 : 3 | | Detaching... This histogram shows that over the last 100 seconds there were 3 events where reading /proc took more than 256 ms.
  • 20. funcslower.py - Dump kernel and user stack when given kernel function was slower than threshold 20 # funcslower.py -m 200 -KU __access_remote_vm Tracing function calls slower than 200 ms... Ctrl+C to quit. COMM PID LAT(ms) RVAL FUNC security_daemon 1720415 399.02 605 __access_remote_vm kretprobe_trampoline read facebook::...::readBytes(folly::File const&) ... This was the kernel+user stack trace when our security daemon was stuck in sys_read() for 399 ms. Yes. It's that daemon causing database latency spikes.
  • 21. Collect more stack traces with offwaketime.py ... 21 finish_task_switch __schedule preempt_schedule_common _cond_resched __get_user_pages get_user_pages_remote __access_remote_vm proc_pid_cmdline_read __vfs_read vfs_read sys_read do_syscall_64 read facebook::...::readBytes(folly::File const&) The task reading from /proc/pid/cmdline can go to sleep without releasing mmap_sem of mm of that pid. The page fault in that pid will be blocked until this task finishes reading /proc.
  • 22. Root cause 22 - The daemon is using 3 kprobes and 1 kretprobe. - Its BPF program code just over 200 lines of C. - It runs with low priority. - It wakes up every few seconds, consumes 0.01% of one cpu and 0.01% of memory. Low CPU quota for the daemon coupled with aggressive sysctl kernel.sched_* tweaks were responsible.
  • 23. Takeaway 23 - BPF tracing tools are the best to tackle BPF regression. BPF BPF
  • 24. Another kind of BPF investigations 24 - Many kernels run in the datacenter. - Daemons (and their BPF programs) need to work on all of them. - BPF program works on developer server, but fails in production.
  • 26. On production server 26 - Embedded LLVM is safer than standalone LLVM. - LLVM takes 70 Mb on disk. 20 Mb of memory at steady state. More at peak. - Dependency on system kernel headers. Subsystem internal headers are missing. - Compilation errors captured at runtime. - Compilation on production server disturbs the main workload. - And the other way around. llvm may take minutes to compile 100 lines of C.
  • 27. BPF CO-RE (Compile Once Run Everywhere) 27 - Compile BPF program into "Run Everywhere" .o file (BPF assembly + extra). - Test it on developer server against many "kernels". - Adjust .o file on production server by libbpf. - No compilation on production server.
  • 28. BTF (BPF Type Format) 28 - BTF describes types, relocations, source code. - LLVM compiles BPF program C code into BPF assembler and BTF. - gcc+pahole compiles kernel C code into vmlinux binary and BTF. - libbpf compares prog's BTF with vmlinux's BTF and adjusts BPF assembly before loading into the kernel. - Developers can compile and test for kprobe and kernel data structure compatibility on a single server at build time instead of on N servers at run-time.
  • 29. trace_kfree_skb today 29 PARM2 typo will "work" too six bpf_probe_read() calls Any type cast is allowed clang -I/path_to_kernel_headers/ -I/path_to_user/
  • 31. 31 Works with any raw tracepoint Same kernel helper as in networking programs If skb and location are accidentally swapped the verifier will catch it Define kernel structs by hand instead of including vmlinux.h
  • 32. BPF verifier giant leaps in 2019 32 - Bounded loops - bpf_spin_lock - Dead code elimination - Scalar precision tracking BPF
  • 33. BPF verifier is smarter than llvm 33 - The verifier removes dead code after it was optimized by llvm -O2. - Developers cannot cheat by type casting integer to pointer or removing 'const'. - LLVM goal -> optimize the code. - The verifier goal -> analyze the code. - Different takes on data flow analysis. - The verifier data flow analysis must be precise.
  • 34. BPF verifier 2.0 34 - The verifier cannot tell what "r2 = *(u64*)(r1 + 8)" assembly instruction is doing. - Unless r1 is a builtin type and +8 is checked by is_valid_access(). - The verifier cannot trust user space hints to verify BPF program assembly code. - In-kernel BTF is trusted. - With BTF the verifier data flow analysis enters into new realm of possibilities.
  • 35. 35 Every program type implements its own is_valid_access() and convert_ctx_access(). #1 cause for code bloat. Bug prone code. None of it is needed with BTF. Will be able to remove 1000s of lines.* * when BTF kconfig is on.
  • 36. How you can help 36 We need you to hack. to talk. to invent. BPF development is 100% use case driven. Your requests, complains, sharing of success stories are shaping the future kernel.