All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: Tejun Heo <tj@kernel.org>
Cc: cui.tao@linux.dev, josef@toxicopanda.com, axboe@kernel.dk,
	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,
	Tao Cui <cuitao@kylinos.cn>,
	ameryhung@gmail.com, alexei.starovoitov@gmail.com
Subject: Re: [RFC PATCH v7 1/4] blk-iocost: add BPF struct_ops cost model support
Date: Tue, 29 Sep 2026 21:42:51 +0800	[thread overview]
Message-ID: <daf428f7-d666-447f-9b6e-a77da4194e91@linux.dev> (raw)
In-Reply-To: <4412563645504aa9a87d3cafd544c97c@kernel.org>

Hello, Tejun.

在 2026/9/29 08:42, Tejun Heo 写道:
> Hello, Tao.
> 
> On Thu, 24 Sep 2026 13:45:46 +0800, Tao Cui wrote:
> 
>> -	/* if user is overriding anything, maintain what was there */
>> -	if (ioc->user_qos_params || ioc->user_cost_model)
>> +	/* if user is overriding anything, maintain what was there; the
>> +	 * same while a BPF model is attached: the builtin coefficients
>> +	 * are inert then, so stepping the profile is pointless
>> +	 */
>> +	if (ioc->user_qos_params || ioc->user_cost_model
>> +#ifdef CONFIG_BLK_CGROUP_IOCOST_BPF
>> +	    || rcu_dereference_protected(ioc->model,
>> +					 lockdep_is_held(&ioc->lock))
>> +#endif
>> +	   )
> 
> Can you add a helper which returns the model in use with a stub returning
> NULL for !CONFIG_BLK_CGROUP_IOCOST_BPF? That'd remove most of the #ifdefs
> including the one in this condition and the duplicated seq_printf() in
> ioc_cost_model_prfill().
Done.  ioc_model_in_use() and a locked variant return the model in
use, with NULL stubs for !CONFIG_BLK_CGROUP_IOCOST_BPF; the autop
condition, both calc paths, the pd callbacks and the prfill now call
the helpers, and the duplicated seq_printf() is unified.

> 
>> +		/* sub-page IO: nothing to transfer-price */
>> +		if (!pages)
>> +			return 0;
>> +		/* zero transfer cost is a legal model; guard the division */
>> +		if (!coeff)
>> +			return 0;
>> +		/* pages * coeff can wrap and dodge the clamp below */
>> +		if (coeff > VTIME_PER_SEC || pages > VTIME_PER_SEC / coeff)
>> +			return VTIME_PER_SEC;
>> +		return min(pages * coeff, VTIME_PER_SEC);
> 
> This can just be pages * coeff like the builtin. An overflow only skews
> the met/missed accounting, same as a user-set linear coefficient, and it
> also gets rid of the 64-bit division.
> 
Done; the guards and the division are gone and the completion-time
sizing is back to a plain pages * coeff, like the builtin.

>> +	bdevf = bdev_file_open_by_dev(new_decode_dev(ops->dev),
>> +				      BLK_OPEN_READ, NULL, NULL);
> 
> When the disk goes away, the model should be ejected completely.
> ioc_rqos_exit() unbinds it but the open bdev file keeps the dead disk and
> the driver module pinned until the link is destroyed. Can you drop all
> device references on removal like hid_bpf_destroy_device() does and look
> up the device like blkg_conf_open_bdev() does, with blkdev_get_no_open()
> and disk_live() checked under rq_qos_mutex? The two attach issues bpf-ci
> reported, the missing re-attach check in .reg and the missing disk_live()
> check, are real.
> 
Done.  The struct file is gone: the attach looks the device up with
blkdev_get_no_open() and checks disk_live() under rq_qos_mutex like
blkg_conf_open_bdev(), .reg rejects re-attach via ops->q, and
ioc_rqos_exit() ejects the model completely on removal, clearing the
queue pointer.

To keep the queue alive across detach, the attach now holds a
no_open bdev reference, similar to hid_bpf's per-ops device
reference but without a struct file or driver-module pin; the
reference is dropped by whichever path detaches the model first,
either ioc_rqos_exit() during removal or .unreg, and .unreg
re-checks ops->q under rq_qos_mutex.

That leaves one race: .unreg may observe a non-NULL ops->q before
ioc_rqos_exit() clears it, then block on rq_qos_mutex while the
ejection drops the last bdev reference.  This looks analogous to
hid_bpf's .unreg vs. destroy_device synchronization.

Does that seem acceptable here too, or would you rather have .unreg
own the final reference unconditionally?

Thanks.
Tao

> Thanks.
> 
> --
> tejun


  reply	other threads:[~2026-09-29 13:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  5:45 [RFC PATCH v7 0/4] blk-iocost: BPF struct_ops cost model Tao Cui
2026-09-24  5:45 ` [RFC PATCH v7 1/4] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-09-24  6:00   ` sashiko-bot
2026-09-24  6:30   ` bot+bpf-ci
2026-09-29  0:42   ` Tejun Heo
2026-09-29 13:42     ` Tao Cui [this message]
2026-09-29 16:27       ` Tejun Heo
2026-09-30  4:14         ` Tao Cui
2026-09-24  5:45 ` [RFC PATCH v7 2/4] selftests/bpf: add iocost cost model test Tao Cui
2026-09-24  5:57   ` sashiko-bot
2026-09-24  6:30   ` bot+bpf-ci
2026-09-24  5:45 ` [RFC PATCH v7 3/4] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-09-24  6:17   ` bot+bpf-ci
2026-09-29  0:42   ` Tejun Heo
2026-09-29 13:46     ` Tao Cui
2026-09-24  5:45 ` [RFC PATCH v7 4/4] docs: cgroup-v2: document the iocost BPF cost model attachment Tao Cui
2026-09-29  0:42 ` [RFC PATCH v7 0/4] blk-iocost: BPF struct_ops cost model Tejun Heo
2026-09-29 13:39   ` Tao Cui
2026-09-29 16:27     ` Tejun Heo
2026-09-30  4:09       ` 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=daf428f7-d666-447f-9b6e-a77da4194e91@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.