From patchwork Mon Jul 10 06:47:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13306319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1432EB64D9 for ; Mon, 10 Jul 2023 06:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231944AbjGJGro (ORCPT ); Mon, 10 Jul 2023 02:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230284AbjGJGrn (ORCPT ); Mon, 10 Jul 2023 02:47:43 -0400 Received: from out-54.mta0.migadu.com (out-54.mta0.migadu.com [IPv6:2001:41d0:1004:224b::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DC53E6 for ; Sun, 9 Jul 2023 23:47:40 -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=1688971659; 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; bh=YsPE8Ph2i63iXfOKdYTTEJ0Ca9a6Ddgy8hiayl5gTk0=; b=cuhHBIOJFOhrK+U5yrcp1YrFeAYfgbRaVbi8wFSIIzRiiGXomhszlXZtXWc7bW8MiaoKu1 H5YLR+XnbL0xBwrUoV4G2YBymHze1pRvf6IGkzG0lFOIFELKWgLKMD6LfGfZqu4ShmuHbt J1XrC5UgdJZ4fDCmyqOnFNlJYPeO3os= From: chengming.zhou@linux.dev To: axboe@kernel.dk, hch@lst.de, ming.lei@redhat.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com Subject: [PATCH 1/2] blk-flush: fix rq->flush.seq for post-flush requests Date: Mon, 10 Jul 2023 14:47:04 +0800 Message-ID: <20230710064705.1847287-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Chengming Zhou If the policy == (REQ_FSEQ_DATA | REQ_FSEQ_POSTFLUSH), it means that the data sequence and post-flush sequence need to be done for this request. The rq->flush.seq should record what sequences have been done (or don't need to be done). So in this case, pre-flush doesn't need to be done, we should init rq->flush.seq to REQ_FSEQ_PREFLUSH not REQ_FSEQ_POSTFLUSH. Of course, this doesn't cause any problem in fact, since pre-flush and post-flush sequence do the same thing for now. But we'd better fix this value, and the next patch will depend on this value to be correct. Signed-off-by: Chengming Zhou Reviewed-by: Christoph Hellwig --- block/blk-flush.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-flush.c b/block/blk-flush.c index 4826d2d61a23..094a6adb2718 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -448,7 +448,7 @@ bool blk_insert_flush(struct request *rq) * the post flush, and then just pass the command on. */ blk_rq_init_flush(rq); - rq->flush.seq |= REQ_FSEQ_POSTFLUSH; + rq->flush.seq |= REQ_FSEQ_PREFLUSH; spin_lock_irq(&fq->mq_flush_lock); fq->flush_data_in_flight++; spin_unlock_irq(&fq->mq_flush_lock); From patchwork Mon Jul 10 06:47: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: 13306320 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 766FCEB64D9 for ; Mon, 10 Jul 2023 06:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232068AbjGJGrs (ORCPT ); Mon, 10 Jul 2023 02:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232055AbjGJGrq (ORCPT ); Mon, 10 Jul 2023 02:47:46 -0400 Received: from out-24.mta0.migadu.com (out-24.mta0.migadu.com [91.218.175.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80E468E for ; Sun, 9 Jul 2023 23:47:43 -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=1688971661; 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=hFHrBB4bko1T7CcipHLq8zzquXX/o6IDfKwmotZ7GxM=; b=DIySGC8GNDHey1wTOKKSQIMH13DY+utpZiE8x/xYUw9o5HGuPML6lnZyjimxk/DUpvkqyY TXi4E3QDQxoIl3DVh3fzjTK1Z87y4Si/e9X84usuuoHvKlPo5BvCpk1Vm6qDEwUO6uYzNh iWuOIONcFgIAsU1k7wL6i4n1Owzvi30= From: chengming.zhou@linux.dev To: axboe@kernel.dk, hch@lst.de, ming.lei@redhat.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com Subject: [PATCH 2/2] blk-flush: don't need to end rq twice for non post-flush requests Date: Mon, 10 Jul 2023 14:47:05 +0800 Message-ID: <20230710064705.1847287-2-chengming.zhou@linux.dev> In-Reply-To: <20230710064705.1847287-1-chengming.zhou@linux.dev> References: <20230710064705.1847287-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Chengming Zhou Now we unconditionally blk_rq_init_flush() to replace rq->end_io to make rq return twice back to the flush state machine for post-flush. Obviously, non post-flush requests don't need it, they don't need to end request twice, so they don't need to replace rq->end_io callback. And the same for requests with the FUA bit on hardware with FUA support. So we move blk_rq_init_flush() to REQ_FSEQ_DATA stage and only replace rq->end_io if it needs post-flush. Otherwise, it can end like normal request and doesn't need to return back to the flush state machine. There are also some other good points: 1. all requests on hardware with FUA support won't have post-flush, so all of them don't need to end twice. 2. non post-flush requests won't have RQF_FLUSH_SEQ rq_flags set, so they can merge like normal requests. 3. we don't account non post-flush requests in flush_data_in_flight, since there is no point to defer pending flush for these requests. Signed-off-by: Chengming Zhou --- block/blk-flush.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/block/blk-flush.c b/block/blk-flush.c index 094a6adb2718..1b92654e8757 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -93,6 +93,7 @@ enum { static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq, blk_opf_t flags); +static void blk_rq_init_flush(struct request *rq); static inline struct blk_flush_queue * blk_get_flush_queue(struct request_queue *q, struct blk_mq_ctx *ctx) @@ -187,7 +188,15 @@ static void blk_flush_complete_seq(struct request *rq, break; case REQ_FSEQ_DATA: - fq->flush_data_in_flight++; + /* + * Only for requests that need post-flush, + * we need to do rq->end_io replacement trick + * to return back to the flush state machine. + */ + if (!(rq->flush.seq & REQ_FSEQ_POSTFLUSH)) { + blk_rq_init_flush(rq); + fq->flush_data_in_flight++; + } spin_lock(&q->requeue_lock); list_move_tail(&rq->queuelist, &q->flush_list); spin_unlock(&q->requeue_lock); @@ -202,7 +211,13 @@ static void blk_flush_complete_seq(struct request *rq, * normal completion and end it. */ list_del_init(&rq->queuelist); - blk_flush_restore_request(rq); + /* + * Only for requests that had rq->end_io replaced, + * we need to restore rq->end_io and make it a normal + * request before the second end. + */ + if (rq->rq_flags & RQF_FLUSH_SEQ) + blk_flush_restore_request(rq); blk_mq_end_request(rq, error); break; @@ -389,7 +404,6 @@ static enum rq_end_io_ret mq_flush_data_end_io(struct request *rq, static void blk_rq_init_flush(struct request *rq) { - rq->flush.seq = 0; rq->rq_flags |= RQF_FLUSH_SEQ; rq->flush.saved_end_io = rq->end_io; /* Usually NULL */ rq->end_io = mq_flush_data_end_io; @@ -424,6 +438,7 @@ bool blk_insert_flush(struct request *rq) * the request accounting. */ rq->cmd_flags |= REQ_SYNC; + rq->flush.seq = 0; switch (policy) { case 0: @@ -458,7 +473,6 @@ bool blk_insert_flush(struct request *rq) * Mark the request as part of a flush sequence and submit it * for further processing to the flush state machine. */ - blk_rq_init_flush(rq); spin_lock_irq(&fq->mq_flush_lock); blk_flush_complete_seq(rq, fq, REQ_FSEQ_ACTIONS & ~policy, 0); spin_unlock_irq(&fq->mq_flush_lock);