Re: [PATCH v15 0/4] blk-iocost: BPF struct_ops cost model
From: Tao Cui
Date: Fri Dec 04 2026 - 04:06:49 EST
在 2026/12/3 23:03, Tao Cui 写道:
> From: Tao Cui <cuitao@xxxxxxxxxx>
>
> This series lets a BPF program take over the cost model of one
> device. The BPF model provides calc_cost() for charged IOs plus two
> transfer coefficients for the completion-time sizing, io.cost.model
> selects between the attached model and the builtin one, and enabling
> and disabling the controller stays with io.cost.qos.
>
> The builtin model is a linear formula derived from a handful of device
> parameters, and the right formula is device specific. A BPF model can
> be adapted to the device and updated without rebuilding the kernel.
>
> The series is based on next-20261201.
>
> Changes since v14:
> - p1: put the three BPF fields under CONFIG_BLK_CGROUP_IOCOST_BPF
> with stub helpers, and pass IOCOST_CALC_* flags into
> calc_vtime_cost() instead of a bool (review from tj)
> - p1: iocost_model_ops gains a name[] member; io.cost.model prints
> "model=bpf name=<name>" and the docs cover the new key (review
> from tj)
> - p1: rework the attach/detach lifecycle: .reg() keeps the bdev
> reference and stores the ops pointer in a private member,
> .unreg() reaches the queue through it and drops the reference,
> and ioc_rqos_exit() queues a work item running the usual
> .unreg(); a NULL-link attach is rejected with -EOPNOTSUPP
> (review from tj)
> - p1: switching the cost model resets the per-iocg vtime state
> accumulated under the old pricing: debts, delays and waiters are
> dropped and vtime snaps to the activation target. An RCU grace
> period before the reset ensures every bio priced by the outgoing
> model is accounted for; the accounting also resets on attach and
> on device removal, and the model write resets before freezing
> the queue so it cannot stall behind the waiters it releases
> (review from tj)
> - p1: clamp a bio's completion-time payoff to vtime so that stale
> costs from bios still in flight across a switch cannot push
> done_vtime past vtime
> - p2: drop the field documentation block that v14 added to the
> iocost_ioc_tick tracepoint and return it to its v13 form (report
> from bpf-ci)
> - p3: mount cgroup2 in a private mount namespace, return negative
> error codes from open_nullb_dev(), and preserve the working
> directory across the setns() unwind (reports from sashiko and
> bpf-ci)
> - p3: add the upper-bound validate case, snapshot the stream
> counters per phase so the assertions cover that phase alone, and
> probe the tracepoint via kallsyms instead of tracefs
> - p4: the coefficient readback under a BPF model shows only
> "model=bpf" plus the model name, and the io.cost.model key table
> lists name=
>
> The p1 lifecycle rework and the model-switch reset change the
> reference semantics Alexei's ack covered (the bdev handoff, the
> workfn eject, the new iocost_model_ops members and the NULL-link
> rejection); a re-review would be appreciated.
>
Hmm,v15 turned out to be the worst posting of this series,three
high-severity bugs in the lifecycle I had just reworked, one of them a
recurrence of a defect already reported on RFC v7, and none of it
caught before posting. Sorry for the noise, and v16 will address all of the reported problems.
Thanks,
Tao
> Tested on next-20261201 (two qemu x86_64 VMs, rotational device):
> the builtin model collapses two sequential 4K readers to ~2 MB/s,
> switching to the attached BPF model completes the io.cost.model
> write in 0.02s and recovers immediately, and switching back
> collapses again; an overnight tidal run of 37 load cycles over 9.6h
> completed 13M+ transactions with all 37 model switches in
> 0.01-0.03s and nothing in dmesg. The selftests pass (3 tests,
> 0 skipped). The final tree also rebuilds cleanly from the four
> patches applied to a fresh next-20261201 tree, kernel and selftests
> alike.
>
> Link: https://lore.kernel.org/r/20261118131029.797007-1-cui.tao@xxxxxxxxx # v14
>
> Tao Cui (4):
> blk-iocost: add BPF struct_ops cost model support
> blk-iocost: add iocost_ioc_tick tracepoint for per-period device
> summary
> selftests/bpf: add iocost cost model test
> docs: cgroup-v2: document the iocost BPF cost model attachment
>
> Documentation/admin-guide/cgroup-v2.rst | 56 +-
> MAINTAINERS | 1 +
> block/Kconfig | 4 +
> block/blk-iocost.c | 705 ++++++++++++++-
> include/trace/events/iocost.h | 43 +
> tools/testing/selftests/bpf/config | 2 +
> .../selftests/bpf/prog_tests/iocost_model.c | 1021 +++++++++++++++
> .../selftests/bpf/progs/iocost_model.c | 189 +++
> tools/testing/selftests/bpf/progs/iocost_ms.c | 206 +++
> 9 files changed, 2192 insertions(+), 35 deletions(-)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/iocost_model.c
> create mode 100644 tools/testing/selftests/bpf/progs/iocost_model.c
> create mode 100644 tools/testing/selftests/bpf/progs/iocost_ms.c
>
> --
> 2.53.0