From patchwork Thu Jun 29 12:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 114285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9595399vqr; Thu, 29 Jun 2023 05:20:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7C6AP8SDU5qwhqsi8FIXKdPw/T2YyGG3uvK0efXlNUz0eRY/AhPkZ4GF+Yy/be27M4TlWy X-Received: by 2002:a05:6a21:3394:b0:126:aa77:a11f with SMTP id yy20-20020a056a21339400b00126aa77a11fmr18122588pzb.6.1688041253516; Thu, 29 Jun 2023 05:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688041253; cv=none; d=google.com; s=arc-20160816; b=ciuEMNOFUtGZRUM7w8nqL+Ie2Z5/qM2PftKjnKrjlgtImHFemChg58Bgfzn0weBQid IYpC1tZgKbUzpMlDvttm6VKZlVGxfAP5+fsMqv16kLBxeFZi8Uz5OFnkFROXWpIY+4Ff m4ZXEddmHyslvYogySBbdAfpSmqcH/rw7thDcNMckwZesf6KKdSrdmecFDnK2YJJACOj KShJxVIVDqYdZwOlKSD2B9rSdM8IPC68Cx3ZMeIYuMqYlZZXskF3ysr/kQ4O+CYje6xC g9i7R0yfTCDo9c4Jve7vSOB4sd20WmeP1V+SkFmOC0K6T8pz3AUlFM/Lognbd3EOlVl8 nDxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PIs+ICQNDa5Vfiyu1UAjrg6pN938Jdy2JxIM6CdLM3k=; fh=jVO2EC1fXvr6Bl8+7yHtFIrYqo7iQ9dvd55sFdmq7po=; b=E2zbyKd0VyL2A5ZLgbROSCtzoADeOYpYn+aXbfJnfb8kcwmtoQB5cEzwn5gCB7hYei 6z8CzkrWIg8zYMJQxltS4QCYDpJqFguBr8TXCqb8DOfU8K9n74QHuKw5NZzHv+nvoXqT 8EaJCRksymc15v4xOlQlc2wxVQ1sMk1DoUV03lQcZiMXd1FUZN5IBStWZ0xTUS1r54T1 QSClUuGF+3UO26FoyfTgUwb0vAnmOUDGHekSZ/VXUHt2Ko6BKnNeFxyHJGtb43FglPuN B2TKselB+V0KtwORYfvu1kVcbfFiN7zfUd1L+cAcGHv/RYkN0pYD3xqgW8N+GosDq6g8 mbYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NFz7GpY3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a170902b49100b001b3f9cedbb7si9762999plr.398.2023.06.29.05.20.36; Thu, 29 Jun 2023 05:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NFz7GpY3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231987AbjF2MN7 (ORCPT + 99 others); Thu, 29 Jun 2023 08:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231861AbjF2MNy (ORCPT ); Thu, 29 Jun 2023 08:13:54 -0400 Received: from out-22.mta1.migadu.com (out-22.mta1.migadu.com [95.215.58.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B285A30C5 for ; Thu, 29 Jun 2023 05:13:53 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1688040831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PIs+ICQNDa5Vfiyu1UAjrg6pN938Jdy2JxIM6CdLM3k=; b=NFz7GpY3S3aV7jV8xRsur9xzqu6C4Qib21R6jTKJkpaZrJiUA8T5yvi48X0ycq/iBk6OgY 58R8Mp6ZmSf/ViThCrgmYM54zKo6r+gs/HHWzHmZhIMHtEiTN7Abue0iPQSPpEgqWoa6+B nhyB0C469Q0wFK9N6G1ka56gVityIBc= From: chengming.zhou@linux.dev To: axboe@kernel.dk, ming.lei@redhat.com, hch@lst.de, tj@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Chengming Zhou Subject: [PATCH v4 1/2] blk-mq: move data->rq_flags initialization code Date: Thu, 29 Jun 2023 20:13:01 +0800 Message-Id: <20230629121302.1124851-2-chengming.zhou@linux.dev> In-Reply-To: <20230629121302.1124851-1-chengming.zhou@linux.dev> References: <20230629121302.1124851-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770039545530196036?= X-GMAIL-MSGID: =?utf-8?q?1770039545530196036?= From: Chengming Zhou The blk_mq_rq_ctx_init() has some data->rq_flags initialization: ``` if (data->flags & BLK_MQ_REQ_PM) data->rq_flags |= RQF_PM; if (blk_queue_io_stat(q)) data->rq_flags |= RQF_IO_STAT; rq->rq_flags = data->rq_flags; ``` We will need this data->rq_flags to tell if we need start_time_ns, so we need to put these initialization in the callers of blk_mq_rq_ctx_init(). Now we basically have two callers, the 1st is general __blk_mq_alloc_requests(), the 2nd is the special blk_mq_alloc_request_hctx(). So change the 2nd caller to reuse the 1st __blk_mq_alloc_requests() to avoid code duplication. This is safe because blk_mq_alloc_request_hctx() always has BLK_MQ_REQ_NOWAIT flag, it won't go into the normal retry path when doesn't have free tag. But it indeed make the general __blk_mq_alloc_requests() more complex. Signed-off-by: Chengming Zhou --- block/blk-mq.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index decb6ab2d508..c50ef953759f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -349,11 +349,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) - data->rq_flags |= RQF_PM; - if (blk_queue_io_stat(q)) - data->rq_flags |= RQF_IO_STAT; rq->rq_flags = data->rq_flags; if (data->rq_flags & RQF_SCHED_TAGS) { @@ -447,6 +442,15 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) if (data->cmd_flags & REQ_NOWAIT) data->flags |= BLK_MQ_REQ_NOWAIT; + if (data->flags & BLK_MQ_REQ_RESERVED) + data->rq_flags |= RQF_RESV; + + if (data->flags & BLK_MQ_REQ_PM) + data->rq_flags |= RQF_PM; + + if (blk_queue_io_stat(q)) + data->rq_flags |= RQF_IO_STAT; + if (q->elevator) { /* * All requests use scheduler tags when an I/O scheduler is @@ -471,14 +475,15 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) } retry: - data->ctx = blk_mq_get_ctx(q); - data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx); + /* See blk_mq_alloc_request_hctx() for details */ + if (!data->ctx) { + data->ctx = blk_mq_get_ctx(q); + data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx); + } + if (!(data->rq_flags & RQF_SCHED_TAGS)) blk_mq_tag_busy(data->hctx); - if (data->flags & BLK_MQ_REQ_RESERVED) - data->rq_flags |= RQF_RESV; - /* * Try batched alloc if we want more than 1 tag. */ @@ -505,6 +510,7 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) * is going away. */ msleep(3); + data->ctx = NULL; goto retry; } @@ -613,16 +619,10 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, .cmd_flags = opf, .nr_tags = 1, }; - u64 alloc_time_ns = 0; struct request *rq; unsigned int cpu; - unsigned int tag; int ret; - /* alloc_time includes depth and tag waits */ - if (blk_queue_rq_alloc_time(q)) - alloc_time_ns = ktime_get_ns(); - /* * If the tag allocator sleeps we could get an allocation for a * different hardware context. No need to complicate the low level @@ -653,20 +653,10 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, goto out_queue_exit; data.ctx = __blk_mq_get_ctx(q, cpu); - if (q->elevator) - data.rq_flags |= RQF_SCHED_TAGS; - else - blk_mq_tag_busy(data.hctx); - - if (flags & BLK_MQ_REQ_RESERVED) - data.rq_flags |= RQF_RESV; - ret = -EWOULDBLOCK; - tag = blk_mq_get_tag(&data); - if (tag == BLK_MQ_NO_TAG) + rq = __blk_mq_alloc_requests(&data); + if (!rq) goto out_queue_exit; - rq = blk_mq_rq_ctx_init(&data, blk_mq_tags_from_data(&data), tag, - alloc_time_ns); rq->__data_len = 0; rq->__sector = (sector_t) -1; rq->bio = rq->biotail = NULL;