From patchwork Mon Oct 18 20:37:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12568037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD03BC433FE for ; Mon, 18 Oct 2021 20:37:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD34F61206 for ; Mon, 18 Oct 2021 20:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbhJRUjz (ORCPT ); Mon, 18 Oct 2021 16:39:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbhJRUjx (ORCPT ); Mon, 18 Oct 2021 16:39:53 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB75C061745 for ; Mon, 18 Oct 2021 13:37:41 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id t16so4129355eds.9 for ; Mon, 18 Oct 2021 13:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QpyFRvxguVaC0e9bZkL9vF7ywKvCl3IKbPcL26yVMxA=; b=UP99eXOCIzfGHt9H6QpBbMPemO52t4H/iBZrzXk7dKT/YALHOPo9FlN+x30omXWCFj qklW1YkASiuYB0jqLJ9WN6VDLt32cFFPCrM54jTw+NDcJ+L8M8BPOpMAQ9asWw/45fKo JaobDCtdYEHDdXykBTdvc38j4vLIGMk7tM38TwrlD7TzmHvLZpvUWtVUJmJdFTvUuxJK uSpgVpmfyGFl+501EzPmCaqqZKxF9yviLtkhnKbCGgbODoSBv/IMS7zFpaflJIcpBGAQ 0+TzA1AHzJpyu690uV08/FxK2Sl7SJ0yUrLFXLVfjFr5PRIGNmSQ6+zvhBTe4PcHgmH7 F/Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QpyFRvxguVaC0e9bZkL9vF7ywKvCl3IKbPcL26yVMxA=; b=0iAM2h86GG47edjeVRoNW5YjVe3/+ZAxJ64F8ayny2AiOdrt/O+n+z8wJb/afrG7U5 2g2woyMWpULMMfuXjOF7CWKHZYWP4sro4mGM9/CvUVBzRqeAnV4hlGNEBSVRvCaagu6n OvLaImIJvKYtD4gvR9PUgueG9wOg8x/f1vlk4D6A0DjIHJT7KEmbogotGiK0pYcS1/qO TTIvLLiZJ9P6iePi2MKrk9EDK0tsv93g2qKw33052tgdpw/lXd/CHF9uN1a8nV6vizw4 g0S+/qv1Po0JFoAnwZE9Zaf9VIsNvaAnSR+yorFLU2jVlEUJpJwa7NqJ9IokflBeoUke qBZw== X-Gm-Message-State: AOAM5339aNGxa4g1CB8E6o0ri/HR9UR7S+KWHmj4NCsslQrFM0t495tj lN7k9J3iRtkO5ViVCnx4ytq1XwVSvnLmyg== X-Google-Smtp-Source: ABdhPJz7h41vVFN5OjJ9EeSUWNE8CNmL1cQLm2JyuQQhPst65UFhALKhuOxEqTrWVf/Xwed9DshTLQ== X-Received: by 2002:aa7:c883:: with SMTP id p3mr16782969eds.279.1634589460363; Mon, 18 Oct 2021 13:37:40 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.145.213]) by smtp.gmail.com with ESMTPSA id y19sm11124889edd.39.2021.10.18.13.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 13:37:40 -0700 (PDT) From: Pavel Begunkov To: linux-block@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Pavel Begunkov Subject: [PATCH 1/3] block: skip elevator fields init for non-elv queue Date: Mon, 18 Oct 2021 21:37:27 +0100 Message-Id: <3a6960482d175ade61333cfc0e3780f92b388197.1634589262.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Don't init rq->hash and rq->rb_node in blk_mq_rq_ctx_init() if there is no elevator. Also, move some other initialisers that imply barriers to the end, so the compiler is free to rearrange and optimise other the rest of them. note: fold in a change from Jens leaving queue_list unconditional, as it might lead to problems otherwise. Signed-off-by: Pavel Begunkov --- block/blk-mq.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 28eb1f3c6f76..1d2e2fd4043e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -325,6 +325,10 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->internal_tag = BLK_MQ_NO_TAG; } + if (blk_mq_need_time_stamp(rq)) + rq->start_time_ns = ktime_get_ns(); + else + rq->start_time_ns = 0; /* csd/requeue_work/fifo_time is initialized before use */ rq->q = data->q; rq->mq_ctx = data->ctx; @@ -334,41 +338,37 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->rq_flags |= RQF_PM; if (blk_queue_io_stat(data->q)) rq->rq_flags |= RQF_IO_STAT; - INIT_LIST_HEAD(&rq->queuelist); - INIT_HLIST_NODE(&rq->hash); - RB_CLEAR_NODE(&rq->rb_node); rq->rq_disk = NULL; rq->part = NULL; #ifdef CONFIG_BLK_RQ_ALLOC_TIME rq->alloc_time_ns = alloc_time_ns; #endif - if (blk_mq_need_time_stamp(rq)) - rq->start_time_ns = ktime_get_ns(); - else - rq->start_time_ns = 0; rq->io_start_time_ns = 0; rq->stats_sectors = 0; rq->nr_phys_segments = 0; #if defined(CONFIG_BLK_DEV_INTEGRITY) rq->nr_integrity_segments = 0; #endif - blk_crypto_rq_set_defaults(rq); - /* tag was already set */ - WRITE_ONCE(rq->deadline, 0); - rq->timeout = 0; - rq->end_io = NULL; rq->end_io_data = NULL; data->ctx->rq_dispatched[op_is_sync(data->cmd_flags)]++; + blk_crypto_rq_set_defaults(rq); + INIT_LIST_HEAD(&rq->queuelist); + /* tag was already set */ + WRITE_ONCE(rq->deadline, 0); refcount_set(&rq->ref, 1); - if (!op_is_flush(data->cmd_flags) && (rq->rq_flags & RQF_ELV)) { + if (rq->rq_flags & RQF_ELV) { struct elevator_queue *e = data->q->elevator; rq->elv.icq = NULL; - if (e->type->ops.prepare_request) { + INIT_HLIST_NODE(&rq->hash); + RB_CLEAR_NODE(&rq->rb_node); + + if (!op_is_flush(data->cmd_flags) && + e->type->ops.prepare_request) { if (e->type->icq_cache) blk_mq_sched_assign_ioc(rq); From patchwork Mon Oct 18 20:37:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12568041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F37D7C433F5 for ; Mon, 18 Oct 2021 20:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB143610FB for ; Mon, 18 Oct 2021 20:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbhJRUj4 (ORCPT ); Mon, 18 Oct 2021 16:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbhJRUjy (ORCPT ); Mon, 18 Oct 2021 16:39:54 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDA66C06161C for ; Mon, 18 Oct 2021 13:37:42 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id d9so4209319edh.5 for ; Mon, 18 Oct 2021 13:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2sE+Xnz4QcqtJUSXnRXCKjmjoQEip/P7dXQFhIdUm5A=; b=YdwHkzL/rXWwseP28cn/vgjfg3f26Myoq3aPdpJnHcNY7rvMexlQ2lvS7y5vc5Brfp okjtDsz76CNIvK/A+4XzqfNI5WzdVxLKYRzcJnbhS+y7yFPWsunzuyreCBU8vm8sLwMU 0OapSHwxiogbYALiMSZ3cRIRFcUqe0Z4usmceV9cDWRxGq7wboWwkfUYH9AYArWH+Wmx 8lx80d5gstSrfPSGcpLge0DjYZe2lCFHt6py0TQJiEvQkKaT93KRkkx0f/v3t1SEY8BG nWIFVOiWOCuK9CdIqHaVsb67RwRHPCnLSlDpQu/Jz3jSFf8Oh1WlD2AZ2E8zs+yQhdrx 1DOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2sE+Xnz4QcqtJUSXnRXCKjmjoQEip/P7dXQFhIdUm5A=; b=rLJ58jURu6QOx8hYzwGHUw2yJbYWpqHUwaDTsX4tv7E7+J6hDiVhdLJqX15c/wi3+1 6EvBPFNWJQbq6zf1N96VOIq27SC+gFlVbX8P+7wzDntOj13htE/SNO32ndlTYDNR0Rub gVW8TcPXOZU7PAjPtk/231gH2yCbWrJwZb9ZNlKI50VD7GKECkejBBu5PApze2yiaXx4 CYChPiEAGdqHnmpAV/vHOhbWvCkU6EkZXSMHvzQnuDcIAQg7XXRdp34SW67cvnGd3Hnb nfHIM7m67j/DyKVh6U8EdRMg3qEyOU2zMIXO3Juq+WFRLvHYgRW4mCLhTQ8WZ8rRQUzJ VxVw== X-Gm-Message-State: AOAM533iuHPjw5BYwJP19TtcBT6WbBeuknoVOE7vgk15x96N9xkFkITQ exiR9WWdas4IwWqVxbj51kMjZ0JL1j8VFA== X-Google-Smtp-Source: ABdhPJz8YB/MOnNMk0g5tQToxieNM7/Rd6qiaOTsuJSXnUXhSgdqv7eAAHGsTPT8nbjfSfmn3I9PBg== X-Received: by 2002:a05:6402:2022:: with SMTP id ay2mr49202236edb.344.1634589461094; Mon, 18 Oct 2021 13:37:41 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.145.213]) by smtp.gmail.com with ESMTPSA id y19sm11124889edd.39.2021.10.18.13.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 13:37:40 -0700 (PDT) From: Pavel Begunkov To: linux-block@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Pavel Begunkov Subject: [PATCH 2/3] block: blk_mq_rq_ctx_init cache ctx/q/hctx Date: Mon, 18 Oct 2021 21:37:28 +0100 Message-Id: <06a05d0b16a6504461502140c3d1e9c8cd91b862.1634589262.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org We should have enough of registers in blk_mq_rq_ctx_init(), store them in local vars, so we don't keep reloading them. note: keeping q->elevator may look unnecessary, but it's also used inside inlined blk_mq_tags_from_data(). Signed-off-by: Pavel Begunkov --- block/blk-mq.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 1d2e2fd4043e..fa4de25c3bcb 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -312,10 +312,14 @@ static inline bool blk_mq_need_time_stamp(struct request *rq) static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, unsigned int tag, u64 alloc_time_ns) { + struct blk_mq_ctx *ctx = data->ctx; + struct blk_mq_hw_ctx *hctx = data->hctx; + struct request_queue *q = data->q; + struct elevator_queue *e = q->elevator; struct blk_mq_tags *tags = blk_mq_tags_from_data(data); struct request *rq = tags->static_rqs[tag]; - if (data->q->elevator) { + if (e) { rq->rq_flags = RQF_ELV; rq->tag = BLK_MQ_NO_TAG; rq->internal_tag = tag; @@ -330,13 +334,13 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, else rq->start_time_ns = 0; /* csd/requeue_work/fifo_time is initialized before use */ - rq->q = data->q; - rq->mq_ctx = data->ctx; - rq->mq_hctx = data->hctx; + rq->q = q; + rq->mq_ctx = ctx; + rq->mq_hctx = hctx; rq->cmd_flags = data->cmd_flags; if (data->flags & BLK_MQ_REQ_PM) rq->rq_flags |= RQF_PM; - if (blk_queue_io_stat(data->q)) + if (blk_queue_io_stat(q)) rq->rq_flags |= RQF_IO_STAT; rq->rq_disk = NULL; rq->part = NULL; From patchwork Mon Oct 18 20:37:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12568039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E6C3C433EF for ; Mon, 18 Oct 2021 20:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02ABA61207 for ; Mon, 18 Oct 2021 20:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230159AbhJRUj4 (ORCPT ); Mon, 18 Oct 2021 16:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbhJRUjz (ORCPT ); Mon, 18 Oct 2021 16:39:55 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86B37C061765 for ; Mon, 18 Oct 2021 13:37:43 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id r18so4137347edv.12 for ; Mon, 18 Oct 2021 13:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n+HXVcu2x/PFm7UXxUdYHEvn+f68pA4E31anhqTCGNg=; b=n7323djZZwfiCZkP3zhz7OtTc/uPWDLWoGZSLrnCz0Xr4lZjvy7g3yQszATbOwoztQ kBxjuWIsYfknBEgLzUHirUoSTGyfDPsrbgO3qvviZBEMF3VLH20lkC/I55YAr6/YuNRY nlyIrxzPYrSqikZEZeWTwmz6/ulcKUdrXpA1ptHAOjMZQhgXzc7dC4lLZ2ARBE54jzl/ r9lTYHYC2Ko7mh25HCYAGluHZrz5vqf8AV5rQJJ3di6pd4UgdUkRsBDVevdY1+cwA5Vh qp+lL5g9QTt0DEVsc2sJ7MDGXCe9wNygvRuSRaE2dkARN2gD+GuBbXBcLNV41N87yOqF Blog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n+HXVcu2x/PFm7UXxUdYHEvn+f68pA4E31anhqTCGNg=; b=Q1fOK7v4nKokEeYtJRf5SIPLnifKbOEQC+1jHfTbTfjrgQy0a/fWLHL71jqt9fHM3T UTfdsracnE+7fRMTmQVBQjH5SHewcI4scX3zmnNjUezli9wFIKlxkZogVS+2GHN/BCw0 C59isNnaZojKxf3V2jWJ4f3hwOMAWNY7abNsnJfYq600tN2MFsg21ypP0mHyQdDb7KyG 3aeco359yrlxYNPmT42p53XJdD+Tr+ndDBG/XvSl4XRMO4yB+b1/l0n5oTmZzfsWOFuO XtbYpNIVNixTMust7IeumE2QrMuwCK94sI3Lgve9Z1xrWcS+mrGUvlVEb+xKsIX/FfGh vF6g== X-Gm-Message-State: AOAM533ABHrTpi8EXAhmkQbDwoaV+MckLoQ78ZAngcqJ9zCRlk9qHjQB G9a5+dHxGiett3LEZGuJ3JbfPuziuwW2oQ== X-Google-Smtp-Source: ABdhPJyVTi4CPWbJoHlsIOMm1X4RSjgq3N1NGkIF7aZWKhF5m/c8s4lSUfIT8o9VyjVbJQTCLNZKjQ== X-Received: by 2002:a17:907:77c8:: with SMTP id kz8mr32199624ejc.188.1634589461903; Mon, 18 Oct 2021 13:37:41 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.145.213]) by smtp.gmail.com with ESMTPSA id y19sm11124889edd.39.2021.10.18.13.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 13:37:41 -0700 (PDT) From: Pavel Begunkov To: linux-block@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Pavel Begunkov Subject: [PATCH 3/3] block: cache rq_flags inside blk_mq_rq_ctx_init() Date: Mon, 18 Oct 2021 21:37:29 +0100 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add a local variable for rq_flags, it helps to compile out some of rq_flags reloads. Signed-off-by: Pavel Begunkov --- block/blk-mq.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index fa4de25c3bcb..633d73580712 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -318,17 +318,23 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, struct elevator_queue *e = q->elevator; struct blk_mq_tags *tags = blk_mq_tags_from_data(data); struct request *rq = tags->static_rqs[tag]; + unsigned int rq_flags = 0; if (e) { - rq->rq_flags = RQF_ELV; + rq_flags = RQF_ELV; rq->tag = BLK_MQ_NO_TAG; rq->internal_tag = tag; } else { - rq->rq_flags = 0; rq->tag = tag; rq->internal_tag = BLK_MQ_NO_TAG; } + if (data->flags & BLK_MQ_REQ_PM) + rq_flags |= RQF_PM; + if (blk_queue_io_stat(q)) + rq_flags |= RQF_IO_STAT; + rq->rq_flags = rq_flags; + if (blk_mq_need_time_stamp(rq)) rq->start_time_ns = ktime_get_ns(); else @@ -338,10 +344,6 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->mq_ctx = ctx; rq->mq_hctx = hctx; rq->cmd_flags = data->cmd_flags; - if (data->flags & BLK_MQ_REQ_PM) - rq->rq_flags |= RQF_PM; - if (blk_queue_io_stat(q)) - rq->rq_flags |= RQF_IO_STAT; rq->rq_disk = NULL; rq->part = NULL; #ifdef CONFIG_BLK_RQ_ALLOC_TIME