Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18872909rwd; Wed, 28 Jun 2023 01:42:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45neDCtMUJrP8e4pFYKpNmAZhbHqh2sPT8u6HzaAOFpL6K0rTLhre4NmX1gY1xuc3erh5t X-Received: by 2002:a17:907:8a0c:b0:992:48b7:99e3 with SMTP id sc12-20020a1709078a0c00b0099248b799e3mr2540894ejc.63.1687941733799; Wed, 28 Jun 2023 01:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687941733; cv=none; d=google.com; s=arc-20160816; b=tPXgutjyV2O1qjOZ+OoE/HXbrT7jZaIZeyBrqs/TTkYer0aG1cq/rYoEZuZITpSxp1 FdypC3qccezf77e5FYE+oFHnZhQRk3t0nJgrgmnF+3PCVb6k8ZyTfjKtYfjosjDiYxrh nr5+T/KL1VoBBPls7OGzH+UOEmhGsZTPhSqD61ZvUENdYM6lOYAi/4D+3fJ4viPz9A0K zjSQrX0DrGf/R4tMAnlL8gVnD/4sXsAZ+MRbTr+lOKlCwv4Un2sM8vHVj/3UlxNr5bOj OWvtjTDks5RIpQROpdfx1vIUQuUn9LxgaVtT4O4+w/4kiKEyrJbDD1q0kX7PSzud7kXN AuAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Z1KUy+mSETB0Ymbiz3MZDrs6ZOWnVr5ABuTlCCBNInE=; fh=gcgu5dva3NJ4mdVZ7eyEyDdd9760tn9hGlEMsydy2zU=; b=U8bWX4uxkwbGljYgynmfcpGKleWV2SvtbJsRY6TO6pOSgixX20sQbh6aWFktLCHTJi yC9xjVfvi+Y6jzJY/3CjI3zbBRJsDFkNzumO4IjSXib4hhFSLlTyFT+n4dRuRTdVgF+S pH+xxJmSLT9Z5Zdw13/kfoyVXz17kvenKpHB2SPug65llvBzRZSVelnx8fLTWwKhjdf0 IrMMv1OoldIq86NfjjonXxzTkhEH1ztZzKZD+RxzQKgb280LTk3MgmqBPErGUYb7zxoA b2B5cMdAPYbdL/uqCPCrW8QZa2nOXgAwftjThl/B+/MW0Rk6oaO+eYyf2WnSaYwoW9O1 My/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S3tqJeTc; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w6-20020a17090633c600b00988994251edsi5447111eja.258.2023.06.28.01.41.49; Wed, 28 Jun 2023 01:42:13 -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=@redhat.com header.s=mimecast20190719 header.b=S3tqJeTc; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233999AbjF1IVg (ORCPT + 99 others); Wed, 28 Jun 2023 04:21:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32250 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234270AbjF1IP1 (ORCPT ); Wed, 28 Jun 2023 04:15:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687940076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Z1KUy+mSETB0Ymbiz3MZDrs6ZOWnVr5ABuTlCCBNInE=; b=S3tqJeTclGtKSCj1KDso5UE0hinm13urRDY2nXdqGLYfta4B3Lq+gDI3X4sv/PZoboVyZh zv/hmleOmlkB3l5L9r6s2o+5Wgl3Ml8CMzqbAgIZuXHxdUGb22dkqFcnH7UQWICdd727j3 N3HekIW1wT4oDMC9qGPnWO6g7M/nDHg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-398-PNS-UaNNObak31gAYQU7LQ-1; Wed, 28 Jun 2023 00:13:47 -0400 X-MC-Unique: PNS-UaNNObak31gAYQU7LQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9C1F61C04B55; Wed, 28 Jun 2023 04:13:46 +0000 (UTC) Received: from ovpn-8-21.pek2.redhat.com (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C68B8111F3B0; Wed, 28 Jun 2023 04:13:25 +0000 (UTC) Date: Wed, 28 Jun 2023 12:13:20 +0800 From: Ming Lei To: chengming.zhou@linux.dev Cc: axboe@kernel.dk, tj@kernel.org, hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com Subject: Re: [PATCH 2/4] blk-flush: count inflight flush_data requests Message-ID: References: <20230627120854.971475-1-chengming.zhou@linux.dev> <20230627120854.971475-3-chengming.zhou@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230627120854.971475-3-chengming.zhou@linux.dev> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 27, 2023 at 08:08:52PM +0800, chengming.zhou@linux.dev wrote: > 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 a u64 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 a u64 counter is good. The only problem I can > think of is that u64 counter may overflow, which should be unlikely happen. It won't overflow, q->nr_requests is 'unsigned long', which should have been limited to one more reasonable value, such as 2 * BLK_MQ_MAX_DEPTH, so u16 should be big enough in theory. > > Signed-off-by: Chengming Zhou > --- > 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 dba392cf22be..bb7adfc2a5da 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_tail(&rq->queuelist, &q->flush_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_POSTFLUSH; > 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; > }; The part of replacing inflight data rq list with counter looks fine. Thanks, Ming