Skip to main content

SPDK

SPDK runs NVMe/TCP and NVMe/RDMA in user space, where kernel hooks see nothing of it. ntprof reads SPDK through USDT probes that a small patch adds to SPDK's hosts and targets of both transports. The next section explains why SPDK needs a patch while the Linux drivers need none; Using it shows how.

Why a patch for SPDK, and none for the kernel​

In short: a hook in the kernel runs where the I/O already is and costs tens of nanoseconds. SPDK's I/O never enters the kernel, so a hook on SPDK from outside is a trap into the kernel and back, about 0.8 µs each, on every command, inside the very times it measures. SPDK's own trace is cheap but lacks the events and the command IDs a breakdown needs. So the patch lets SPDK take the times itself and hand them over once per command.

Linux drivers + eBPFhooks run in the kernel,where the I/O already iskernela hook: tens of nsSPDK, hooked from outsideuprobes: no change to SPDK,a trap per hook, every commanduser spacekernellongertrap, about 0.8 µsSPDK + ntprof's patchSPDK reads the clock itself;one probe after the commanduser spacekernelone probe, after the command is doneclock reads: tens of ns
One sampled I/O, left to right. Teal: the I/O's own work. Orange: a trap from user space into the kernel and back. Hooked from outside, SPDK pays a trap at every hook and the I/O gets longer; with the patch, the times are taken in place and the one trap comes after the command is done, outside the times measured.

The Linux drivers: hooks where the I/O already runs​

The kernel's NVMe drivers run in the kernel, and so do eBPF programs. ntprof attaches its programs to tracepoints the kernel already has (nvme_setup_cmd, block_rq_issue, nvmet_req_init, …) and to the drivers' own functions (fentry or kprobe); when a command passes one of these points, the program runs right there, on the same CPU, in the same kernel context. The kernel's BTF type information tells ntprof the layout of the drivers' structures, so it can read a command's ID, queue and length without any change to the kernel.

Such a hook is cheap: in one of our measurements a 4 KiB read passed 34 hook runs that took 2.2 µs together, about 60 ns each. That is why ntprof can afford to let every command pass every hook, sampled or not: on our servers, recording both sides at one command in 1000 adds 0.8 µs (NVMe/RDMA) and 1.3 µs (NVMe/TCP) to a 4 KiB read.

SPDK: the I/O never enters the kernel​

SPDK drives the NIC (over RDMA) and the SSD from user space and polls them; over TCP it still uses the kernel's socket calls, but everything NVMe happens in SPDK's own code. There are two ways to watch it without changing it. We looked at both.

1. Hook SPDK's functions from outside (uprobes). Linux can attach an eBPF program to any function of a running program. This needs no change to SPDK, and most of the functions where SPDK's stages change are still in the binary to hook. But a uprobe works by a breakpoint: every time the program reaches it, the CPU traps into the kernel, runs the eBPF program and returns. That costs about 0.8 µs per hit in our measurement, and three things make it unusable here:

  • It lands inside the times measured. A read crosses about 16 stage boundaries. Our first SPDK version had a probe at each of them (attached probes trap the same way), and the traps inflated the very commands they timed: sampled reads measured 30.8 µs while the application saw 19.0 µs.
  • Every command pays. A uprobe traps before any code can decide whether the command is sampled, so every command takes the traps, as if every command were traced. In our first version, tracing every command made reads go from 17.6 µs to 31.4 µs.
  • SPDK's structures have no BTF. To read a command's ID from SPDK's memory, ntprof would need the layout of SPDK's internal structures for each SPDK version and build.

2. Use SPDK's own trace. SPDK has a built-in trace: an application started with -e <group> (or told so over its RPC) writes records to a ring in shared memory, and spdk_trace reads them. It is cheap, with no trap. But it was made for debugging SPDK, not for joining two machines, and in SPDK v26.05 it lacks what a breakdown needs:

  • The NVMe/RDMA host has no trace points, and the NVMe/TCP host records only a command's submission and completion, not when it was sent or when its response arrived.
  • The target names a request by its memory address, not by the NVMe command ID, so its records cannot be matched with the host's, command by command.
  • spdk_nvme_perf has no trace option, and the times are in CPU ticks, not the clock the kernel hooks use.

What the NSDI'25 paper proposed​

The paper (§3.7) proposed extending ntprof to SPDK by defining tracepoints in SPDK's tracing framework and capturing them with eBPF, which SPDK supports through USDT probes (./configure --with-usdt). USDT probes are places marked in the program's source when it is built, so this route also changes SPDK's code: SPDK v26.05 has 40 USDT probes of its own, but all on setup events (controllers, queue pairs, subsystems, poll groups), none on a command's way through its NVMe/TCP or NVMe/RDMA code. Our first SPDK version followed the proposal with a probe at every stage boundary; that is where the 30.8 µs above came from. The patch keeps the approach, USDT probes read by eBPF, and changes how often a probe fires: once per sampled command and side.

What the patch does instead​

The patch (about 190 lines in SPDK, plus one header) moves the measurement into SPDK and keeps the trap out of it:

  1. Sampling first. For each command SPDK checks one variable that ntprof sets when it starts: one load and one compare. Commands that are not sampled cost nothing more.
  2. Times taken in place. For a sampled command, SPDK writes the time of each stage boundary into the request, with clock_gettime(), which takes tens of nanoseconds and no trap, on the same clock as the kernel's eBPF programs.
  3. One probe, after the command is done. When the command completes on that side, one USDT probe hands the times and the command's IDs to ntprof. Its trap comes after the last time was taken, so it is not in the measurement.

The result agrees with SPDK's own view: on our servers ntprof's mean is within 0.3 µs of spdk_nvme_perf's (66.17 against 66.11 µs over RDMA, 82.34 against 82.08 µs over TCP; tutorial), and recording both sides at one command in 1000 adds 0.11 µs (RDMA) and 0.18 µs (TCP) to a 4 KiB read.

WayCost per I/OBreakdown
uprobes on SPDK's functions (no change to SPDK)about 0.8 µs per hook, on every command, inside the timesinflated
SPDK's own trace (no change to SPDK)smallno: missing events, no command IDs to join
ntprof's patch (about 190 lines)one compare; for a sampled command, clock reads and one probe after ityes
The price of the patch

SPDK must be rebuilt with it, and the patch is made for one SPDK release (v26.05). It touches only the NVMe/TCP and NVMe/RDMA host and target code and the socket layer, and SPDK builds and passes its own unit tests for those files with it. If SPDK took such hooks upstream, no patch would be needed.

Using it​

cd spdk && git checkout v26.05
git apply /path/to/ntprof/spdk/ntprof-usdt-v26.05.patch
./configure --with-usdt --with-rdma && make

Start the SPDK applications first, then ntprof, naming the binary of each side that runs in SPDK:

sudo ntprof probe -r both --spdk-host spdk/build/bin/spdk_nvme_perf --spdk-target spdk/build/bin/nvmf_tgt
sudo ntprof record -r both -s 1 --spdk-host spdk/build/bin/spdk_nvme_perf --spdk-target spdk/build/bin/nvmf_tgt
sudo ntprof record -r both --spdk-target spdk/build/bin/nvmf_tgt # kernel host, SPDK target
sudo ntprof record -r both -t rdma --spdk-host spdk/build/bin/spdk_nvme_perf --spdk-target spdk/build/bin/nvmf_tgt
  • ntprof profiles every running process that maps the named file. With SPDK's shared libraries, name the transport library first and add the socket module, for example --spdk-target build/lib/libspdk_nvmf.so,build/lib/libspdk_sock_posix.so.
  • SPDK samples nothing until ntprof, once attached, writes its sampling period into the processes, and ntprof writes 0 back when it stops. An unsampled command costs SPDK one load and one compare. For a sampled command, SPDK writes the stage times itself and one probe per side fires when the command is done, so the probe's cost stays out of the times.
  • An SPDK host has no block layer: the host block layer is not shown, and the throughput is estimated from the sampled commands.
  • The driver rows of an SPDK side read "host driver (SPDK)" and "target driver (SPDK)". With an SPDK target, storage is "storage (SPDK bdev, drive)", the bdev layer and the device, without the block-layer split.
  • tests/demo-spdk.sh runs the steps on one machine in about a minute, with ntprof's mean latency next to spdk_nvme_perf's own.

SPDK against the Linux drivers​

Two servers, 400 GbE RoCE, the same Samsung PM9A3 drive, one I/O at a time. Mean µs per I/O, each cell SPDK on both sides / the Linux drivers on both sides; "drivers" is the host and target drivers together. SPDK drives the SSD with its own NVMe driver (the drive bound to uio_pci_generic, the bdev from bdev_nvme_attach_controller).

NVMe/RDMA (Linux: nvme-rdma, nvmet-rdma)

TotalNetworkDriversStorage
4 KiB read66.2 / 72.86.4 / 10.00.5 / 2.359.3 / 60.0
4 KiB write13.9 / 19.76.1 / 9.60.4 / 1.67.4 / 8.1
128 KiB read103.8 / 121.211.7 / 15.70.5 / 10.891.6 / 93.7
128 KiB write51.9 / 76.813.7 / 25.80.6 / 11.137.6 / 39.0

NVMe/TCP (Linux: nvme-tcp, nvmet-tcp)

TotalNetworkDriversStorage
4 KiB read84.0 / 86.720.5 / 19.73.9 / 6.359.6 / 60.1
4 KiB write30.4 / 33.518.7 / 18.53.8 / 6.37.8 / 8.2
128 KiB read144.2 / 181.631.0 / 56.421.3 / 31.791.9 / 92.8
128 KiB write135.5 / 148.053.0 / 77.745.0 / 30.937.5 / 38.9
  • Storage is the drive: SPDK's storage stage equals the drive measured alone through SPDK's driver (bdevperf, 4 KiB read 59.4 µs). Through Linux's NVMe driver instead (an AIO bdev), SPDK's storage stage was about 2 µs higher and everything else the same.
  • Over RDMA, SPDK saves its time in the drivers and in the network stage, which includes the interrupts and completion work of the Linux drivers on both machines; SPDK polls. A 128 KiB write's RDMA READ took 8.2 µs against 15.8 µs.
  • Over TCP, SPDK still uses the Linux TCP stack on both machines, so a 4 KiB I/O spends the same time in the network; SPDK saves 2–3 µs in the drivers.
  • At 128 KiB over TCP, ntprof does not split SPDK's data phase: receiving the rest of a read's data, copying and waiting together, stays in SPDK's host driver (17 µs), and receiving a write's data in SPDK's target driver (41 µs). The Linux numbers count the waiting as network, so compare the totals there. TCP numbers also vary between connections: one SPDK round had an extra 30 µs in the network for part of its commands.
  • The Linux side also has a host block layer (0.5–0.9 µs), which SPDK does not.
  • ntprof, recording one command in 1000 on both sides, added 0.11 µs (RDMA) and 0.18 µs (TCP) to the 4 KiB read.