From patchwork Mon Jul 17 04:00:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 121032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp893516vqt; Sun, 16 Jul 2023 21:04:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHthZ7e3eUUaYBemgXltFmg5ry6kX4imTSvea63Pu/xloTnbFuj4J7QaTMpycmmJlwRKjZj X-Received: by 2002:a2e:b0d0:0:b0:2b7:25b2:e37a with SMTP id g16-20020a2eb0d0000000b002b725b2e37amr9607492ljl.44.1689566666563; Sun, 16 Jul 2023 21:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689566666; cv=none; d=google.com; s=arc-20160816; b=IBpQs3+swyxcOiWBKwKRePXj0knh2O1/wIgvDOD3aR/9K/GWhSCiGqwWsXj+5QBWwX X2UdxHfEVN6bqOH+7qvtgAJ/YIPoF35af8Y3RFNlYpUX8kta92AgWkCUOoSsrGhfn+Sl jALHoJMX2+XOH5BJT5WNjDZVCVfXvpc/tM/Tg46FYbUaUFx4hoNE9+q9LE+GmzTSRSLl yarHvPE/0s2N4DlpCXV7oVXXRUrU+vmPTLN7navgRyRa1VfvgrBTnrpN6HAz3CXzQulQ 4bgkI30w7AemVxNby46Ce1EafEGDjpylG/SxPizYc9L1uvt0uqx5hM69bUbUH/WcL7X1 i7WQ== 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=vDpuVCWvXzou2B7OXWC1deh3uuUZ5lSIACnNEl46ljk=; fh=o3CILnJq08Htpby3w3Eph3505qyaosLn1T+ze21qfHQ=; b=YVSVEvxUcjbTVSIqLGbdv2Pa4xYRSWz3sQ9EBs9Own4II0X2LwCrwFFPv3WwJvk/HJ soCl4D0aiPVmkLTj29TvNUdAHQni0rcs9U+FVMt4PQJ5nFrLtl3ulnw1f4CI4An2zR/R 3JK6YVcq2kh1A6/d6lsrrFjM+V4lUAQj1SXU/ZuH5QzkG9yAhuR9Vwm0DZFAUljBASe0 e+fG2gqK9wQcI4KRPUy79WSCR2Rc6OgW+KGsiUj/YmKa6XeYGKWj7PAYG9jooxN6O0I3 Bks4LjHdS8JKEHnIwNqsq0otCFkFNYxR2UogxCq2mjHE3ODA6mi8rMvCNdPyhLpQ3AAD iSpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gpKgExO2; 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 i17-20020a170906115100b0098dcadb4002si11839923eja.492.2023.07.16.21.04.02; Sun, 16 Jul 2023 21:04:26 -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=gpKgExO2; 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 S231218AbjGQECI (ORCPT + 99 others); Mon, 17 Jul 2023 00:02:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjGQEB4 (ORCPT ); Mon, 17 Jul 2023 00:01:56 -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 21104E6B for ; Sun, 16 Jul 2023 21:01:48 -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=1689566506; 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=vDpuVCWvXzou2B7OXWC1deh3uuUZ5lSIACnNEl46ljk=; b=gpKgExO2AR+T/Bj9kjyrPBzUoeybLo9OrrTg5UdcGIDGxeXfbzRBk9yEwPT5OaFDuNmzs/ G0ZGilzX2aVZLRlwQRBq6A8xKzQ3fhBTHG/jP+A3OzV4gShsa4bY4zJvPlVNVYWVECW1WF LZVjRGhopjLHLNIyAeglKcuZDCurIeY= From: chengming.zhou@linux.dev To: axboe@kernel.dk, ming.lei@redhat.com, hch@lst.de, bvanassche@acm.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com Subject: [PATCH v4 3/4] blk-flush: count inflight flush_data requests Date: Mon, 17 Jul 2023 12:00:57 +0800 Message-ID: <20230717040058.3993930-4-chengming.zhou@linux.dev> In-Reply-To: <20230717040058.3993930-1-chengming.zhou@linux.dev> References: <20230717040058.3993930-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,RCVD_IN_DNSWL_BLOCKED, 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: INBOX X-GMAIL-THRID: 1771639056655047112 X-GMAIL-MSGID: 1771639056655047112 From: Chengming Zhou The flush state machine use a double list to link all inflight flush_data requests, to avoid issuing separate post-flushes for these flush_data requests which shared PREFLUSH. So we can't reuse rq->queuelist, this is why we need rq->flush.list In preparation of the next patch that reuse rq->queuelist for flush state machine, we change the double linked list to unsigned long counter, which count all inflight flush_data requests. This is ok since we only need to know if there is any inflight flush_data request, so unsigned long counter is good. Signed-off-by: Chengming Zhou Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig --- block/blk-flush.c | 9 +++++---- block/blk.h | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/blk-flush.c b/block/blk-flush.c index fdc489e0ea16..fedb39031647 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -187,7 +187,8 @@ static void blk_flush_complete_seq(struct request *rq, break; case REQ_FSEQ_DATA: - list_move_tail(&rq->flush.list, &fq->flush_data_in_flight); + list_del_init(&rq->flush.list); + fq->flush_data_in_flight++; spin_lock(&q->requeue_lock); list_add(&rq->queuelist, &q->requeue_list); spin_unlock(&q->requeue_lock); @@ -299,7 +300,7 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq, return; /* C2 and C3 */ - if (!list_empty(&fq->flush_data_in_flight) && + if (fq->flush_data_in_flight && time_before(jiffies, fq->flush_pending_since + FLUSH_PENDING_TIMEOUT)) return; @@ -374,6 +375,7 @@ static enum rq_end_io_ret mq_flush_data_end_io(struct request *rq, * the comment in flush_end_io(). */ spin_lock_irqsave(&fq->mq_flush_lock, flags); + fq->flush_data_in_flight--; blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error); spin_unlock_irqrestore(&fq->mq_flush_lock, flags); @@ -445,7 +447,7 @@ bool blk_insert_flush(struct request *rq) blk_rq_init_flush(rq); rq->flush.seq |= REQ_FSEQ_PREFLUSH; spin_lock_irq(&fq->mq_flush_lock); - list_move_tail(&rq->flush.list, &fq->flush_data_in_flight); + fq->flush_data_in_flight++; spin_unlock_irq(&fq->mq_flush_lock); return false; default: @@ -496,7 +498,6 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size, INIT_LIST_HEAD(&fq->flush_queue[0]); INIT_LIST_HEAD(&fq->flush_queue[1]); - INIT_LIST_HEAD(&fq->flush_data_in_flight); return fq; diff --git a/block/blk.h b/block/blk.h index 608c5dcc516b..686712e13835 100644 --- a/block/blk.h +++ b/block/blk.h @@ -15,15 +15,14 @@ struct elevator_type; extern struct dentry *blk_debugfs_root; struct blk_flush_queue { + spinlock_t mq_flush_lock; unsigned int flush_pending_idx:1; unsigned int flush_running_idx:1; blk_status_t rq_status; unsigned long flush_pending_since; struct list_head flush_queue[2]; - struct list_head flush_data_in_flight; + unsigned long flush_data_in_flight; struct request *flush_rq; - - spinlock_t mq_flush_lock; }; bool is_flush_rq(struct request *req);