blk-iocost: BPF struct_ops cost model
Subsystems (8)
cover blk-iocost: BPF struct_ops cost model
From: Tao Cui <[email protected]>
Why a pluggable model at all
----------------------------
When iocost landed in 2019, its commit message already promised that "a later patch will also allow using bpf progs for cost models", and the code has carried the split for it ever since: calc_vtime_cost() is a dispatcher whose only implementation is calc_vtime_cost_builtin(). Seven years later the builtin linear model is still the only one. This RFC fills that slot, following the bpf_tcp_ca and sched_ext
precedent: builtin algorithms stay as the default, new algorithms are prototyped in BPF behind a struct_ops.
The measured problems
---------------------
The builtin model prices each IO with a binary sequential/random base picked by a single per-cgroup cursor and a 16MB seek threshold, plus a per-page cost. On a virtio-blk device with the HDD autop profile, a 4k IO costs ~24us when judged sequential and ~2.7ms when judged random, a 112x spread, so a wrong judgement becomes a wrong price. Three classes of mispricing, all measured:
1. Heuristic rigidity. Two legitimate sequential readers in one cgroup (a database with multiple tablespaces, a threaded backup) ping-pong the single cursor and are all priced random: measured 89x overcharge, 12.9x throughput collapse under the same weight. Random IO within a hot window smaller than the 16MB threshold is priced sequential: measured 107x undercharge, an accounting escape for hotspot workloads. No setting of the six builtin parameters seems able to fix this: telling the streams apart requires per-IO state tracking, which looks like logic rather than coefficients.
2. Device nonlinearity. SLC-cache phases, SMR band placement and shared controllers (multiple NVMe namespaces multiplexing one device) make the real cost of an identical IO vary by an order of magnitude over time or across namespaces. A static 6-parameter linear model has no way to express that.
3. Unpriced operations. Flush and zone append fall through to a cost of zero and bypass throttling entirely (fixed in a separate series already posted), but the same pattern extends to device quirks the builtin model was never taught.
Mispricing feeds directly into the control loop: vtime budgets, surplus donation and the vrate feedback all consume the model's output, so a wrong model can skew the whole controller.
How
---
A new "iocost_model_ops" struct_ops with a single callback:
u64 calc_cost(op, nbytes, sector, cursor, iocg_id, flags)
scalar arguments only, no kernel pointers exposed; the return value is vtime (2^37 per second of device time), clamped to 1s per IO; a return value of 0 delegates the IO back to the builtin formula, so a model which only handles some IO types cannot make the rest free. iocg_id identifies the issuing cgroup so a model can keep per-cgroup state; struct_ops signatures are frozen once merged, so it is part of the initial interface. Devices opt in per queue with "echo $dev ctrl=bpf > io.cost.model"; everything else keeps the builtin model unchanged. Patch overview:
1/8: add an iocost_ioc_tick tracepoint emitting the per-period
controller state, so model quality can be evaluated without drgn (existing events are state-change driven and silent in steady state)
2/8: define the iocost_model_ops interface (above); the model is
called from the IO submission path under RCU and must not sleep
3/8: register the struct_ops; at most one model system-wide (EBUSY),
registration serialized with a mutex, base helper set allowed so models can use maps for per-cgroup state
4/8: dispatch cost calculation to the registered model in
calc_vtime_cost(), falling back to the builtin formula; the request-level sizing path keeps the builtin formula
5/8: per-device opt-in via ctrl=bpf
6/8: selftest with an example model (the builtin linear HDD formula
at double cost, mirroring bpf_dctcp as the in-tree reference implementation) plus a runner verifying registration and ctrl=bpf readback, including the rejected-without-model case
7/8: a second example model which replaces the single-cursor
sequentiality heuristic with per-cgroup multi-stream detection keyed by iocg_id, the first consumer of that argument
8/8: document ctrl=bpf in cgroup-v2.rst
Does it work
------------
Mechanism, verified functionally (QEMU, virtio-blk with the HDD profile, same 8s sequential-read workload from a 1%-weight cgroup, builtin vs the 2x example model):
- per-IO charge: 2854us -> 5728us, a factor of 2.001-2.007x; the completed IO count halves (2634 -> 1332) and total cost.usage is conserved (7.51s vs 7.63s of device time), i.e. the model output drives both charging and budgeting
- the same ratio holds across four hosts (local disk, enterprise NVMe, NVMe-backed root on an idle k8s master, and a real 7.3T HDD behind a loaded host) and across 4k/64k/1M block sizes: 2.00-2.03x on the flash-backed hosts, and within 2% of 2x on the real HDD, where the host load adds variance
- edge cases: ctrl=bpf without a registered model is rejected; a second registration fails with EBUSY; unregistering the model or returning 0 (delegation) both fall back to the builtin price; a model using a map keyed by iocg_id records distinct ids per cgroup
- iocost_ioc_tick fires every period in steady state and emits one final tick with running=0 before the controller goes idle
Payoff, demonstrated with the multi-stream example model (7/8) on the same setup, 4k IOs at weight 1000, builtin vs the model:
- two sequential readers in one cgroup: priced 2064us/op by builtin (both judged random by the single cursor) and 23us/op by the model (each stream keeps its own slot), a throughput recovery from 7.2 to 511 MiB/s
- random IO inside an 8M window: priced 22.9us/op by builtin (undercharge, an accounting escape) and 2643us/op by the model
- single-stream sequential and whole-disk random pricing are unchanged, so the model fixes both directions of mispricing without introducing a new one
Non-interference, measured on enterprise NVMe (MEMBLAZE P6541, passthrough to KVM guest, 8 proc x 128k sequential read, 7.5M aggregate IOPS):
- no measurable overhead when not in use: builtin vs BPF-patched kernel (no model registered) within noise (30180 vs 30314 ops/proc); the one indirect call per bio is not measurable at this rate
- 12-hour stress (870 iterations, 3 cgroups at 1000/100/10 weights, read + write + flush concurrent, 87 iocost disable/enable cycles, 870 model switches): zero errors, zero memory drift (0.03% over 32GB)
Open questions for discussion:
1. Interface: scalar args (as here) vs passing struct bio * for CO-RE access? Is a cold-path model_refresh() callback needed so models can track vrate?
2. Per-cgroup state lifetime: iocg_id is the css id and is recycled once the cgroup is removed, so models must treat it as a transient key. Does the interface need a release(iocg_id) callback so models can clean up per-cgroup state instead of detecting reuse, or is per-cgroup bpf local storage, which carries its own lifetime, the better home for model state?
3. Request-level asymmetry: the request-based sizing path (calc_size_vtime_cost, which feeds the latency QoS met/missed decision) still uses the builtin formula when a model is registered, while bio charging goes through the model. Should the request path dispatch too, or is builtin sizing with a BPF charge model acceptable?
4. One model system-wide vs named models selectable per device (as tcp-cc names are per-socket)?
Tao Cui (8):
blk-iocost: add iocost_ioc_tick tracepoint for per-period device
summary
blk-iocost: define iocost_model_ops cost model interface
blk-iocost: implement BPF struct_ops registration
blk-iocost: dispatch cost calculation to registered BPF model
blk-iocost: add ctrl=bpf per-device opt-in selftests/bpf: add iocost cost model test selftests/bpf: add multi-stream sequentiality example model
docs: cgroup-v2: document io.cost ctrl=bpf option
Documentation/admin-guide/cgroup-v2.rst | 16 +- block/Kconfig | 9 + block/Makefile | 1 + block/blk-iocost-bpf.c | 152 +++++++++++++++++ block/blk-iocost.c | 46 +++++- include/linux/blk-iocost.h | 56 +++++++ include/trace/events/iocost.h | 40 +++++ .../selftests/bpf/prog_tests/iocost_model.c | 155 ++++++++++++++++++ .../selftests/bpf/progs/iocost_model.c | 91 ++++++++++ tools/testing/selftests/bpf/progs/iocost_ms.c | 122 ++++++++++++++ 10 files changed, 682 insertions(+), 6 deletions(-) create mode 100644 block/blk-iocost-bpf.c create mode 100644 include/linux/blk-iocost.h 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
Signature · 1 line
2.43.0
RFC PATCH 1/8 blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary
From: Tao Cui <[email protected]>
The existing iocost tracepoints are state-change driven: vrate_adj fires only when the adjustment logic runs, inuse_* only on surplus state transitions, activate/idle only on cgroup state changes. In a steady state none of them fire. The only other way to observe the controller (period length, vrate, busy level, active cgroup count, device utilization) is iocost_monitor.py, which reads kernel memory through drgn and is not usable in most production environments.
Add iocost_ioc_tick, emitted once per period from the tail of ioc_timer_fn() with the overall controller state: period_us, vrate, busy_level, active iocg count, usage percentage and running state. It fires every period the controller runs, including steady states, plus one final tick before the controller goes idle, which makes dormancy (e.g. a device saturated entirely by uncharged IO) directly visible.
At the default period this is a couple of events per second per device; the cost is zero while the static key is off.
--- block/blk-iocost.c | 5 +++++ include/trace/events/iocost.h | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
block/blk-iocost.c +5 -0
@@ -2238,6 +2238,7 @@ static void ioc_timer_fn(struct timer_list *timer)struct ioc_now now;LIST_HEAD (surpluses);int nr_debtors, nr_shortages =0 , nr_lagging =0 ; +int nr_active =0 ;u64 usage_us_sum =0 ;u32 ppm_rthr;u32 ppm_wthr;
@@ -2274,6 +2275,8 @@ static void ioc_timer_fn(struct timer_list *timer)u64 vdone, vtime, usage_us;u32 hw_active, hw_inuse; + nr_active++; +/* * Collect unused and wind vtime closer to vnow to prevent * iocgs from accumulating a large amount of budget.
@@ -2460,6 +2463,8 @@ static void ioc_timer_fn(struct timer_list *timer)ioc_refresh_vrate (ioc, &now); } +trace_iocost_ioc_tick (ioc, nr_active, usage_us_sum); +spin_unlock_irq (&ioc->lock); }
include/trace/events/iocost.h +40 -0
@@ -178,6 +178,46 @@ TRACE_EVENT(iocost_ioc_vrate_adj, ) ); +/* +* Periodic per-device summary, emitted once per period from the tail of +* ioc_timer_fn(). Unlike the state-change events above, this fires every +* period the controller is running, including steady states, and carries +* the overall controller state so basic monitoring doesn't require drgn. +*/ +TRACE_EVENT (iocost_ioc_tick, + + TP_PROTO(struct ioc *ioc, int nr_active, u64 usage_us_sum), + +TP_ARGS (ioc, nr_active, usage_us_sum), + +TP_STRUCT__entry ( + __string(devname, ioc_name(ioc)) + __field(u32, period_us) + __field(u64, vrate) + __field(int, busy_level) + __field(int, nr_active) + __field(u32, usage_pct) +__field (int, running) + ), + +TP_fast_assign ( + __assign_str(devname); + __entry->period_us = ioc->period_us; + __entry->vrate = ioc->vtime_base_rate; + __entry->busy_level = ioc->busy_level; + __entry->nr_active = nr_active; + __entry->usage_pct = ioc->period_us ? + div_u64(usage_us_sum * 100, ioc->period_us) : 0; + __entry->running = ioc->running; + ), + +TP_printk ("[%s] period=%uus vrate=%llu busy=%d active=%d usage=%u%% running=%d" , +__get_str (devname), __entry->period_us, __entry->vrate, + __entry->busy_level, __entry->nr_active, __entry->usage_pct, + __entry->running + ) +); + TRACE_EVENT(iocost_iocg_forgive_debt, TP_PROTO(struct ioc_gq *iocg, const char *path, struct ioc_now *now,
Signature · 1 line
2.43.0
RFC PATCH 2/8 blk-iocost: define iocost_model_ops cost model interface
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Define the interface for pluggable cost models: a struct_ops with a single calc_cost(op, nbytes, sector, cursor, iocg_id, flags) callback taking scalar arguments only. The return value is vtime (2^37 per second of device time), clamped to 1s per IO by the kernel. A return value of 0 delegates the IO back to the builtin formula, so a model which only handles some IO types cannot make the rest free.
iocg_id is the id of the issuing cgroup, so a model can keep per-cgroup state, e.g. for multi-stream sequentiality detection. The id is only valid while the cgroup exists and is recycled after removal, so models must treat it as a transient key; struct_ops callback signatures are frozen once merged, so the identifier is part of the initial interface.
The model is called from the IO submission path under RCU and must not sleep. Only the bio-level charging path consults the model; the request-level sizing path keeps using the builtin formula.
This is a definition-only patch; the registration infrastructure and dispatch hook follow in subsequent patches.
--- block/Kconfig | 9 ++++++ include/linux/blk-iocost.h | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 include/linux/blk-iocost.h
block/Kconfig +9 -0
@@ -231,4 +231,13 @@ config BLK_ERROR_INJECTION source "block/Kconfig.iosched" +config BLK_CGROUP_IOCOST_BPF + bool "Enable BPF pluggable cost model support for the cost IO controller" + depends on BLK_CGROUP_IOCOST && BPF_SYSCALL && BPF_JIT + help + Enabling this option registers the "iocost_model_ops" BPF + struct_ops type, which allows a BPF program to replace the + builtin linear cost model on devices configured with + "ctrl=bpf" through io.cost.model. + endif # BLOCK
include/linux/blk-iocost.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH 2/8] blk-iocost: define iocost_model_ops cost model interface
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The `iocost_model_ops` interface uses recycled cgroup IDs (`iocg_id`) without a lifecycle callback…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The iocost_model_ops interface uses recycled cgroup IDs (iocg_id) without a lifecycle callback (e.g., release), making safe per-cgroup state management impossible.
- [Low] Incorrect header reference in BPF struct_ops documentation.
--
commit 64a8ffdba67eaf906639412faa34e6125d2960c1
Author: Tao Cui <[email protected]>
blk-iocost: define iocost_model_ops cost model interface
This commit defines the interface for pluggable cost models via a struct_ops with a single calc_cost callback. It passes iocg_id to allow models to keep per-cgroup state. The model is called from the IO submission path under RCU.
Quoted 6 lines
include/linux/blk-iocost.h new file +0
-0@@ -0,0 +1,56 @@
[ ... ]
include/linux/blk-iocost.h line 40
Quoted 3 lines
include/linux/blk-iocost.h new file +3
-0+struct iocost_model_ops { +/* +* @op: REQ_OP_* value (uapi blk_opf.h)
[Severity: Low]
Is this the correct header reference?
The file blk_opf.h does not exist in uapi. Should this point to include/linux/blk_types.h instead?
include/linux/blk-iocost.h line 49
Quoted 9 lines
include/linux/blk-iocost.h new file +9
-0+* @nbytes: IO size in bytes +* @sector: starting sector +* @cursor: iocg cursor sector, 0 if none (sequentiality hint) +* @iocg_id: css id of the issuing cgroup +* @flags: IOCOST_COST_F_* +*/ +u64 (*calc_cost)(u64 op,u64 nbytes,u64 sector,u64 cursor, +u64 iocg_id,u64 flags); +};
[Severity: High]
Does this struct_ops interface need a release or offline callback for cgroup state cleanup?
When a cgroup is deleted and its CSS ID is recycled, the new cgroup inherits the historical IO state of the deleted cgroup if the BPF model tracks it. There is no reliable way for the BPF program to garbage collect entries, which can eventually exhaust map space.
Could unprivileged users with cgroup delegation create and destroy cgroups, triggering map exhaustion and causing a denial of service for the cost model (which falls back to failure or builtin behavior once max_entries is reached)?
The commit message notes that the need for a release(iocg_id) callback is an open question. Since BPF struct_ops signatures are frozen once merged, is it safe to omit it from the initial interface? This appears to be confirmed in a follow-up patch where map entries have no deletion logic and will leak in a production environment.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Tejun Heo
maintainerRe: [RFC PATCH 2/8] blk-iocost: define iocost_model_ops cost model interface
In reply to Tao CuiHello, Tao.
block/Kconfig config BLK_ERROR_INJECTION · line 236
Quoted 3 lines · Tao Cui
block/Kconfig +3
-0+config BLK_CGROUP_IOCOST_BPF + bool "Enable BPF pluggable cost model support for the cost IO controller" + depends on BLK_CGROUP_IOCOST && BPF_SYSCALL && BPF_JIT
This also needs a dependency on DEBUG_INFO_BTF. Otherwise the option can be enabled without the BTF required to register iocost_model_ops.
Thanks.
Signature · 1 line
tejun
RFC PATCH 3/8 blk-iocost: implement BPF struct_ops registration
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Register the iocost_model_ops struct_ops type: at most one model system-wide (EBUSY otherwise), called under RCU from the submit/merge path. Registration and unregistration are serialized with a mutex because the caller only holds the per-map lock. Includes the verifier ops, CFI stubs and late_initcall registration. A model returning 0 makes the caller fall back to the builtin formula, which keeps a partial model from making the IO types it does not handle free.
The verifier allows the base helper set, so models can use maps for per-cgroup state keyed by iocg_id. The model runs in the submit path under RCU and must not sleep.
No code calls the registered model yet; the dispatch hook follows.
--- block/Makefile | 1 + block/blk-iocost-bpf.c | 152 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 block/blk-iocost-bpf.c
block/Makefile +1 -0
@@ -39,3 +39,4 @@ obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += blk-crypto.o blk-crypto-profile.o \ blk-crypto-sysfs.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o obj-$(CONFIG_BLOCK_HOLDER_DEPRECATED) += holder.o +obj-$(CONFIG_BLK_CGROUP_IOCOST_BPF) += blk-iocost-bpf.o
block/blk-iocost-bpf.c new file +152 -0
152 lines not on this page · raw message
Signature · 1 line
2.43.0
Tejun Heo
maintainerRe: [RFC PATCH 3/8] blk-iocost: implement BPF struct_ops registration
Hello, Tao.
block/blk-iocost-bpf.c line 140
Quoted 4 lines · Tao Cui
block/blk-iocost-bpf.c new file +4
-0+static struct bpf_struct_ops bpf_iocost_model_ops = { + .verifier_ops = &bpf_iocost_verifier_ops, + .init = bpf_iocost_model_init, + .init_member = bpf_iocost_init_member,
Please add a .check_member callback rejecting sleepable programs. The generic verifier permits sleepable struct_ops programs, so a model can currently call bpf_copy_from_user() while iocost_bpf_calc_cost() holds rcu_read_lock().
Thanks.
Signature · 1 line
tejun
RFC PATCH 4/8 blk-iocost: dispatch cost calculation to registered BPF model
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Add the bpf_cost_model field to struct ioc and the dispatch hook in calc_vtime_cost(): when a BPF model is registered and the device has opted in (bpf_cost_model set), call the model's calc_cost instead of the builtin formula. If no model is registered anymore the builtin formula is used as fallback.
The user interface to set bpf_cost_model follows.
--- block/blk-iocost.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
block/blk-iocost.c +19 -0
@@ -177,6 +177,7 @@#include <linux/timer.h> #include <linux/time64.h> #include <linux/parser.h> +#include <linux/blk-iocost.h> #include <linux/sched/signal.h> #include <asm/local.h> #include <asm/local64.h>
@@ -445,6 +446,7 @@ struct ioc {int autop_idx; bool user_qos_params:1; bool user_cost_model:1; +bool bpf_cost_model; };struct iocg_pcpu_stat {
@@ -2578,6 +2580,23 @@ static u64 calc_vtime_cost(struct bio *bio, struct ioc_gq *iocg, bool is_merge) {u64 cost; +#ifdef CONFIG_BLK_CGROUP_IOCOST_BPF +struct ioc *ioc = iocg->ioc; + +if (READ_ONCE (ioc->bpf_cost_model)) { +u64 bpf_cost; + +if (iocost_bpf_calc_cost (bio_op (bio), + bio->bi_iter.bi_size, + bio->bi_iter.bi_sector, + iocg->cursor, +iocg_to_blkg (iocg)->blkcg->css.id, + is_merge ?IOCOST_COST_F_MERGE :0 , + &bpf_cost)) +return bpf_cost; + } +#endif +calc_vtime_cost_builtin (bio, iocg, is_merge, &cost);return cost; }
Signature · 1 line
2.43.0
Tejun Heo
maintainerRe: [RFC PATCH 4/8] blk-iocost: dispatch cost calculation to registered BPF model
Hello, Tao.
block/blk-iocost.c static u64 calc_vtime_cost(struct bio *bio, struct ioc_gq *iocg, bool is_merge) · line 2594
Quoted 6 lines · Tao Cui
block/blk-iocost.c +6
-0+ if (iocost_bpf_calc_cost(bio_op(bio), + bio->bi_iter.bi_size, + bio->bi_iter.bi_sector, + iocg->cursor, + iocg_to_blkg(iocg)->blkcg->css.id, + is_merge ? IOCOST_COST_F_MERGE : 0,
bio_op() drops REQ_PREFLUSH and REQ_FUA, and the flags argument only carries merge status. Please preserve the operation flags.
Thanks.
Signature · 1 line
tejun
RFC PATCH 5/8 blk-iocost: add ctrl=bpf per-device opt-in
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Add "bpf" to the ctrl= options in io.cost.model. Writing "$dev ctrl=bpf" to io.cost.model switches the device to the registered BPF cost model (if any is registered); ctrl=auto or ctrl=user switches back to the builtin model.
--- block/blk-iocost.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
block/blk-iocost.c +17 -5
@@ -3465,7 +3465,8 @@ static u64 ioc_cost_model_prfill(struct seq_file *sf,seq_printf (sf,"%s ctrl=%s model=linear " "rbps=%llu rseqiops=%llu rrandiops=%llu " "wbps=%llu wseqiops=%llu wrandiops=%llu\n" , - dname, ioc->user_cost_model ?"user" :"auto" , + dname, ioc->bpf_cost_model ?"bpf" : + ioc->user_cost_model ?"user" :"auto" , u[I_LCOEF_RBPS ], u[I_LCOEF_RSEQIOPS ], u[I_LCOEF_RRANDIOPS ], u[I_LCOEF_WBPS ], u[I_LCOEF_WSEQIOPS ], u[I_LCOEF_WRANDIOPS ]);spin_unlock_irq (&ioc->lock);
@@ -3505,7 +3506,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,unsigned int memflags;struct ioc *ioc;u64 u[NR_I_LCOEFS ]; -bool user; +bool user, bpf;char *body, *p;int ret;
@@ -3536,6 +3537,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,spin_lock_irq (&ioc->lock);memcpy (u, ioc->params.i_lcoefs,sizeof (u)); user = ioc->user_cost_model; + bpf = ioc->bpf_cost_model; ret = -EINVAL ;
@@ -3551,11 +3553,20 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,switch (match_token (p, cost_ctrl_tokens, args)) {case COST_CTRL :match_strlcpy (buf, &args[0 ],sizeof (buf)); -if (!strcmp (buf,"auto" )) +if (!strcmp (buf,"auto" )) { user = false; -else if (!strcmp (buf,"user" )) + bpf = false; + }else if (!strcmp (buf,"user" )) { user = true; -else + bpf = false; +#ifdef CONFIG_BLK_CGROUP_IOCOST_BPF + }else if (!strcmp (buf,"bpf" )) { +if (!iocost_bpf_model_registered ()) + goto unlock; + user = false; + bpf = true; +#endif + }else goto unlock;continue ;case COST_MODEL :
@@ -3580,6 +3591,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, }else { ioc->user_cost_model = false; } +WRITE_ONCE (ioc->bpf_cost_model, bpf);ioc_refresh_params (ioc, true); ret =0 ;
Signature · 1 line
2.43.0
RFC PATCH 6/8 selftests/bpf: add iocost cost model test
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Add an example cost model implementing iocost_model_ops with the builtin linear HDD formula at double cost, and a runner which registers it as a struct_ops, switches a device to ctrl=bpf through io.cost.model and verifies the readback, restoring ctrl=auto afterwards. The runner first checks the negative case: writing ctrl=bpf while no model is registered is rejected. Under the same workload the doubled model should charge exactly twice the builtin model, which makes it a convenient way to verify that accounting goes through the BPF path; the accounting itself needs real IO and is covered by the kernel-side validation described in the cover letter. The runner is skipped unless $IOCOST_TEST_DEV gives a major:minor of a device with iocost enabled.
--- .../selftests/bpf/prog_tests/iocost_model.c | 124 ++++++++++++++++++ .../selftests/bpf/progs/iocost_model.c | 91 +++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/iocost_model.c create mode 100644 tools/testing/selftests/bpf/progs/iocost_model.c
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +124 -0
@@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2026 Tao Cui */ +#include <test_progs.h> +#include "iocost_model.skel.h" + +/* +* Switch a device to ctrl=bpf through io.cost.model and verify the +* readback, restoring ctrl=auto afterwards. Returns 0 on success. +* Shared by the example-model tests below. +*/ +static int switch_to_bpf (const char *dev) +{ +char path[] ="/sys/fs/cgroup/io.cost.model" ; +char word[256 ], line[256 ], buf[300 ]; +FILE *fp; +int err, found =0 ; + + fp =fopen (path,"r+" ); +if (!fp) { +TH_LOG ("open %s: %s" , path,strerror (errno)); +return -1 ; + } + +while (fgets (line,sizeof (line), fp)) { +if (sscanf (line,"%255s" , word) ==1 && !strcmp (word, dev)) { + found =1 ; +break ; + } + } +if (!found) { +TH_LOG ("%s has no iocost line" , dev); +fclose (fp); +return -1 ; + } + +snprintf (buf,sizeof (buf),"%s ctrl=bpf" , dev); + err =fprintf (fp,"%s\n" , buf); +if (err <=0 ) { +TH_LOG ("write ctrl=bpf failed" ); +fclose (fp); +return -1 ; + } +fflush (fp); + +rewind (fp); + found =0 ; +while (fgets (line,sizeof (line), fp)) { +if (sscanf (line,"%255s" , word) ==1 && !strcmp (word, dev)) { + found =strstr (line,"ctrl=bpf" ) !=NULL ; +break ; + } + } +if (!found) +TH_LOG ("readback does not show ctrl=bpf" ); + +fprintf (fp,"%s ctrl=auto\n" , dev); +fclose (fp); +return found ?0 :-1 ; +} + +static int dev_has_iocost (void ) +{ +FILE *fp =fopen ("/sys/fs/cgroup/io.cost.qos" ,"r" ); + +if (fp) +fclose (fp); +return fp !=NULL ; +} + +/* +* Register the example cost model and switch a device to ctrl=bpf. +* IO accounting itself is not checked here; it needs a device doing +* real IO under iocost and is covered by the kernel-side validation +* described in the cover letter. +* +* Requires root, cgroup v2 and a device with iocost support. The +* device must be given as major:minor in $IOCOST_TEST_DEV, otherwise +* the test is skipped. +*/ +void serial_test_iocost_model (void ) +{ +struct iocost_model *skel; +char word[256 ], *dev; +int err; + + dev =getenv ("IOCOST_TEST_DEV" ); +if (!dev ||geteuid () !=0 ) { +test__skip (); +return ; + } +if (!ASSERT_TRUE (dev_has_iocost (),"iocost_mounted" )) +return ; + +/* negative: ctrl=bpf must be rejected while no model is +* registered, so a typo cannot silently disable cost model +* updates */ +if (sscanf (dev,"%255s" , word) !=1 ) +return ; + { +char path[] ="/sys/fs/cgroup/io.cost.model" ; +char buf[300 ]; +FILE *fp =fopen (path,"w" ); + +snprintf (buf,sizeof (buf),"%s ctrl=bpf\n" , word); + err =0 ; +if (fp) { + err =fprintf (fp,"%s" , buf) <=0 ; +fclose (fp); + } +ASSERT_TRUE (err,"ctrl_bpf_without_model_rejected" ); + } + + skel =iocost_model__open_and_load (); +if (!ASSERT_OK_PTR (skel,"skel_open_load" )) +return ; + +/* attaching the struct_ops registers the model; a second +* registration of the same ops would fail with EBUSY */ + err =iocost_model__attach (skel); +if (ASSERT_OK (err,"attach" )) +ASSERT_OK (switch_to_bpf (dev),"switch_and_readback" ); + +iocost_model__destroy (skel); +}
tools/testing/selftests/bpf/progs/iocost_model.c new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH 6/8] selftests/bpf: add iocost cost model test
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] The negative test case incorrectly checks the return value of `fprintf` instead of `fclose` or…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] The negative test case incorrectly checks the return value of fprintf instead of fclose or fflush, causing the test to assert the wrong condition and spuriously fail.
- [Medium] Interleaved input and output on the same stream in update mode without an intervening file positioning function causes undefined behavior.
- [Low] Several multi-line comments do not follow the mandatory BPF subsystem multi-line comment style.
--
commit 312862fd426ea5bb64f752670a814d2e20308af1
Author: Tao Cui <[email protected]>
selftests/bpf: add iocost cost model test
This commit adds an example cost model implementing iocost_model_ops and a runner that registers it as a struct_ops. The runner verifies readback and ensures that writing to the cost model is properly rejected if no model is registered.
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +0
-0@@ -0,0 +1,124 @@
[ ... ]
Quoted 17 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +17
-0+static int switch_to_bpf (const char *dev) +{ +char path[] ="/sys/fs/cgroup/io.cost.model" ; +char word[256 ], line[256 ], buf[300 ]; +FILE *fp; +int err, found =0 ; + + fp =fopen (path,"r+" ); +if (!fp) { +TH_LOG ("open %s: %s" , path,strerror (errno)); +return -1 ; + } + +while (fgets (line,sizeof (line), fp)) { +if (sscanf (line,"%255s" , word) ==1 && !strcmp (word, dev)) { + found =1 ; +break ;
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 37
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +10
-0+ } + } +if (!found) { +TH_LOG ("%s has no iocost line" , dev); +fclose (fp); +return -1 ; + } + +snprintf (buf,sizeof (buf),"%s ctrl=bpf" , dev); + err =fprintf (fp,"%s\n" , buf);
[Severity: Medium]
Is an intervening file positioning function like fseek() or fflush() needed here before calling fprintf()?
The C11 standard mandates an intervening call to a file positioning function or fflush() between reading and writing when a stream is opened in update mode ("r+"). Without it, stream buffer pointers can become corrupted, causing the write to fail, be dropped, or write at an incorrect offset.
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +9
-0+if (err <=0 ) { +TH_LOG ("write ctrl=bpf failed" ); +fclose (fp); +return -1 ; + } +fflush (fp); + +rewind (fp); + found =0 ;
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 56
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +10
-0+while (fgets (line,sizeof (line), fp)) { +if (sscanf (line,"%255s" , word) ==1 && !strcmp (word, dev)) { + found =strstr (line,"ctrl=bpf" ) !=NULL ; +break ; + } + } +if (!found) +TH_LOG ("readback does not show ctrl=bpf" ); + +fprintf (fp,"%s ctrl=auto\n" , dev);
[Severity: Medium]
Similarly, is an fseek() or fflush() needed here between the fgets() read loop and this fprintf() write to avoid undefined behavior?
Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +3
-0+fclose (fp); +return found ?0 :-1 ; +}
[ ... ]
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +7
-0+void serial_test_iocost_model (void ) +{ +struct iocost_model *skel; +char word[256 ], *dev; +int err; + + dev =getenv ("IOCOST_TEST_DEV" );
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 96
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +10
-0+if (!dev ||geteuid () !=0 ) { +test__skip (); +return ; + } +if (!ASSERT_TRUE (dev_has_iocost (),"iocost_mounted" )) +return ; + +/* negative: ctrl=bpf must be rejected while no model is +* registered, so a typo cannot silently disable cost model +* updates */
[Severity: Low]
This isn't a bug, but does this violate the BPF subsystem multi-line comment style?
The BPF guidelines specify that the opening /* should be on its own line:
/*
* negative: ctrl=bpf must be rejected while no model is
* registered...
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +4
-0+if (sscanf (dev,"%255s" , word) !=1 ) +return ; + { +char path[] ="/sys/fs/cgroup/io.cost.model" ;
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 110
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +10
-0+char buf[300 ]; +FILE *fp =fopen (path,"w" ); + +snprintf (buf,sizeof (buf),"%s ctrl=bpf\n" , word); + err =0 ; +if (fp) { + err =fprintf (fp,"%s" , buf) <=0 ; +fclose (fp); + } +ASSERT_TRUE (err,"ctrl_bpf_without_model_rejected" );
[Severity: Medium]
Should this error check evaluate the return value of fclose() or fflush() instead of fprintf()?
Since fopen() on cgroupfs files defaults to full buffering, fprintf() will merely copy data to the userspace buffer and return success. The actual rejection from the kernel (-EINVAL) occurs during the write() syscall triggered by fclose(). Checking fprintf() here might cause the test to assert the wrong condition and spuriously fail.
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 118
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +8
-0+ } + + skel =iocost_model__open_and_load (); +if (!ASSERT_OK_PTR (skel,"skel_open_load" )) +return ; + +/* attaching the struct_ops registers the model; a second +* registration of the same ops would fail with EBUSY */
[Severity: Low]
This isn't a bug, but this comment also doesn't follow the preferred BPF multi-line comment format where the /* sits on its own line.
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +6
-0+ err =iocost_model__attach (skel); +if (ASSERT_OK (err,"attach" )) +ASSERT_OK (switch_to_bpf (dev),"switch_and_readback" ); + +iocost_model__destroy (skel); +}tools/testing/selftests/bpf/progs/iocost_model.c new file +0
-0@@ -0,0 +1,91 @@
[ ... ]
tools/testing/selftests/bpf/progs/iocost_model.c line 27
Quoted 7 lines
tools/testing/selftests/bpf/progs/iocost_model.c new file +7
-0+#define IOC_PAGE_SIZE 4096 +#define IOC_SECT_TO_PAGE_SHIFT 3/* 512B sectors to 4kB pages */ +#define LCOEF_RANDIO_PAGES 4096/* 16MB seek threshold */ +#define IOCOST_COST_F_MERGE (1ULL << 0)/* not in BTF: a plain macro */ + +/* DIV64_U64_ROUND_UP / DIV_ROUND_UP_ULL equivalents, folded at +* compile time */
[Severity: Low]
This isn't a bug, but this multi-line comment has the opening /* on the same line as the text, which isn't the preferred style for the BPF subsystem.
Quoted 4 lines
tools/testing/selftests/bpf/progs/iocost_model.c new file +4
-0+#define RU (x, y) ((x) / (y) + (((x) % (y)) ? 1 : 0)) + +#define RBPS 174019176ULL +#define RSEQIOPS 41708ULL
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Tejun Heo
maintainerRe: [RFC PATCH 6/8] selftests/bpf: add iocost cost model test
In reply to Tao CuiHello, Tao.
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 20
Quoted 1 line · Tao Cui
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +1
-0+TH_LOG ("open %s: %s" , path,strerror (errno));
TH_LOG is not available through test_progs.h. A syntax check of the posted runner fails here. Please use the test_progs logging facilities.
Quoted 1 line
+#include "
iocost_model.skel.h"
The selftest kernel config also needs CONFIG_BLK_CGROUP_IOCOST and CONFIG_BLK_CGROUP_IOCOST_BPF so vmlinux.h contains iocost_model_ops. The runtime skip cannot avoid that build dependency.
tools/testing/selftests/bpf/prog_tests/iocost_model.c line 108
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/iocost_model.c new file +2
-0+ err =fprintf (fp,"%s" , buf) <=0 ; +fclose (fp);
fprintf() can succeed while the buffered write is rejected at fclose(), whose result is ignored. Check the actual write result and expected errno. Please also check the flush and restoration errors in switch_to_bpf().
Thanks.
Signature · 1 line
tejun
RFC PATCH 7/8 selftests/bpf: add multi-stream sequentiality example model
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Add a second example cost model which replaces the builtin single-cursor sequentiality heuristic with a per-cgroup table of stream slots keyed by iocg_id: an IO is sequential iff its sector matches the expected next sector of any tracked stream. Interleaved sequential readers in one cgroup keep their own slots instead of ping-ponging a single cursor, and random IO inside a hot window rarely matches a moving expectation.
Measured (QEMU, virtio-blk with the HDD profile, 4k IOs, w=1000):
two sequential readers in one cgroup are priced 2064us/op by the builtin model (judged random) and 23us/op by this model (judged sequential), a throughput recovery from 7.2 to 511 MiB/s; random IO inside an 8M window is priced 22.9us/op by builtin (undercharge) and 2643us/op by this model; single-stream sequential and whole-disk random pricing are unchanged.
The runner reuses the switch helper from the first example model.
--- .../selftests/bpf/prog_tests/iocost_model.c | 31 +++++ tools/testing/selftests/bpf/progs/iocost_ms.c | 122 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/iocost_ms.c
tools/testing/selftests/bpf/prog_tests/iocost_model.c +31 -0
@@ -2,6 +2,7 @@/* Copyright (c) 2026 Tao Cui */ #include <test_progs.h> #include "iocost_model.skel.h" +#include "iocost_ms.skel.h" /* * Switch a device to ctrl=bpf through io.cost.model and verify the
@@ -122,3 +123,33 @@ void serial_test_iocost_model(void)iocost_model__destroy (skel); } + +/* +* Same check for the multi-stream example model. Only one model can +* be registered at a time, so this test must run separately from +* test_iocost_model; both are serial. +*/ +void serial_test_iocost_model_streams (void ) +{ +struct iocost_ms *skel; +char *dev; +int err; + + dev =getenv ("IOCOST_TEST_DEV" ); +if (!dev ||geteuid () !=0 ) { +test__skip (); +return ; + } +if (!ASSERT_TRUE (dev_has_iocost (),"iocost_mounted" )) +return ; + + skel =iocost_ms__open_and_load (); +if (!ASSERT_OK_PTR (skel,"skel_open_load" )) +return ; + + err =iocost_ms__attach (skel); +if (ASSERT_OK (err,"attach" )) +ASSERT_OK (switch_to_bpf (dev),"switch_and_readback" ); + +iocost_ms__destroy (skel); +}
tools/testing/selftests/bpf/progs/iocost_ms.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [RFC PATCH 7/8] selftests/bpf: add multi-stream sequentiality example model
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Multi-line comment does not follow the required BPF subsystem comment style, starting on the same…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Multi-line comment does not follow the required BPF subsystem comment style, starting on the same line as the opening '/*'. --
commit d8df4bd81fa04615013e2f2662dbdb807cb8794c
Author: Tao Cui <[email protected]>
selftests/bpf: add multi-stream sequentiality example model
This commit adds a second example cost model which replaces the single-cursor sequentiality heuristic with a per-cgroup table of stream slots keyed by iocg_id. This improves pricing accuracy for interleaved sequential readers and windowed random IO.
Quoted 5 lines
tools/testing/selftests/bpf/progs/iocost_ms.c new file +0
-0
[ ... ]
tools/testing/selftests/bpf/progs/iocost_ms.c line 26
Quoted 6 lines
tools/testing/selftests/bpf/progs/iocost_ms.c new file +6
-0+/* VTIME_PER_SEC comes from vmlinux.h (a BTF enum constant) */ +#define IOC_PAGE_SIZE 4096 +#define IOCOST_COST_F_MERGE (1ULL << 0)/* not in BTF: a plain macro */ + +/* DIV64_U64_ROUND_UP / DIV_ROUND_UP_ULL equivalents, folded at +* compile time */
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the preferred kernel comment style for the BPF subsystem? The BPF guidelines specify that multi-line comments must have the opening /* on its own line, rather than starting the text on the same line as the opening marker.
Quoted 3 lines
tools/testing/selftests/bpf/progs/iocost_ms.c new file +3
-0+#define RU (x, y) ((x) / (y) + (((x) % (y)) ? 1 : 0)) + +#define RBPS 174019176ULL
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Tejun Heo
maintainerRe: [RFC PATCH 7/8] selftests/bpf: add multi-stream sequentiality example model
In reply to Tao CuiHello, Tao.
tools/testing/selftests/bpf/progs/iocost_ms.c line 90
Quoted 3 lines · Tao Cui
tools/testing/selftests/bpf/progs/iocost_ms.c new file +3
-0+if (flags &IOCOST_COST_F_MERGE ) { + base =0 ; + goto out;
Please advance the stream position for merged bios too. With 4K IOs, a new request at sector S sets expected to S+8. A merged bio at S+8 leaves it there, so the next new request at S+16 is priced random.
tools/testing/selftests/bpf/progs/iocost_ms.c line 85
Quoted 3 lines
tools/testing/selftests/bpf/progs/iocost_ms.c new file +3
-0+ s =bpf_map_lookup_elem (&stream_tab, &iocg_id); +if (!s) +return seqio +RU (nbytes,IOC_PAGE_SIZE ) * page;
Once the 64-entry map fills, every new cgroup receives sequential prices, including for random IO. Please note this limitation in the example.
Thanks.
Signature · 1 line
tejun
RFC PATCH 8/8 docs: cgroup-v2: document io.cost ctrl=bpf option
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Document the "bpf" value of the ctrl key of io.cost.model and the iocost_model_ops struct_ops it selects, in the io.cost.model section of the cgroup v2 documentation: the registration precondition and single-instance limit, the scalar arguments, the vtime clamp and the delegation-to-builtin semantics of a zero return value.
--- Documentation/admin-guide/cgroup-v2.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
Documentation/admin-guide/cgroup-v2.rst +15 -1
@@ -2115,10 +2115,24 @@ IO Interface Files are defined. ===== ================================ - ctrl "auto" or "user" + ctrl "auto", "user" or "bpf" model The cost model in use - "linear" ===== ================================ + When "ctrl" is "bpf" (only available when + CONFIG_BLK_CGROUP_IOCOST_BPF is enabled), cost calculation for + the device is dispatched to the BPF program registered against + the iocost_model_ops struct_ops. Writing "bpf" fails with -EINVAL + until such a program is registered, and at most one program can + be registered system-wide. The model is called with scalar + arguments (operation, size, sector, cgroup cursor, css id of the + issuing cgroup, flags; see include/linux/blk-iocost.h for their + meaning) and returns a cost in vtime units, clamped by the kernel + to 1 second of device time per IO. A return value of 0 delegates + the IO back to the builtin linear formula, so a model which only + handles some IO types cannot make the rest free. Devices which + don't opt in keep the builtin linear model unchanged. + When "ctrl" is "auto", the kernel may change all parameters dynamically. When "ctrl" is set to "user" or any other parameters are written to, "ctrl" become "user" and the
Signature · 1 line
2.43.0
Tejun Heo
maintainerHello, Tao.
Quoted 2 lines · Tao Cui
4. One model system-wide vs named models selectable per device (as tcp-cc names are per-socket)?
The struct_ops instance should be per-device. Loading a model for a device should switch it to BPF automatically. Switching back to the builtin model should detach the struct_ops.
Quoted 6 lines
2. Per-cgroup state lifetime:
iocg_idis the css id and is recycled once the cgroup is removed, so models must treat it as a transient key. Does the interface need arelease(iocg_id)callback so models can clean up per-cgroup state instead of detecting reuse, or is per-cgroup bpf local storage, which carries its own lifetime, the better home for model state?
I'd pass blkcg as a kptr and add online/offline callbacks so the model can manage its per-cgroup state.
Quoted 2 lines
return value of 0 delegates the IO back to the builtin formula, so a model which only handles some IO types cannot make the rest free.
I don't think mixing BPF and builtin pricing makes sense, either per IO or between charging and request sizing. It seems convoluted and error-prone. Implementing the linear model in BPF is straightforward.
Please combine the interface, registration, dispatch and configuration changes into one patch. These patches are small and implement one feature.
Thanks.
Signature · 1 line
tejun
Hello, Tejun
Quoted 24 lines · Tejun Heo
Hello, Tao.
Quoted 2 lines · Tao Cui
4. One model system-wide vs named models selectable per device (as tcp-cc names are per-socket)?
The
struct_opsinstance should be per-device. Loading a model for a device should switch it to BPF automatically. Switching back to the builtin model should detach thestruct_ops.Quoted 6 lines
2. Per-cgroup state lifetime:
iocg_idis the css id and is recycled once the cgroup is removed, so models must treat it as a transient key. Does the interface need arelease(iocg_id)callback so models can clean up per-cgroup state instead of detecting reuse, or is per-cgroup bpf local storage, which carries its own lifetime, the better home for model state?I'd pass blkcg as a kptr and add online/offline callbacks so the model can manage its per-cgroup state.
Quoted 2 lines
return value of 0 delegates the IO back to the builtin formula, so a model which only handles some IO types cannot make the rest free.
Quoted 7 lines
I don't think mixing BPF and builtin pricing makes sense, either per IO or between charging and request sizing. It seems convoluted and error-prone. Implementing the linear model in BPF is straightforward.
Please combine the interface, registration, dispatch and configuration changes into one patch. These patches are small and implement one feature.
Thanks for the detailed review across the series.
All the comments make sense. I'm reworking the interface for v2 along those lines: the attachment model will be reworked, the mixed builtin/BPF pricing path will go away so a model fully owns pricing on a device it's attached to (including flushes), the per-cgroup state handling is being reworked, operation flags will be preserved, and sleepable models will be rejected during verification.
The Kconfig dependency, the example model issues, the selftest problems, and the patch organization will all be addressed as well.
I'll post v2 once it's ready.
Thanks,
Tao
Quoted 2 lines
Thanks.