From: Yu Kuai <yukuai1@huaweicloud.com>
To: Liang Jie <buaajxlj@163.com>, yukuai1@huaweicloud.com
Cc: axboe@kernel.dk, fanggeng@lixiang.com, gj.han@foxmail.com,
hailan@yukuai.org.cn, hanguangjiang@lixiang.com,
liangjie@lixiang.com, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, yangchen11@lixiang.com,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] blk-throttle: check policy bit in blk_throtl_activated()
Date: Wed, 3 Sep 2025 16:24:45 +0800 [thread overview]
Message-ID: <f17231f5-61a0-8d2d-eef5-f9b838caad34@huaweicloud.com> (raw)
In-Reply-To: <20250903072112.3432190-1-buaajxlj@163.com>
Hi,
在 2025/09/03 15:21, Liang Jie 写道:
> On Wed, 3 Sep 2025 14:03:37 +0800, Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
>> 在 2025/09/03 10:55, Han Guangjiang 写道:
>>> Hi Kuai,
>>>
>>>> Instead of add checking from hot path, do you consider delaying setting q->td
>>>> until policy is activated from the slow path? I think this is better solution.
>>>
>>> Thank you for your review. You're absolutely right that performance
>>> considerations in the hot path are important.
>>>
>>> We actually considered delaying the setting of q->td until after policy
>>> activation, but we found that q->td is needed by blkcg_activate_policy()
>>> during its execution, so it has to be set before calling
>>> blkcg_activate_policy().
>>
>> That's not hard to bypass, q->td is used to initialze tg->td in
>> throtl_pd_init(), actually you can just remove it, and add a helper
>> tg_to_td() to replace it;
>>
>> struct throtl_data *tg_to_td(struct throtl_grp *tg)
>> {
>> return tg_to_blkg(tg)->q->td;
>> }
>
> Hi Kuai,
>
> Thanks for the suggestion. Just a quick note: in throtl_pd_init(), q->td is not
> only used to init tg->td, it’s also needed for sq->parent_sq:
>
> - sq->parent_sq = &td->service_queue;
>
> So if we remove tg->td and delay q->td, throtl_pd_init() won’t have a valid td
> to set parent_sq.
Yes, however, this can be fixed very similar:
Set sq->parent_sq to NULL here, and add a helper parent_sq(q, sq):
if (sq->parent_sq)
return sq->parent_sq;
td_sq = &q->td->service_queue;
return sq == td_sq ? NULL : td_sq;
And sq_to_tg() need to be changed as well. So far, I'm not sure how many
code changes are required this way. We of course want a simple fix for
stable backport, but we definitely still want this kind of fix in future
release.
Thanks,
Kuai
>
>>
>> Meanwhile, please remove the comment about freeze queue, turns out it
>> can't protect blk_throtl_bio() becasue q_usage_coutner is not grabbed
>> yet while issuing bio.
>
> You’re right. We’ll remove that comment in patch v2.
>
> Thanks,
> Liang Jie
>
>>
>> Thanks,
>> Kuai
>>
>>>
>>> We explored several alternative approaches:
>>>
>>> 1) Adding a dedicated flag like 'throttle_ready' to struct request_queue:
>>> - Set this flag at the end of blk_throtl_init()
>>> - Check this flag in blk_throtl_activated() to determine if policy
>>> loading is complete
>>> - However, this requires adding a new bool variable to the struct
>>>
>>> 2) Reusing the q->td pointer with low-order bit flags:
>>> - Use pointer low-order bits to mark initialization completion status
>>> - This would avoid adding new fields but requires careful handling
>>> and additional processing
>>>
>>> Given these constraints, we chose the current approach of checking the
>>> policy bit in blk_throtl_activated() as it:
>>> - Doesn't require struct changes
>>> - Provides a clean, atomic check
>>> - Aligns with the existing policy activation mechanism
>>>
>>> We would appreciate your suggestions on how to better handle this
>>> initialization race condition.
>>>
>>> Thanks,
>>> Han Guangjiang
>>>
>
> .
>
prev parent reply other threads:[~2025-09-03 8:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 12:39 [PATCH] blk-throttle: check policy bit in blk_throtl_activated() gj.han
2025-09-02 17:06 ` Yu Kuai
2025-09-03 2:55 ` Han Guangjiang
2025-09-03 6:03 ` Yu Kuai
2025-09-03 7:21 ` Liang Jie
2025-09-03 8:24 ` Yu Kuai [this message]
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=f17231f5-61a0-8d2d-eef5-f9b838caad34@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=axboe@kernel.dk \
--cc=buaajxlj@163.com \
--cc=fanggeng@lixiang.com \
--cc=gj.han@foxmail.com \
--cc=hailan@yukuai.org.cn \
--cc=hanguangjiang@lixiang.com \
--cc=liangjie@lixiang.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yangchen11@lixiang.com \
--cc=yukuai3@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).