Linux Kernel Selftest development
 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,
	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: Mon, 16 Nov 2026 07:27:17 -1000	[thread overview]
Message-ID: <e6062944917f1c9a87ab084bae9352a9@kernel.org> (raw)
In-Reply-To: <20261106122356.3224638-2-cui.tao@linux.dev>

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?

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

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.

> +	/* 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.

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?

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

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

Thanks.

--
tejun

  reply	other threads:[~2026-11-16 17:27 UTC|newest]

Thread overview: 10+ 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 [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=e6062944917f1c9a87ab084bae9352a9@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