SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
Kernel TLV
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
Kernel TLV
 

Was ist angesagt? (20)

Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
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
 
eBPF Basics
eBPF BasicseBPF Basics
eBPF Basics
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
Linux Kernel Live Patching
Linux Kernel Live PatchingLinux Kernel Live Patching
Linux Kernel Live Patching
 
DPDK
DPDKDPDK
DPDK
 
Physical Layer - Metal vs Fiber
Physical Layer - Metal vs FiberPhysical Layer - Metal vs Fiber
Physical Layer - Metal vs Fiber
 
C/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツール
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
UEFI時代のブートローダ
UEFI時代のブートローダUEFI時代のブートローダ
UEFI時代のブートローダ
 
Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
nftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewallnftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewall
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
 
EBPF and Linux Networking
EBPF and Linux NetworkingEBPF and Linux Networking
EBPF and Linux Networking
 
FD.io VPP事始め
FD.io VPP事始めFD.io VPP事始め
FD.io VPP事始め
 
Hokkaido.cap #osc11do Wiresharkを使いこなそう!
Hokkaido.cap #osc11do Wiresharkを使いこなそう!Hokkaido.cap #osc11do Wiresharkを使いこなそう!
Hokkaido.cap #osc11do Wiresharkを使いこなそう!
 

Ähnlich wie Kernel Recipes 2019 - BPF at Facebook

Multi-threaded Performance Pitfalls
Multi-threaded Performance PitfallsMulti-threaded Performance Pitfalls
Multi-threaded Performance Pitfalls
Ciaran McHale
 
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
Alison Chaiken
 

Ähnlich wie 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
 

Mehr von 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 data
Anne Nicolas
 

Mehr von 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 - 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 - 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
 
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
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 

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.