Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2946235pxb; Mon, 18 Oct 2021 05:20:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzE12UhSEFEJxZo+3hHhB0ObefUltcLLhauhEi5oa6XDGL90c5fD0tKjhGK+An1ocDNWSTK X-Received: by 2002:a63:4f57:: with SMTP id p23mr23407179pgl.376.1634559631594; Mon, 18 Oct 2021 05:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634559631; cv=none; d=google.com; s=arc-20160816; b=aLw0ZYfQucEixE/f5jZ9whi3b3RIynzARarmw8h1Mh5AHPXi8NrAUQNVgSAeXLbZMr D1lh/tHR6PPp+QrKmBZHDq0G34snq9Fu1CLcKDDKPlh2mKUdrgyttxa57JPtU1AhbP1a k29n4LWeMYOUGc+gSA9bdna0B3stc53PB52TYPXkC/zsw+YsDDzwnfJNe5dEcg2yaPdP 9BrVR606DuCaAuFOQJw4fbobnPsD/z6wbPZFsh2nyHsaFmASVwYQFsJgk3fQ75ufhy+D PLx1diqS3BxHeNZWj58Un1CGGknOVsg8Qkdwbmmy0fb9VGBsLhqhspjg/nxna0fAGDDR vm1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=+uUVF0ufBrqDr/nJK7Z5GT5PPudhjxo3QmlnZ8FkmEc=; b=hSRD34w2ia9m0T6DPBIvt3c973i+mrm1xpk+p9KYfs7Rz5pTU3gzAFXSzIQcKV2qpk Ez/9O/CZUYjVj9tUISv1UFlsQRtDGFpEVv+26mpg9hoBUMO5o6qnanSjJ4744f4yUHiS rSiBNgvkfzqOgQA0cumOuHLI3PnqXKerPAEewwrvCZ6C8bHdWUnFGt0nIVbZia1kKkcx wN+ITuj8y/glMyIe7JKKtE0wwqglVnWzl86s5L+Il1ChYlucXdY+0aDu273VF5GTDNLL DJBgFVRcKvQtUy7Z0oq3c9ZVfGQxZHKZVF84b9JTTbTiSEwrVAyiItxP4eI6I/BmsdCp G5ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si28439440pjq.55.2021.10.18.05.20.18; Mon, 18 Oct 2021 05:20:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231503AbhJRMUL (ORCPT + 99 others); Mon, 18 Oct 2021 08:20:11 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:51819 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbhJRMUK (ORCPT ); Mon, 18 Oct 2021 08:20:10 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R231e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=haoxu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UsfKwST_1634559477; Received: from B-25KNML85-0107.local(mailfrom:haoxu@linux.alibaba.com fp:SMTPD_---0UsfKwST_1634559477) by smtp.aliyun-inc.com(127.0.0.1); Mon, 18 Oct 2021 20:17:57 +0800 Subject: Re: [PATCH v1] fs/io_uring: Hoist ret2 == -EAGAIN check in tail of io_write To: Noah Goldstein Cc: axboe@kernel.dk, asml.silence@gmail.com, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <20211018070242.20325-1-goldstein.w.n@gmail.com> From: Hao Xu Message-ID: Date: Mon, 18 Oct 2021 20:17:57 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211018070242.20325-1-goldstein.w.n@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/10/18 下午3:02, Noah Goldstein 写道: > This commit reorganizes the branches in the tail of io_write so that > the 'ret2 == -EAGAIN' check is not repeated and done first. > > The previous version was duplicating the 'ret2 == -EAGAIN'. As well > 'ret2 != -EAGAIN' gurantees the 'done:' path so it makes sense to > move that check to the front before the likely more expensive branches > which require memory derefences. > > Signed-off-by: Noah Goldstein > --- > Generally I would want to rewrite this as: > ``` > if (ret2 != -EAGAIN > || (req->flags & REQ_F_NOWAIT) > || (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))) > kiocb_done(kiocb, ret2, issue_flags); > else { > ... > ``` To me, this one is clear enough and short, but I think better to: if (ret2 != -EAGAIN || (req->flags & REQ_F_NOWAIT) || (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL)) if the first line doesn't exceed the line limit. Reviewed-by: Hao Xu > > But the style of the file seems to be to use gotos. If the above is > prefereable, let me know and I'll post a new version. > fs/io_uring.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index d1e672e7a2d1..932fc84d70d3 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -3648,12 +3648,15 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags) > */ > if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT)) > ret2 = -EAGAIN; > + > + if (ret2 != -EAGAIN) > + goto done; > /* no retry on NONBLOCK nor RWF_NOWAIT */ > - if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT)) > + if (req->flags & REQ_F_NOWAIT) > goto done; > - if (!force_nonblock || ret2 != -EAGAIN) { > + if (!force_nonblock) { > /* IOPOLL retry should happen for io-wq threads */ > - if (ret2 == -EAGAIN && (req->ctx->flags & IORING_SETUP_IOPOLL)) > + if (req->ctx->flags & IORING_SETUP_IOPOLL) > goto copy_iov; > done: > kiocb_done(kiocb, ret2, issue_flags); >