From patchwork Mon Jun 26 05:04:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 112741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7253905vqr; Sun, 25 Jun 2023 22:15:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4C2KjPU1uof7LvNiumWZP0XSdhylU6QqVglurM1Eup7/VVtOLWNEorq2O3U4CTgzsECEGp X-Received: by 2002:a17:90b:88f:b0:262:d6e9:208b with SMTP id bj15-20020a17090b088f00b00262d6e9208bmr2154122pjb.4.1687756542886; Sun, 25 Jun 2023 22:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687756542; cv=none; d=google.com; s=arc-20160816; b=xRGf+VH0xtp4NABUc3wCTLdSNibmRFKHqJ1jlLMsGdX18L9w9Yh+L94dvlsIZcETi5 VpqMdesIBquMgkh3DEmg1U2xC7zJWTCi8h1lw4AaX6qvtcNI8lpLZjwleeLYFZ86H653 qLkyIZjohefugcVcnpz8DmFM3ZRAzXahzCj61FAer+C+tTw679lubfI980H4/iBO5K1H a6FZjTvwJpoB1nDOGNcun9agz0tOcmkZ4mZzlZ8cmhp4K/EH2/W/yp22XJB5LRjfVk4M C42R5rHmGW7bllKTRg6+/CJXqmKpj/DfQM1vYDwC2OWApkxW2R+Jln0OIGHa/zGeAGiA t04w== 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=pM/RdRZgsIDACaBVp4cmgZyrhE7a7KC7/ymGEmkl5Ls=; fh=s+7/nupwQZ4a1QHaVvuQwq8RXVZrSOTBv0qS15WToQk=; b=Br++KtdQ5TaI4LK8I+xz7mO6tszDn54avBowwZ8X8Qz0q8r6QYpbFfSIrxUFFXvXRb hWqefo8LVX8ZmyMnKoP3ti0Y5S4cPAAdzqoBmapQmotQ/b0vIbWv/0QN3lZWluZK8TbG I/cseRTnPXgaMbBQ75pkz0iklXdNhtrWH3GxRWUHH0NcI/PxZ6HBcuyT4JeIERVXxRd8 FP8/TYvrPPSe+uEwdvUft3OU3SI4Pr2sg2Q2FjeQpWNdx0r9kZSv7+nCw1ledn31xtwg qL+IHZJcXuALvFDY8HyuqJZPMtc8KrD0LgJ8kRuZlPZiRdGPkViJrQoRqcgK3Uw95nAH F5+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qqmlYU33; 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 q93-20020a17090a17e600b0026130b11b7csi4512263pja.75.2023.06.25.22.15.30; Sun, 25 Jun 2023 22:15:42 -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=qqmlYU33; 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 S229541AbjFZFGG (ORCPT + 99 others); Mon, 26 Jun 2023 01:06:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjFZFGA (ORCPT ); Mon, 26 Jun 2023 01:06:00 -0400 Received: from out-11.mta0.migadu.com (out-11.mta0.migadu.com [91.218.175.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA06611C for ; Sun, 25 Jun 2023 22:05:58 -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=1687755957; 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=pM/RdRZgsIDACaBVp4cmgZyrhE7a7KC7/ymGEmkl5Ls=; b=qqmlYU33idi+L25aeu0BxjrOCMeoS6+/x3Xh4aumx5bgSi8bY5S2o+ygYcNgvpqpgGtNa2 PER3wbn148AqyWu7JR/54qzmjJA6KJa4uhXdAd+7pFyMB+quNHtv4qZLvycK+iOB8oJ8h7 ah8HEUHyzNeBz97525DRwiDkqu8MhIM= From: chengming.zhou@linux.dev To: axboe@kernel.dk, tj@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com Subject: [PATCH v2 1/3] blk-mq: always use __blk_mq_alloc_requests() to alloc and init rq Date: Mon, 26 Jun 2023 13:04:03 +0800 Message-Id: <20230626050405.781253-2-chengming.zhou@linux.dev> In-Reply-To: <20230626050405.781253-1-chengming.zhou@linux.dev> References: <20230626050405.781253-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?1769741004404752356?= X-GMAIL-MSGID: =?utf-8?q?1769741004404752356?= From: Chengming Zhou This patch is preparation for the next patch that ktime_get_ns() only once for batched pre-allocated requests start_time_ns setting. 1. data->flags is input for blk_mq_rq_ctx_init(), shouldn't update in every blk_mq_rq_ctx_init() in batched requests alloc. So put the data->flags initialization in the caller. 2. make blk_mq_alloc_request_hctx() to reuse __blk_mq_alloc_requests(), instead of directly using blk_mq_rq_ctx_init() by itself, so avoid doing the same data->flags initialization in it. After these cleanup, __blk_mq_alloc_requests() is the only entry to alloc and init rq. 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;