From: Yu Kuai <yukuai1@huaweicloud.com>
To: Damien Le Moal <dlemoal@kernel.org>,
Yu Kuai <yukuai1@huaweicloud.com>, Hannes Reinecke <hare@suse.de>,
jack@suse.cz, tj@kernel.org, josef@toxicpanda.com,
axboe@kernel.dk
Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, yi.zhang@huawei.com,
yangerkun@huawei.com, johnny.chenyi@huawei.com,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v2 2/5] mq-deadline: switch to use elevator lock
Date: Thu, 31 Jul 2025 15:14:06 +0800 [thread overview]
Message-ID: <2ada440d-5121-6c3e-71db-1f8eb63864a7@huaweicloud.com> (raw)
In-Reply-To: <9d918e77-73ef-41ad-87cf-cf87803041b5@kernel.org>
Hi,
在 2025/07/31 15:04, Damien Le Moal 写道:
> On 7/31/25 3:32 PM, Yu Kuai wrote:
>> Hi,
>>
>> 在 2025/07/31 14:22, Damien Le Moal 写道:
>>> On 7/31/25 3:20 PM, Hannes Reinecke wrote:
>>>> On 7/30/25 10:22, Yu Kuai wrote:
>>>>> From: Yu Kuai <yukuai3@huawei.com>
>>>>>
>>>>> Replace the internal spinlock 'dd->lock' with the new spinlock in
>>>>> elevator_queue, there are no functional changes.
>>>>>
>>>>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>>>>> ---
>>>>> block/mq-deadline.c | 58 +++++++++++++++++++++------------------------
>>>>> 1 file changed, 27 insertions(+), 31 deletions(-)
>>>>>
>>>>> diff --git a/block/mq-deadline.c b/block/mq-deadline.c
>>>>> index 9ab6c6256695..2054c023e855 100644
>>>>> --- a/block/mq-deadline.c
>>>>> +++ b/block/mq-deadline.c
>>>>> @@ -101,7 +101,7 @@ struct deadline_data {
>>>>> u32 async_depth;
>>>>> int prio_aging_expire;
>>>>> - spinlock_t lock;
>>>>> + spinlock_t *lock;
>>>>> };
>>>>> /* Maps an I/O priority class to a deadline scheduler priority. */
>>>>> @@ -213,7 +213,7 @@ static void dd_merged_requests(struct request_queue *q,
>>>>> struct request *req,
>>>>> const u8 ioprio_class = dd_rq_ioclass(next);
>>>>> const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
>>>>> - lockdep_assert_held(&dd->lock);
>>>>> + lockdep_assert_held(dd->lock);
>>>>> dd->per_prio[prio].stats.merged++;
>>>>> @@ -253,7 +253,7 @@ static u32 dd_queued(struct deadline_data *dd, enum
>>>>> dd_prio prio)
>>>>> {
>>>>> const struct io_stats_per_prio *stats = &dd->per_prio[prio].stats;
>>>>> - lockdep_assert_held(&dd->lock);
>>>>> + lockdep_assert_held(dd->lock);
>>>>> return stats->inserted - atomic_read(&stats->completed);
>>>>> }
>>>>> @@ -323,7 +323,7 @@ static struct request *__dd_dispatch_request(struct
>>>>> deadline_data *dd,
>>>>> enum dd_prio prio;
>>>>> u8 ioprio_class;
>>>>> - lockdep_assert_held(&dd->lock);
>>>>> + lockdep_assert_held(dd->lock);
>>>>> if (!list_empty(&per_prio->dispatch)) {
>>>>> rq = list_first_entry(&per_prio->dispatch, struct request,
>>>>> @@ -434,7 +434,7 @@ static struct request
>>>>> *dd_dispatch_prio_aged_requests(struct deadline_data *dd,
>>>>> enum dd_prio prio;
>>>>> int prio_cnt;
>>>>> - lockdep_assert_held(&dd->lock);
>>>>> + lockdep_assert_held(dd->lock);
>>>>> prio_cnt = !!dd_queued(dd, DD_RT_PRIO) + !!dd_queued(dd,
>>>>> DD_BE_PRIO) +
>>>>> !!dd_queued(dd, DD_IDLE_PRIO);
>>>>> @@ -466,10 +466,9 @@ static struct request *dd_dispatch_request(struct
>>>>> blk_mq_hw_ctx *hctx)
>>>>> struct request *rq;
>>>>> enum dd_prio prio;
>>>>> - spin_lock(&dd->lock);
>>>>> rq = dd_dispatch_prio_aged_requests(dd, now);
>>>>> if (rq)
>>>>> - goto unlock;
>>>>> + return rq;
>>>>> /*
>>>>> * Next, dispatch requests in priority order. Ignore lower priority
>>>>> @@ -481,9 +480,6 @@ static struct request *dd_dispatch_request(struct
>>>>> blk_mq_hw_ctx *hctx)
>>>>> break;
>>>>> }
>>>>> -unlock:
>>>>> - spin_unlock(&dd->lock);
>>>>> -
>>>>> return rq;
>>>>> }
>>>>> @@ -538,9 +534,9 @@ static void dd_exit_sched(struct elevator_queue *e)
>>>>> WARN_ON_ONCE(!list_empty(&per_prio->fifo_list[DD_READ]));
>>>>> WARN_ON_ONCE(!list_empty(&per_prio->fifo_list[DD_WRITE]));
>>>>> - spin_lock(&dd->lock);
>>>>> + spin_lock(dd->lock);
>>>>> queued = dd_queued(dd, prio);
>>>>> - spin_unlock(&dd->lock);
>>>>> + spin_unlock(dd->lock);
>>>>> WARN_ONCE(queued != 0,
>>>>> "statistics for priority %d: i %u m %u d %u c %u\n",
>>>>
>>>> Do you still need 'dd->lock'? Can't you just refer to the lock from the
>>>> elevator_queue structure directly?
>>>
>>> Indeed. Little inline helpers for locking/unlocking q->elevator->lock would be
>>> nice.
>>
>> How about the first patch to factor out inline helpers like dd_lock()
>> and dd_unlock(), still use dd->lock without any functional changes, and
>> then switch to use q->elevator->lock in the next patch? (same for bfq)
>
> Patch one can introduce elv->lock and the helpers, then patch 2 use the helpers
> to replace dd->lock. Just don't say "no functional change" in the commit
> message and rather explain that things keep working the same way as before, but
> using a different lock. That will address Bart's comment too.
> And same for bfq in patch 3.
>
Ok, this is what I did in the first RFC version:
https://lore.kernel.org/all/20250530080355.1138759-3-yukuai1@huaweicloud.com/
I somehow convince myself using dd->lock is better. :(
Will change this in the next version.
Thanks,
Kuai
>
next prev parent reply other threads:[~2025-07-31 7:14 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-30 8:22 [PATCH v2 0/5] blk-mq-sched: support request batch dispatching for sq elevator Yu Kuai
2025-07-30 8:22 ` [PATCH v2 1/5] blk-mq-sched: introduce high level elevator lock Yu Kuai
2025-07-30 17:19 ` Bart Van Assche
2025-07-30 17:59 ` Yu Kuai
2025-07-31 6:17 ` Hannes Reinecke
2025-07-30 8:22 ` [PATCH v2 2/5] mq-deadline: switch to use " Yu Kuai
2025-07-30 17:21 ` Bart Van Assche
2025-07-30 18:01 ` Yu Kuai
2025-07-30 18:10 ` Bart Van Assche
2025-07-31 6:20 ` Hannes Reinecke
2025-07-31 6:22 ` Damien Le Moal
2025-07-31 6:32 ` Yu Kuai
2025-07-31 7:04 ` Damien Le Moal
2025-07-31 7:14 ` Yu Kuai [this message]
2025-07-30 8:22 ` [PATCH v2 3/5] block, bfq: " Yu Kuai
2025-07-30 17:24 ` Bart Van Assche
2025-07-31 6:22 ` Hannes Reinecke
2025-07-30 8:22 ` [PATCH v2 4/5] blk-mq-sched: refactor __blk_mq_do_dispatch_sched() Yu Kuai
2025-07-30 18:32 ` Bart Van Assche
2025-07-31 0:49 ` Yu Kuai
2025-07-30 8:22 ` [PATCH v2 5/5] blk-mq-sched: support request batch dispatching for sq elevator Yu Kuai
2025-07-31 8:18 ` [PATCH v2 0/5] " Ming Lei
2025-07-31 8:42 ` Yu Kuai
2025-07-31 9:25 ` Ming Lei
2025-07-31 9:33 ` Yu Kuai
2025-07-31 10:22 ` Ming Lei
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=2ada440d-5121-6c3e-71db-1f8eb63864a7@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=dlemoal@kernel.org \
--cc=hare@suse.de \
--cc=jack@suse.cz \
--cc=johnny.chenyi@huawei.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.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).