From patchwork Mon Jun 26 05:04:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 112740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7253290vqr; Sun, 25 Jun 2023 22:13:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ700EwqzNohVo3xyLpznBwLP1RRevL385CeTdUwlVYL+O0h6OB0Ptt1rz7iEGNMb0d7jsw8 X-Received: by 2002:a05:6a20:3d10:b0:125:c3f7:f863 with SMTP id y16-20020a056a203d1000b00125c3f7f863mr11460457pzi.8.1687756421253; Sun, 25 Jun 2023 22:13:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687756421; cv=none; d=google.com; s=arc-20160816; b=fxjllME1kykOB4gI7O5DS+2T519m00Dp1Mebe5sPWrZ4+FofcyXMwhXYTOUvTwY19N NT99NP873mlMqf3amqPgPY1i5MYSkNGYE6YHLqa8xuQsIW30vjQK9y+1qZ4HP5vpqOEZ dkkivEAwQf3ZdPShXkFOD1xEdbcITbhASPpmygpT+Dh5WeBBBf4GYeFAQ2x++07xm6Mp cOpQQ7bMAKNvTsG3McRVFimcZht4BUgsyuWs6qxyPDEpOatjR495ZXWotFODeCcbN08p kR6L/a7voM5zqM8Ih/W0IzglBu/3J6E27deuqi8Qi3ZDYm5Ec4bmZYSCK1cAxh7Wo/tv 0upQ== 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=bQ1f0H8lujgnS2QY9KNbH8M2Bukb16RSvTZHPii0Y5I=; fh=s+7/nupwQZ4a1QHaVvuQwq8RXVZrSOTBv0qS15WToQk=; b=Uic/1zg5ILtvWfR1Q1J4XsctQ3OWt1V7z//K9gdN3BCW08b0qZMnepZiYuzN/3tLZq VXxwfQXgMsec3tOeQb0IY009DB83hSiFhiNKp7lI+GgkQxZoGNR5OKhnsdrurmLWUjXr vHFz0nj8jIjKQYg90LgodR4sXaoUdUMEG00/sURuK6+hj0iYwatlbSeNgd6B+8h41fId 4n1l95U8oKAutal9bzpLXXcBOInZAwEDmOwhZsqPhsAmPT0+LraIXMurtYOFEouLwLJ+ /+S43N7ryVWEMbh4XbP+yV20wM1QwSVUgposqWE9sia3FFDal6t0MXTOWLfzxCEpUi02 r2Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=lvw7E9kn; 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 185-20020a6308c2000000b0053f7fcd4705si4388845pgi.541.2023.06.25.22.13.28; Sun, 25 Jun 2023 22:13:41 -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=lvw7E9kn; 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 S229619AbjFZFGR (ORCPT + 99 others); Mon, 26 Jun 2023 01:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjFZFGI (ORCPT ); Mon, 26 Jun 2023 01:06:08 -0400 Received: from out-27.mta0.migadu.com (out-27.mta0.migadu.com [91.218.175.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9892912D for ; Sun, 25 Jun 2023 22:06:06 -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=1687755963; 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=bQ1f0H8lujgnS2QY9KNbH8M2Bukb16RSvTZHPii0Y5I=; b=lvw7E9knFolsCy1ySMPIvpFMBrc7UR0e6MThfgqnPdjxDNnCU7/EjXABj2lUVUuWS8Coh3 RjIsc8pcy0woXf34Kpr/XsRT/oSF6zr1BCff+csDOdEI248UxN68j6UlvH0Nfe1wjVPHS+ JrfpuqDXNxNpmkEpLr/jNAqFPuLCBnE= 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 3/3] blk-mq: fix start_time_ns and alloc_time_ns for pre-allocated rq Date: Mon, 26 Jun 2023 13:04:05 +0800 Message-Id: <20230626050405.781253-4-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=unavailable 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?1769740451704387189?= X-GMAIL-MSGID: =?utf-8?q?1769740877483407341?= From: Chengming Zhou The iocost rely on rq start_time_ns and alloc_time_ns to tell saturation state of the block device. Most of the time request is allocated after rq_qos_throttle() and its alloc_time_ns or start_time_ns won't be affected. But for plug batched allocation introduced by the commit 47c122e35d7e ("block: pre-allocate requests if plug is started and is a batch"), we can rq_qos_throttle() after the allocation of the request. This is what the blk_mq_get_cached_request() does. In this case, the cached request alloc_time_ns or start_time_ns is much ahead if blocked in any qos ->throttle(). This patch fix it by setting alloc_time_ns and start_time_ns to now when the pre-allocated rq is actually used. Note we don't skip setting alloc_time_ns and start_time_ns for all pre-allocated rq, since the first returned rq still need to be set. Signed-off-by: Chengming Zhou --- block/blk-mq.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 8b981d0a868e..6a3f1b8aaad8 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -337,6 +337,24 @@ void blk_rq_init(struct request_queue *q, struct request *rq) } EXPORT_SYMBOL(blk_rq_init); +/* Set rq alloc and start time when pre-allocated rq is actually used */ +static inline void blk_mq_rq_time_init(struct request_queue *q, struct request *rq) +{ + if (blk_mq_need_time_stamp(rq->rq_flags)) { + u64 now = ktime_get_ns(); + +#ifdef CONFIG_BLK_RQ_ALLOC_TIME + /* + * alloc time is only used by iocost for now, + * only possible when blk_mq_need_time_stamp(). + */ + if (blk_queue_rq_alloc_time(q)) + rq->alloc_time_ns = now; +#endif + rq->start_time_ns = now; + } +} + static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, struct blk_mq_tags *tags, unsigned int tag, u64 alloc_time_ns, u64 start_time_ns) @@ -575,6 +593,7 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q, return NULL; plug->cached_rq = rq_list_next(rq); + blk_mq_rq_time_init(q, rq); } rq->cmd_flags = opf; @@ -2896,6 +2915,7 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q, plug->cached_rq = rq_list_next(rq); rq_qos_throttle(q, *bio); + blk_mq_rq_time_init(q, rq); rq->cmd_flags = (*bio)->bi_opf; INIT_LIST_HEAD(&rq->queuelist); return rq;