mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Tao Cui <cui.tao@linux.dev>
Cc: 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: Sun, 29 Nov 2026 09:10:36 -1000	[thread overview]
Message-ID: <e7400e9857d370843a5e9f099ca470fb@kernel.org> (raw)
In-Reply-To: <20261118131029.797007-2-cui.tao@linux.dev>

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()?

> @@ -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?

Also, what's the justification for capping the cost at VTIME_PER_SEC?

> @@ -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>

> +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?

Thanks.

--
tejun

  reply	other threads:[~2026-11-29 19:10 UTC|newest]

Thread overview: 10+ 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 [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=e7400e9857d370843a5e9f099ca470fb@kernel.org \
    --to=tj@kernel.org \
    --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=cui.tao@linux.dev \
    --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 \
    /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®