From First Principles to Production Deployments
Introduction: The eBPF Revolution
- The Observability Problem in Modern Infrastructure
- Before eBPF: What We Used to Do
- What eBPF Gives You
- Who Should Read This Book
- How This Book Is Organized
Chapter 1: History and Evolution of BPF
- The Original Berkeley Packet Filter
- Linux Socket Filters: The First Step
- The Birth of cBPF and eBPF
- Alexei Starovoitov and the eBPF Project
- Major Milestones: From 3.18 to 6.x
Chapter 2: Linux Kernel Architecture for eBPF
- Kernel Space vs User Space: The Boundary
- System Calls and Context Switching
- Kernel Hooks and Tracing Infrastructure
- Memory Management Basics for eBPF
- The BPF Virtual Machine Architecture
- How Programs Attach to the Kernel
Chapter 3: The eBPF Execution Model
- The eBPF Instruction Set Architecture
- Registers and Calling Conventions
- The Fixed-Size Stack
- Control Flow: Loops and Conditionals
- Execution Contexts and Program Inputs
- Deterministic Termination Requirements
Chapter 4: Writing Your First eBPF Programs
- Setting Up the Development Environment
- The LLVM/Clang Compilation Pipeline
- A Hello World Tracepoint Program
- Building with libbpf Skeletons
- Running and Reading Output
- Understanding the Generated Code
Chapter 5: The eBPF Verifier
- Why the Verifier Exists
- Safety Guarantees: Memory, Execution Time, Privileges
- How the Verifier Works: State Machine Analysis
- Common Verification Failures and Fixes
- Loop Unrolling and Complexity Limits
- Understanding Verifier Logs
Chapter 6: JIT Compilation
- Why JIT Compilation Matters
- The JIT Compilation Pipeline
- Architecture-Specific JITs (x86, ARM, RISC-V)
- JIT vs Interpreter Performance
- Enabling, Disabling and Tuning JIT
- When Native Performance Is Critical
Chapter 7: eBPF Maps - Data Structures Between Kernel and User Space
- What Maps Are and Why They Matter
- Hash Maps: The Workhorse
- Array Maps and Perf Arrays
- Ring Buffers for High-Throughput Data
- LRU and Per-CPU Variants
- Map Performance and Capacity Planning
Chapter 8: Helper Functions - Talking to the Kernel
- The Helper Function Calling Convention
- Core Helpers: Time, Task and Map Operations
- Networking Helpers for Packets and Sockets
- Tracing Helpers for kprobes and Tracepoints
- Security and Permission Helpers
- Choosing the Right Helper
Chapter 9: BTF and CO-RE - Kernel-Agnostic eBPF Programs
- The Kernel Version Compatibility Problem
- What BTF Is: Type Information in the Kernel
- How CO-RE Relocation Works
- Writing CO-RE-Compatible Programs
- libbpf’s Role in CO-RE
- Debugging CO-RE Relocations
Chapter 10: Tracing with kprobes, uprobes and Tracepoints
- kprobes: Instrumenting Kernel Functions
- Finding Safe Probe Locations
- uprobes for User-Space Tracing
- Tracepoints: Stable Instrumentation Points
- Raw Tracepoints for Maximum Performance
- Choosing the Right Tracing Mechanism
Chapter 11: fentry, fexit and Modern Function Tracing
- How fentry/fexit Differ from kprobes
- Performance Advantages of fentry/fexit
- Attaching to Kernel Functions Safely
- Return Value Tracing with fexit
- Limitations and Gotchas
- Migration Guide: From kprobes to fentry
Chapter 12: XDP - Extreme Packet Processing at Line Rate
- The Networking Performance Problem
- XDP Architecture and Execution Points
- Driver, Hardware and Generic Modes
- Writing Your First XDP Program
- Packet Manipulation and Actions
- XDP in Production: Load Balancing and DDoS Protection
Chapter 13: Traffic Control, Socket Filters and cgroups Programs
- Traffic Control (TC) Hooks
- Socket Filters for Application Traffic
- cgroup Attach Points: v1 vs v2
- Socket Operations Tracing
- Container-Aware Networking with cgroups
- Combining Multiple Network Hooks
Chapter 14: Security Monitoring with eBPF and LSM Hooks
- Why Traditional Security Tools Fall Short
- Syscall Monitoring and Auditing
- File System Access Tracking
- Process Lifecycle Monitoring
- LSM Hooks: Deep Kernel Security Integration
- Building a Security Monitoring Stack
Chapter 15: Observability, Profiling and Performance Analysis
- The Three Pillars: Metrics, Traces, Logs
- Building Custom Observability Tools
- CPU Profiling with eBPF
- Latency Analysis and Histograms
- Integration with Prometheus and OpenTelemetry
- Production Monitoring Patterns
Chapter 16: Kubernetes and Container Visibility
- Containers as a Tracing Challenge
- Namespace-Aware eBPF Programs
- Pod and Container Identification
- Service Mesh Integration (Istio, Cilium)
- Runtime Security in Kubernetes
- Multi-Tenant Observability
Chapter 17: Production Operations - Deploying, Securing and Maintaining eBPF
- Security Model and Privilege Management
- Deployment Strategies and Automation
- Debugging Production eBPF Programs
- Performance Tuning and Resource Limits
- Version Compatibility and Rollout Planning
- Monitoring Your eBPF Infrastructure
Conclusion: The Future of eBPF
- Where eBPF Has Been
- Emerging Capabilities and Active Development
- Beyond Linux: Cross-Platform Prospects
- Skills That Will Matter
- Final Thoughts on Systems Engineering with eBPF