From: Tao Cui <cui.tao@linux.dev>
To: Tejun Heo <tj@kernel.org>
Cc: cui.tao@linux.dev, josef@toxicopanda.com, axboe@kernel.dk,
ast@kernel.org, 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, daniel@iogearbox.net,
linux-kselftest@vger.kernel.org, cuitao@kylinos.cn,
ameryhung@gmail.com
Subject: Re: [RFC PATCH v14 1/4] blk-iocost: add BPF struct_ops cost model support
Date: Mon, 30 Nov 2026 18:14:53 +0800 [thread overview]
Message-ID: <88713b2f-180a-4ed0-9626-53f1ae4af9f5@linux.dev> (raw)
In-Reply-To: <e7400e9857d370843a5e9f099ca470fb@kernel.org>
Hello, Tejun,
在 2026/11/30 03:10, Tejun Heo 写道:
> Hello, Tao.
>
> On Wed, Nov 18, 2026 at 09:10:26PM +0800, Tao Cui wrote:
>> + const struct iocost_model_ops *attached;
>> + struct bpf_link *attached_link;
>> + /* either NULL (linear) or ->attached */
>> + const struct iocost_model_ops __rcu *bpf_model;
>
> Can you put these inside #ifdef CONFIG_BLK_CGROUP_IOCOST_BPF and go through
> helpers with stubs where they're used outside the struct_ops code, e.g. in
> ioc_cost_model_write()?
>
Makes sense. I'll put the three fields under the ifdef and use helpers
for accesses outside the struct_ops code, with ioc_bpf_attached()
returning NULL and ioc_bpf_model_set() being a no-op when BPF support
is disabled.
>> @@ -2657,6 +2723,41 @@ static u64 calc_vtime_cost(struct bio *bio, struct ioc_gq *iocg, bool is_merge)
> ...
>> + cost = model->calc_cost(bio, is_merge ? IOCOST_CALC_MERGE : 0);
>> + return min(cost, VTIME_PER_SEC);
>
> Maybe calc_vtime_cost() and calc_vtime_cost_builtin() can take IOCOST_CALC_
> flags from the callers instead of the is_merge bool?
>
Agreed. I'll have both helpers take IOCOST_CALC_* flags directly, with
callers passing either 0 or IOCOST_CALC_MERGE. This keeps the builtin
behavior unchanged and aligns the helper interface with the BPF
callback.
> Also, what's the justification for capping the cost at VTIME_PER_SEC?
>
The intent was to protect the downstream accounting arithmetic from
unexpectedly large costs returned by a BPF model. For example,
abs_cost_to_cost() multiplies the absolute cost by WEIGHT_ONE, which
can overflow with an arbitrary u64 return value.
However, VTIME_PER_SEC was chosen as a conservative per-bio bound
rather than one derived from the accounting arithmetic. I'll revisit
the bound and check what limit is actually needed.
>> @@ -3535,11 +3680,12 @@ static u64 ioc_cost_model_prfill(struct seq_file *sf,
> ...
>> - seq_printf(sf, "%s ctrl=%s model=linear "
>> + seq_printf(sf, "%s ctrl=%s model=%s "
>> "rbps=%llu rseqiops=%llu rrandiops=%llu "
>> "wbps=%llu wseqiops=%llu wrandiops=%llu "
>> "flushiops=%llu\n",
>
> ctrl and the coefficients describe the linear model and don't mean anything
> while a BPF model is selected. Can you add a name[] member to
> iocost_model_ops and print that instead when the model is bpf? Something
> like:
>
> 252:1 model=bpf name=<name>
>
Yes. I'll add a name member to iocost_model_ops, validate it
during initialization, and print only
252:1 model=bpf name=<name>
when a BPF model is selected. The existing output format will remain
unchanged for the linear model.
>> +static void ioc_bpf_unreg(void *kdata, struct bpf_link *link)
>> +{
> ...
>> + /* del_gendisk() is in progress or done. ioc_rqos_exit() detaches. */
>> + bdev = blkdev_get_no_open(new_decode_dev(ops->dev), false);
>> + if (!bdev)
>> + return;
>
> Looking the device up by dev_t again here is what makes iocost hold its own
> reference on the map and handle the window after the bdev is unhashed. I
> wonder whether it'd be simpler to make .unreg the only detach path:
>
> - .reg keeps the device reference it already has and stores the pointer in
> a private member of iocost_model_ops, like hid_bpf_ops->hdev. .unreg
> reaches the queue through it and drops the reference.
>
> - ioc_rqos_exit() runs under rq_qos_mutex and can't detach the link
> directly, but it can queue a work item which calls link->ops->detach()
> so that the usual .unreg runs. It'd need to hold the link for that,
> maybe with bpf_link_inc_not_zero().
>
> The link holds the map until .unreg has run, so iocost wouldn't need its
> own reference on it. The device reference would be there only for .unreg
> calls which run after rq_qos_exit(), from the work item or from a link
> close racing the removal. Can you add a comment explaining that?
>
I implemented the workqueue-based approach locally, and it passed the
same validation as the current implementation.
This avoids the dev_t lookup in .unreg() and allows the link to hold
the map reference until .unreg() runs, removing the need for iocost to
hold an additional map reference.
I'll adopt this approach in the next revision and add a comment
explaining why the bdev reference is retained until .unreg(), including
the case where it runs after ioc_rqos_exit().
Thanks,
Tao
> Thanks.
>
> --
> tejun
next prev parent reply other threads:[~2026-11-30 10:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 13:10 [RFC PATCH v14 0/4] blk-iocost: BPF struct_ops cost model Tao Cui
2026-11-18 13:10 ` [RFC PATCH v14 1/4] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-11-29 19:10 ` Tejun Heo
2026-11-30 10:14 ` Tao Cui [this message]
2026-11-18 13:10 ` [RFC PATCH v14 2/4] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-11-18 13:49 ` bot+bpf-ci
2026-11-18 13:10 ` [RFC PATCH v14 3/4] selftests/bpf: add iocost cost model test Tao Cui
2026-11-18 13:49 ` bot+bpf-ci
2026-11-18 13:10 ` [RFC PATCH v14 4/4] docs: cgroup-v2: document the iocost BPF cost model attachment Tao Cui
2026-11-18 13:17 ` [RFC PATCH v14 0/4] blk-iocost: BPF struct_ops cost model Tao Cui
2026-11-29 2:17 ` 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=88713b2f-180a-4ed0-9626-53f1ae4af9f5@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
all inboxes | Powered by JetHome®