From: Tao Cui <cui.tao@linux.dev>
To: Tejun Heo <tj@kernel.org>
Cc: cui.tao@linux.dev, josef@toxicopanda.com, axboe@kernel.dk,
alexei.starovoitov@gmail.com, cgroups@vger.kernel.org,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, andrii@kernel.org, eddyz87@gmail.com,
ast@kernel.org, daniel@iogearbox.net,
linux-kselftest@vger.kernel.org, cuitao@kylinos.cn,
ameryhung@gmail.com
Subject: Re: [RFC PATCH v13 1/4] blk-iocost: add BPF struct_ops cost model support
Date: Tue, 17 Nov 2026 16:10:06 +0800 [thread overview]
Message-ID: <64588236-7ab4-4d63-8ab5-8a1658eb15b0@linux.dev> (raw)
In-Reply-To: <e6062944917f1c9a87ab084bae9352a9@kernel.org>
Hello, Tejun.
在 2026/11/17 01:27, Tejun Heo 写道:
> Hello, Tao.
>
> On Fri, Nov 06, 2026 at 08:23:53PM +0800, Tao Cui wrote:
>> Attaching an iocost_model_ops struct_ops binds the model to one
>> device: the target is set in the dev member from userspace and
>> .reg creates the ioc if needed like an io.cost.model write and
>> ...
>
> From here on, the description mostly walks through what the code does.
> Can it instead explain why it works this way and what it guarantees, and
> leave the mechanics to the code?
>
Rewritten. The commit message now describes what the attachment
guarantees: one attached model per device, pricing follows the
model across io.cost.model writes, attaching doesn't enable the
controller, and the model can't go away while it's pricing. The
freeze ordering and the detach mechanics are left to the code.
>> +enum {
>> + IOCOST_COST_F_MERGE = 1 << 0, /* called from the merge path */
>> +};
>
> Maybe name the flags after the callback they're passed to, e.g. enum
> iocost_calc_flags, IOCOST_CALC_MERGE and a calc_flags parameter, the way
> sched_ext pairs ops.enqueue()'s enq_flags with enum scx_enq_flags and
> SCX_ENQ_*? An unnamed enum type can't be looked up by name through BTF,
> so BPF programs can't test whether a flag exists.
>
Renamed. The enum is now iocost_calc_flags with
IOCOST_CALC_MERGE and the calc_cost parameter is calc_flags.
The named enum is used for the kernel-side definition; the BPF
callback argument remains u64, matching the existing struct_ops
interface style.
> Also, can the comment say what the flag means to the model rather than
> where the call comes from? The bio is being merged into an IO which was
> already charged its base cost.
>
Updated accordingly.
>> + /* holds a reference on the struct_ops map, NULL if none is attached */
>> + const struct iocost_model_ops *attached;
>> + struct bpf_link *attached_link;
>> + /* either NULL (linear) or ->attached */
>> + const struct iocost_model_ops __rcu *model;
>
> Can the comment say why iocost holds its own reference on the map? If the
> link is destroyed after del_gendisk() has unhashed the bdev but before
> rq_qos_exit(), .unreg can't look up the disk and returns without
> detaching, and the link drops its reference. iocost's reference keeps the
> map alive until ioc_rqos_exit() detaches the model.
>
The field comment now says exactly this.
> Also, why are attached and attached_link updated under ioc->lock in
> ioc_bpf_reg() and ioc_detach_model()? Everything which reads the two
> holds rq_qos_mutex: .reg, .unreg, ioc_detach_model() and
> ioc_cost_model_write(), which gets it from blkg_conf_open_bdev(). Only
> model is read under ioc->lock alone, by ioc_autop_idx() from the timer
> and the io.cost.model show path, besides the RCU readers. What is
> ioc->lock protecting for the two? Can you document the locking on the
> fields?
>
attached and attached_link themselves are protected by
rq_qos_mutex. The ioc->lock coverage is only needed for bpf_model,
which is read under ioc->lock by the timer and io.cost.model show
paths. The field comments now document the locking rules.
>> +static const struct iocost_model_ops *ioc_model(struct ioc *ioc)
>> +{
>> + if (!IS_ENABLED(CONFIG_BLK_CGROUP_IOCOST_BPF))
>> + return NULL;
>> + return rcu_dereference_check(ioc->model, lockdep_is_held(&ioc->lock));
>> +}
>
> ioc_model() returns NULL while the builtin linear model is in use, which
> is a model too. Maybe rename the accessor and the field together, e.g.
> ioc_bpf_model() and bpf_model, or ioc_model_bpf() and model_bpf?
>
Renamed to ioc_bpf_model() and bpf_model.
>> + spin_lock_irq(&ioc->lock);
>> + rcu_assign_pointer(ioc->model, NULL);
>> ...
>> + ioc->autop_too_fast_at = 0;
>> + ioc->autop_too_slow_at = 0;
>
> Resetting to 0 is right, but maybe ioc_bpf_reg() is a better place for
> it? .reg is the only path which switches pricing to the BPF model without
> a forced ioc_refresh_params(), which is what zeroes the timestamps for
> io.cost.qos and io.cost.model writes. If ioc_bpf_reg() zeroes them, they
> stay zero while the BPF model is in use, which covers both detach and the
> "model=linear" switch sashiko reported on this posting.
>
Moved. ioc_bpf_reg() zeroes the timestamps inside the ioc->lock
section together with the settle, and the zero in ioc_detach_model()
is dropped; as you say, they stay zero for the whole BPF period,
which covers both the detach and the model=linear switch.
Besides your comments, p1 also picked up two fixes from testing:
calc_cost() now matches the builtin pricing scope, and a dead owning
map now reports -ENODEV instead of -EBUSY.
Thanks,
Tao
> Thanks.
>
> --
> tejun
next prev parent reply other threads:[~2026-11-17 8:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 12:23 [RFC PATCH v13 0/4] blk-iocost: BPF struct_ops cost model Tao Cui
2026-11-06 12:23 ` [RFC PATCH v13 1/4] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-11-16 17:27 ` Tejun Heo
2026-11-17 8:10 ` Tao Cui [this message]
2026-11-06 12:23 ` [RFC PATCH v13 2/4] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-11-06 12:56 ` bot+bpf-ci
2026-11-09 13:05 ` Tao Cui
2026-11-16 17:30 ` Tejun Heo
2026-11-06 12:23 ` [RFC PATCH v13 3/4] selftests/bpf: add iocost cost model test Tao Cui
2026-11-06 12:56 ` bot+bpf-ci
2026-11-06 12:23 ` [RFC PATCH v13 4/4] docs: cgroup-v2: document the iocost BPF cost model attachment Tao Cui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=64588236-7ab4-4d63-8ab5-8a1658eb15b0@linux.dev \
--to=cui.tao@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=axboe@kernel.dk \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=cuitao@kylinos.cn \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=josef@toxicopanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox