Skip to content

RFC blk-iocost: BPF struct_ops cost model

Tao Cui bpf cgroups linux-block linux-kselftest lkml 15 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v14 RFC Latest4 patches 1 replyIn review
  2. v13 RFC4 patches 5 repliesSuperseded
  3. v12 RFC4 patches 6 repliesSuperseded
Earlier versions · 12
VersionPostedPatchesRepliesStatus
v11 RFC5 patches15 repliesSuperseded
v10 RFC4 patches12 repliesSuperseded
v9 RFC4 patches1 replySuperseded
v8 RFC4 patches9 repliesSuperseded
v7 RFC4 patches10 repliesSuperseded
v6 RFC5 patches6 repliesSuperseded
v5 RFC5 patches3 repliesSuperseded
v4 RFC posting 2/25 patches1 replySuperseded
v4 RFC posting 1/20 of 5 patches0 repliesSuperseded
v3 RFC5 patches2 repliesSuperseded
v2 RFC5 patches1 replySuperseded
v1 RFC8 patches7 repliesSuperseded

Changes in v14 from the cover letter

- p1: stop updating attached and attached_link under ioc->lock; rq_qos_mutex already orders all their accessors (review from tj)
- p1: name the calc_cost flags enum iocost_calc_flags and rename ioc_model()/model to ioc_bpf_model()/bpf_model so that the builtin model isn't called a NULL model (review from tj)
- p1: document why iocost holds its own model reference, the field locking and the merge flag semantics, and reword the commit message to describe guarantees instead of code paths (review from tj)
- p1: clear the autop stepping timestamps when a BPF model is attached; without this, the timestamps from before the attach survive until a model=linear switchback and can trigger an immediate profile step on that stale pre-attach evidence (report from sashiko)
- p1: align the BPF pricing scope with the builtin model:
dataless bios with no flush state and ops other than reads, writes and zone appends cost nothing, completion-time sizing prices reads, writes and zone appends, and a dead owning map no longer reports -EBUSY (report from sashiko)
- p3: probe the iocost_ioc_tick tracepoint, unwind the private mount namespace on setup failure, report fopen errors faithfully and fix an inverted posix_memalign() assertion that made the streams test skip its whole IO block (report from sashiko)
- p2/p4: document the iocost_ioc_tick fields in the trace header and extend the io.cost.model docs with the dev supply and the -ENODEV attach conditions (report from sashiko)

Patches in v14 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4blk-iocost: add BPF struct_ops cost model supportblock/Kconfig block/blk-iocost.c+342 -40 replies
2/4blk-iocost: add iocost_ioc_tick tracepoint for per-period device summaryMAINTAINERS block/blk-iocost.c include/trace/events/iocost.h+76 -00 replies
3/4selftests/bpf: add iocost cost model testtools/testing/selftests/bpf/config tools/testing/selftests/bpf/prog_tests/iocost_model.c tools/testing/selftests/bpf/progs/iocost_model.c +1 more+1332 -00 replies
4/4docs: cgroup-v2: document the iocost BPF cost model attachmentDocumentation/admin-guide/cgroup-v2.rst+47 -80 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by.

PatchAlexei StarovoitovTejun Heo
1/4A-b
2/4A-b
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v14 thread

Cover letter [RFC PATCH v14 0/4] blk-iocost: BPF struct_ops cost model

From: Tao Cui <[email protected]>

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-20261117.

Changes since v13:
- p1: stop updating attached and attached_link under ioc->lock; rq_qos_mutex already orders all their accessors (review from tj)
- p1: name the calc_cost flags enum iocost_calc_flags and rename ioc_model()/model to ioc_bpf_model()/bpf_model so that the builtin model isn't called a NULL model (review from tj)
- p1: document why iocost holds its own model reference, the field locking and the merge flag semantics, and reword the commit message to describe guarantees instead of code paths (review from tj)
- p1: clear the autop stepping timestamps when a BPF model is attached; without this, the timestamps from before the attach survive until a model=linear switchback and can trigger an immediate profile step on that stale pre-attach evidence (report from sashiko)
- p1: align the BPF pricing scope with the builtin model:
dataless bios with no flush state and ops other than reads, writes and zone appends cost nothing, completion-time sizing prices reads, writes and zone appends, and a dead owning map no longer reports -EBUSY (report from sashiko)
- p3: probe the iocost_ioc_tick tracepoint, unwind the private mount namespace on setup failure, report fopen errors faithfully and fix an inverted posix_memalign() assertion that made the streams test skip its whole IO block (report from sashiko)
- p2/p4: document the iocost_ioc_tick fields in the trace header and extend the io.cost.model docs with the dev supply and the -ENODEV attach conditions (report from sashiko)

Tested on next-20261117 (qemu x86_64): the selftests pass, and the 2x example model doubles the charged cost over the builtin on a rotational device (2.00x measured), returning to 1.00x after "model=linear".

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       |  55 +-
 MAINTAINERS                                   |   1 +
 block/Kconfig                                 |   4 +
 block/blk-iocost.c                            | 360 ++++++-
 include/trace/events/iocost.h                 |  57 ++
 tools/testing/selftests/bpf/config            |   2 +
 .../selftests/bpf/prog_tests/iocost_model.c   | 947 ++++++++++++++++++
 .../selftests/bpf/progs/iocost_model.c        | 188 ++++
 tools/testing/selftests/bpf/progs/iocost_ms.c | 195 ++++
 9 files changed, 1797 insertions(+), 12 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