eBPF (extended Berkeley Packet Filter) is a Linux kernel technology that runs small, verified programs inside the kernel in response to events such as system calls, function entries, network packets and scheduler activity. In Linux monitoring, it gives administrators and engineers deep observability with low overhead and without loading custom kernel modules or rebooting the system.
The original Berkeley Packet Filter was a narrow tool for filtering packets in programs such as tcpdump. The extended version, merged into Linux from kernel 3.18 onward and greatly expanded since, turned it into a general-purpose in-kernel virtual machine. Today eBPF underpins tracing tools such as bpftrace, parts of perf, container networking stacks and runtime security agents.
How eBPF programs run inside the kernel
An eBPF program follows a load, verify, compile and attach life cycle. A user-space tool compiles restricted C or a higher-level script into eBPF bytecode, loads it through the bpf() system call, and attaches it to a hook. When the hooked event occurs, the kernel executes the program and the program records or acts on what it observes.
Safety comes from the in-kernel verifier. Before any program runs, the verifier walks every possible execution path and rejects code that could read invalid memory, loop without bound or exceed the instruction complexity limit of one million verified instructions on modern kernels. Accepted bytecode is then translated by a just-in-time (JIT) compiler into native machine code, so it runs at nearly the speed of compiled kernel code.
Programs exchange data with user space through eBPF maps, which are kernel-resident key-value structures. A monitoring tool typically aggregates counts or histograms in a map inside the kernel and reads only the summary, which avoids copying every event across the kernel and user-space boundary.
The table below summarizes the main building blocks and the role each plays.
| Component | Role | Why it matters |
|---|---|---|
| Bytecode | Portable instruction set of 11 registers | Same program runs on many architectures |
| Verifier | Static analysis before loading | Prevents crashes and unsafe memory access |
| JIT compiler | Converts bytecode to native code | Keeps per-event cost very low |
| Maps | Shared hash, array, ring buffer and other stores | Moves aggregated data to user space |
| Helpers and kfuncs | Approved kernel functions callable from programs | Limits what a program may touch |
| BTF and CO-RE | Type information and relocation | Lets one binary run on many kernel versions |
Hook points used for Linux monitoring
The value of eBPF in monitoring depends on where a program attaches. Each hook type exposes a different layer of the system, and the choice affects both stability across kernel versions and the amount of overhead.
| Hook type | What it observes | Stability across kernels |
|---|---|---|
| Tracepoints | Static, documented kernel events | High, defined as a stable interface |
| kprobes and kretprobes | Entry and return of almost any kernel function | Low, function names and arguments change |
| fentry and fexit | Kernel functions via BPF trampolines | Medium, faster than kprobes |
| uprobes | Functions in user-space binaries and libraries | Depends on the application build |
| USDT probes | Static markers compiled into applications | High when the application maintains them |
| perf events | CPU sampling and hardware counters | High |
| XDP and tc | Network packets at the driver or traffic-control layer | High |
Experienced practitioners prefer tracepoints for long-lived dashboards, because a tracepoint keeps its meaning across releases, and reserve kprobes for ad hoc investigation, where flexibility outweighs the risk that the probed function is renamed or inlined in the next kernel.
eBPF compared with classic monitoring tools
Classic Linux tools such as top, vmstat and iostat read periodic counters from procfs, while strace intercepts system calls through ptrace. eBPF differs because it observes individual events in the kernel and summarizes them in place, which reveals latency distributions and causes that counters cannot show.
| Approach | Data source | Typical overhead | Best use |
|---|---|---|---|
| procfs-based tools | Kernel counters sampled at intervals | Negligible | Quick health overview |
| strace | ptrace stops on every system call | High, often several times slower | Debugging one process |
| perf | Sampling, counters and tracepoints | Low to moderate | CPU profiling |
| eBPF via bpftrace or BCC | Programmable in-kernel probes | Low with in-kernel aggregation | Latency and causal analysis |
| Kernel modules | Arbitrary kernel code | Low, but unsafe | Legacy or special drivers |
In practice eBPF complements rather than replaces these tools. A quick look at uptime or vmstat shows that something is wrong, and an eBPF tool such as biolatency or runqlat explains where the time is going.
Tooling and practical deployment
Most administrators never write raw bytecode. They use front ends that generate eBPF programs: bpftrace for one-line scripts, the BCC collection of ready-made tools, and libbpf-based binaries that ship as compiled, portable programs. Observability agents, container network plugins and runtime security products also embed eBPF.
- Kernel version matters: a kernel of 5.8 or later with BTF enabled supports most modern features, including ring buffers and CO-RE.
- Privileges are required: loading tracing programs normally needs
CAP_BPFtogether withCAP_PERFMON, or full root. - Unprivileged eBPF is disabled by default on most distributions through the
kernel.unprivileged_bpf_disabledsetting. - Pinned programs and maps in the BPF file system survive the exit of the loading process.
Limitations, risks and common mistakes
eBPF is safe by design but not free of cost or risk. A probe on a function that fires millions of times per second adds measurable CPU load, and the verifier guarantees safety, not correctness. The following table lists frequent problems and their remedies.
| Problem | Cause | Remedy |
|---|---|---|
| Noticeable CPU overhead | Probing a very hot function or sending every event to user space | Aggregate in maps and sample where possible |
| Program fails to load | Verifier rejects complex loops or missing bounds checks | Add explicit bounds and simplify logic |
| Tool breaks after upgrade | kprobe target renamed or inlined | Switch to tracepoints or CO-RE builds |
| Lost events | Perf or ring buffer too small | Enlarge the buffer and reduce event volume |
| Security exposure | Overly broad privileges for eBPF loaders | Restrict capabilities and audit loaded programs |
A further concern is that attackers can also use eBPF to hide activity or read sensitive data once they hold root privileges. Security teams therefore inventory loaded programs with bpftool prog list and treat unexpected eBPF programs as an indicator of compromise.
In everyday language
The Linux kernel is the core of the system. It handles every disk read, network packet and program start. Normally it is hard to see inside it. eBPF lets you place tiny, checked sensors at chosen spots in the kernel.
Each sensor is a small program. Before it runs, the kernel inspects it for safety. If it could crash the system, it is refused. Once accepted, it counts or measures events very quickly. It then reports only a short summary. It works like fitting a traffic counter at one junction instead of filming the whole city.
Seen in the real world
An operations engineer runs a PostgreSQL database on a Linux server where query times randomly jump from 5 ms to 200 ms. The tools top and iostat show average disk usage of only 30 percent, so the cause is unclear. The engineer runs the eBPF tool biolatency for 60 seconds and sees that most disk requests finish in under 1 ms, but a small tail exceeds 150 ms.
A second eBPF tool, runqlat, shows normal scheduler delay, which rules out CPU contention. Tracing block requests per process then reveals that a nightly backup job issues large synchronous writes at the same moments. After the backup is moved to a different volume and given a lower I/O priority, the latency spikes disappear. The whole investigation runs on the production server with less than 2 percent extra CPU load and no restart.