public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized
@ 2025-04-15 14:51 Jens Axboe
  2025-04-15 15:39 ` Chaitanya Kulkarni
  2025-04-15 15:50 ` Bart Van Assche
  0 siblings, 2 replies; 6+ messages in thread
From: Jens Axboe @ 2025-04-15 14:51 UTC (permalink / raw)
  To: linux-block@vger.kernel.org

On x86, rep stos will be emitted to clear the the blk_mq_alloc_data
struct, as not all members are being initialied. Depending on the
type of CPU, this is a noticeable slowdown compared to just ensuring
that the struct is fully initialized when setup.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/block/blk-mq.c b/block/blk-mq.c
index c2697db59109..9fb43b09a401 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -584,9 +584,13 @@ static struct request *blk_mq_rq_cache_fill(struct request_queue *q,
 	struct blk_mq_alloc_data data = {
 		.q		= q,
 		.flags		= flags,
+		.shallow_depth	= 0,
 		.cmd_flags	= opf,
+		.rq_flags	= 0,
 		.nr_tags	= plug->nr_ios,
 		.cached_rqs	= &plug->cached_rqs,
+		.ctx		= NULL,
+		.hctx		= NULL
 	};
 	struct request *rq;
 
@@ -646,8 +650,13 @@ struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf,
 		struct blk_mq_alloc_data data = {
 			.q		= q,
 			.flags		= flags,
+			.shallow_depth	= 0,
 			.cmd_flags	= opf,
+			.rq_flags	= 0,
 			.nr_tags	= 1,
+			.cached_rqs	= NULL,
+			.ctx		= NULL,
+			.hctx		= NULL
 		};
 		int ret;
 
@@ -675,8 +684,13 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	struct blk_mq_alloc_data data = {
 		.q		= q,
 		.flags		= flags,
+		.shallow_depth	= 0,
 		.cmd_flags	= opf,
+		.rq_flags	= 0,
 		.nr_tags	= 1,
+		.cached_rqs	= NULL,
+		.ctx		= NULL,
+		.hctx		= NULL
 	};
 	u64 alloc_time_ns = 0;
 	struct request *rq;
@@ -2969,8 +2983,14 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
 {
 	struct blk_mq_alloc_data data = {
 		.q		= q,
-		.nr_tags	= 1,
+		.flags		= 0,
+		.shallow_depth	= 0,
 		.cmd_flags	= bio->bi_opf,
+		.rq_flags	= 0,
+		.nr_tags	= 1,
+		.cached_rqs	= NULL,
+		.ctx		= NULL,
+		.hctx		= NULL
 	};
 	struct request *rq;
 
-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized
  2025-04-15 14:51 [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized Jens Axboe
@ 2025-04-15 15:39 ` Chaitanya Kulkarni
  2025-04-15 15:50 ` Bart Van Assche
  1 sibling, 0 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2025-04-15 15:39 UTC (permalink / raw)
  To: Jens Axboe, linux-block@vger.kernel.org

On 4/15/25 07:51, Jens Axboe wrote:
> On x86, rep stos will be emitted to clear the the blk_mq_alloc_data
> struct, as not all members are being initialied. Depending on the
> type of CPU, this is a noticeable slowdown compared to just ensuring
> that the struct is fully initialized when setup.
>
> Signed-off-by: Jens Axboe<axboe@kernel.dk>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized
  2025-04-15 14:51 [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized Jens Axboe
  2025-04-15 15:39 ` Chaitanya Kulkarni
@ 2025-04-15 15:50 ` Bart Van Assche
  2025-04-15 15:59   ` Jens Axboe
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Van Assche @ 2025-04-15 15:50 UTC (permalink / raw)
  To: Jens Axboe, linux-block@vger.kernel.org

On 4/15/25 7:51 AM, Jens Axboe wrote:
> On x86, rep stos will be emitted to clear the the blk_mq_alloc_data
> struct, as not all members are being initialied.

"Partial initialization" never happens in the C language when
initializing a data structure. If a data structure is initialized,
members that have not been specified are initialized to zero (the 
compiler is not required to initialize padding bytes). In other words,
the description of this patch needs to be improved.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized
  2025-04-15 15:50 ` Bart Van Assche
@ 2025-04-15 15:59   ` Jens Axboe
  2025-04-15 16:13     ` Bart Van Assche
  0 siblings, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2025-04-15 15:59 UTC (permalink / raw)
  To: Bart Van Assche, linux-block@vger.kernel.org

On 4/15/25 9:50 AM, Bart Van Assche wrote:
> On 4/15/25 7:51 AM, Jens Axboe wrote:
>> On x86, rep stos will be emitted to clear the the blk_mq_alloc_data
>> struct, as not all members are being initialied.
> 
> "Partial initialization" never happens in the C language when
> initializing a data structure. If a data structure is initialized,
> members that have not been specified are initialized to zero (the
> compiler is not required to initialize padding bytes). In other words,
> the description of this patch needs to be improved.

How is the description inaccurate? As not all members are being
explicitly initialized, rep stos is emitted to do so.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized
  2025-04-15 15:59   ` Jens Axboe
@ 2025-04-15 16:13     ` Bart Van Assche
  2025-04-15 16:15       ` Jens Axboe
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Van Assche @ 2025-04-15 16:13 UTC (permalink / raw)
  To: Jens Axboe, linux-block@vger.kernel.org

On 4/15/25 8:59 AM, Jens Axboe wrote:
> On 4/15/25 9:50 AM, Bart Van Assche wrote:
>> On 4/15/25 7:51 AM, Jens Axboe wrote:
>>> On x86, rep stos will be emitted to clear the the blk_mq_alloc_data
>>> struct, as not all members are being initialied.
>>
>> "Partial initialization" never happens in the C language when
>> initializing a data structure. If a data structure is initialized,
>> members that have not been specified are initialized to zero (the
>> compiler is not required to initialize padding bytes). In other words,
>> the description of this patch needs to be improved.
> 
> How is the description inaccurate? As not all members are being
> explicitly initialized, rep stos is emitted to do so.

Hi Jens,

I think we agree if the word "explicit" would be added to the patch
description.

Thanks,

Bart.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized
  2025-04-15 16:13     ` Bart Van Assche
@ 2025-04-15 16:15       ` Jens Axboe
  0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2025-04-15 16:15 UTC (permalink / raw)
  To: Bart Van Assche, linux-block@vger.kernel.org

On 4/15/25 10:13 AM, Bart Van Assche wrote:
> On 4/15/25 8:59 AM, Jens Axboe wrote:
>> On 4/15/25 9:50 AM, Bart Van Assche wrote:
>>> On 4/15/25 7:51 AM, Jens Axboe wrote:
>>>> On x86, rep stos will be emitted to clear the the blk_mq_alloc_data
>>>> struct, as not all members are being initialied.
>>>
>>> "Partial initialization" never happens in the C language when
>>> initializing a data structure. If a data structure is initialized,
>>> members that have not been specified are initialized to zero (the
>>> compiler is not required to initialize padding bytes). In other words,
>>> the description of this patch needs to be improved.
>>
>> How is the description inaccurate? As not all members are being
>> explicitly initialized, rep stos is emitted to do so.
> 
> Hi Jens,
> 
> I think we agree if the word "explicit" would be added to the patch
> description.

Sure

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-15 16:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 14:51 [PATCH] block: ensure that struct blk_mq_alloc_data is fully initialized Jens Axboe
2025-04-15 15:39 ` Chaitanya Kulkarni
2025-04-15 15:50 ` Bart Van Assche
2025-04-15 15:59   ` Jens Axboe
2025-04-15 16:13     ` Bart Van Assche
2025-04-15 16:15       ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox