Trace and analyze Large Language Model (LLM) inference workloads (e.g., PyTorch + CUDA) at the Linux kernel level using eBPF.
This project enables system-level observability for modern AI inference pipelines — revealing what happens when LLMs interact with memory, CPUs, GPUs, and the filesystem under the hood.
LLMs like LLaMA, Mistral, and GPT-variants require optimized infrastructure. While most focus on model design or training, inference performance depends heavily on OS-level behaviors like:
- File I/O for model weights (multi-GB mmap)
- CPU-GPU data paths and device access
- Thread pinning, scheduling, and NUMA locality
- Page locking (mlock) and memory pressure
Traditional profilers miss this. eBPF (extended Berkeley Packet Filter) allows us to trace these interactions with zero modification to the model code or OS kernel.
- ✅ Trace
mmap,mlock,openatduring model loading - ✅ Visualize
sched_switchto track inference thread behavior - ✅ Monitor access to
/dev/nvidia*(GPU devices) - ✅ Support for PyTorch, TensorRT, and Hugging Face model servers
- ✅ Plug-and-play tracing using
bpftraceandbcc - 🧪 Optional integration with Prometheus and Grafana dashboards
bpftrace -e 'tracepoint:syscalls:sys_enter_mmap { @[comm] = count(); }'bpftrace -e 'tracepoint:syscalls:sys_enter_mlock { @[comm] = count(); }'bpftrace -e 'tracepoint:sched:sched_switch { @[prev_comm, next_comm] = count(); }'bpftrace -e 'tracepoint:syscalls:sys_enter_openat /str(args->filename) =~ "/dev/nvidia.*/" / { @[comm] = count(); }'- 🔹 Model load phase duration
- 🔹
mmapvsmlockevent frequency - 🔹 CPU usage per inference worker
- 🔹 NUMA locality and scheduling efficiency
- 🔹 Live latency trends per token
.
├── scripts/ # bpftrace tracing scripts
│ ├── mmap.bt
│ ├── mlock.bt
│ ├── sched.bt
│ └── gpu_access.bt
├── dashboards/ # (WIP) Grafana dashboards for LLM workload visibility
├── benchmark/ # Scripts to benchmark LLM inference performance
├── README.md # This file
└── LICENSE- Debug slow inference cold starts due to poor I/O or mmap
- Optimize thread pinning and scheduling latency
- Monitor GPU usage contention in shared environments
- Profile PyTorch and TensorRT workloads at system level
- Tune NUMA policies for large model inference
- Linux kernel ≥ 5.8
clang,llc, andbpftoolinstalled- Go ≥ 1.20
- Root/sudo access (required to load eBPF programs)
sudo apt update
sudo apt install \
linux-headers-$(uname -r) \
build-essential \
clang llvm libelf-dev libbpf-devgit clone https://github.com/ravikumar1907/llm-ebpf-tracer
cd llm-ebpf-tracermake bpfThis should generate .o object files from the bpf/*.bpf.c sources.
sudo go run ./cmd/main.goYou should see log output like:
Listening for mmap events... Press Ctrl+C to stop.
Received mmap trace event, raw bytes: [120 156 ...]
Open another terminal and run:
python3 -c "import torch; torch.zeros((10000, 10000)).cuda()"This will trigger mmap and possibly mlock + /dev/nvidia* accesses.
You should see trace output from the eBPF tracer as those syscalls happen.
If you enabled the Prometheus exporter:
curl http://localhost:2112/metricsWe're looking for collaborators who are into:
- PyTorch, HuggingFace, or vLLM internals
- Kernel memory and NUMA optimization
- eBPF, tracing, and observability pipelines
Open an issue, drop a PR, or just DM me on LinkedIn!
Ravikumar Vallabhu
Linux Kernel + AI Infra Enthusiast
LinkedIn →
GitHub →
MIT License — Free to use, modify, and share.
