Skip to content

Instantly share code, notes, and snippets.

View davidlohr's full-sized avatar

Davidlohr Bueso davidlohr

View GitHub Profile
@davidlohr
davidlohr / io_uring_profile.bt
Created April 23, 2026 20:03
BPF script to profile io_uring workloads
#!/usr/bin/env bpftrace
/*
* io_uring workload insight.
*
* Gives a complete picture of io_uring activity during a workload:
* - ring lifecycle (create, cqring wait)
* - submission & completion volume and per-opcode breakdown
* - per-request latency (submit -> complete) per opcode
* - registration-path activity (buffers/files/etc.), with stacks
* - async-work offload and io_uring_enter traffic
@davidlohr
davidlohr / hmm-snoop.bt
Created April 21, 2026 00:39
Linux HMM snooping tool
#!/usr/bin/env bpftrace
/*
* hmm-snoop.bt -- comprehensive observer for Linux HMM / CPU-GPU memory
*
* Reports all CPU<->device memory interactions that flow through the
* kernel's HMM (Heterogeneous Memory Management) APIs, without any driver
* cooperation. Works transparently for any driver that uses the standard
* migrate_vma_* / hmm_range_fault interface: amdgpu/amdkfd, nouveau,
* drm/xe (via drm_pagemap), and lib/test_hmm. No kernel patches required.
*
@davidlohr
davidlohr / offline_mem.sh
Last active October 4, 2025 19:05
A script to offline a certain percentage of memory from a specific NUMA node.
#!/bin/bash
# A script to offline a certain percentage of memory from a specific NUMA node.
# --- Input Validation ---
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit 1
fi
#!/usr/bin/env bpftrace
/*
* extfragsnoop Trace events that induce system external memory fragmentation.
* For Linux, uses bpftrace and eBPF.
*
* This traces when a fallback event occurs, particularly mixed pageblocks that
* occur as a consequence of pollution upon memory pressure.
*
* Unmovable memory is the enemy of a de-fragmenting process (compaction), so
* gather such allocations as well as situations when movable memory becomes
@davidlohr
davidlohr / qemu-4xinterleave-switch-type3.cfg
Last active December 11, 2023 02:09
syzkaller config - qemu deployment emulating a 4 devices setup below a switch suitable for 1, 2 or 4 way interleave
{
"target": "linux/amd64",
"http": "127.0.0.1:56741",
"workdir": "workdir",
"kernel_obj": "/home/dave/code/linux/",
"image": "/img/bullseye.img",
"sshkey": "/img/bullseye.id_rsa",
"syzkaller": "/home/dave/code/syzkaller",
"procs": 8,
"type": "qemu",
@davidlohr
davidlohr / qemu-4xinterleave-1cfmw-2hb-2rp-type3.cfg
Last active December 24, 2024 16:06
syzkaller config - qemu deployment emulating a setup suitable for 4 way interleave. Only one fixed window provided, to enable 2 way interleave across 2 CXL host bridges. Each host bridge has 2 CXL Root Ports, with the CXL Type3 device directly attached (no switches).
{
"target": "linux/amd64",
"http": "127.0.0.1:56741",
"workdir": "workdir",
"kernel_obj": "/home/dave/code/linux/",
"image": "/img/bullseye.img",
"sshkey": "/img/bullseye.id_rsa",
"syzkaller": "/home/dave/code/syzkaller",
"procs": 8,
"type": "qemu",
@davidlohr
davidlohr / qemu-single-volatile-nolsa-type3.cfg
Last active December 11, 2023 02:11
syzkaller config - qemu deployment emulating a simple setup with just one directly attached CXL Type 3 volatile memory device
{
"target": "linux/amd64",
"http": "127.0.0.1:56741",
"workdir": "workdir",
"kernel_obj": "/home/dave/code/linux/",
"image": "/img/bullseye.img",
"sshkey": "/img/bullseye.id_rsa",
"syzkaller": "/home/dave/code/syzkaller",
"procs": 8,
"type": "qemu",
@davidlohr
davidlohr / qemu-single-pmem-type3.cfg
Last active December 11, 2023 02:09
syzkaller config - qemu deployment emulating a simple setup with just one directly attached CXL Type 3 Persistent Memory device
{
"target": "linux/amd64",
"http": "127.0.0.1:56741",
"workdir": "workdir",
"kernel_obj": "/home/dave/code/linux/",
"image": "/img/bullseye.img",
"sshkey": "/img/bullseye.id_rsa",
"syzkaller": "/home/dave/code/syzkaller",
"procs": 8,
"type": "qemu",
Applies to the MM, but works on any subsystem.
Based on https://deferred.io/2015/10/27/visualizing-linux-kernel-call-graphs.html
$ git diff
diff --git a/Makefile b/Makefile
index c43d825a3c4c..3b9f43a112b8 100644
--- a/Makefile
+++ b/Makefile
@@ -523,7 +523,7 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
// Copyright (C) Davidlohr Bueso, 2018.
//
// Convert the infamous mmap_sem to a range lock.
// Usage within the kernel source:
//
// $ make coccicheck MODE=patch COCCI=/path/to/mmap_sem.cocci
virtual patch
virtual context
virtual org