Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3086740pxb; Mon, 18 Oct 2021 08:00:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsLxjqV1dg6KP92ovQnqml3CfOfF/U8ePlwul/w3v+iKsB95V3frA5wAxrTRdQLqJQtWod X-Received: by 2002:a05:6402:2554:: with SMTP id l20mr45214407edb.322.1634569241551; Mon, 18 Oct 2021 08:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634569241; cv=none; d=google.com; s=arc-20160816; b=a+zf1KkIdudh9kpzQ5eurrAD3fNUWSm8DIWXvMWeBi/kKl3zNWsgFED+ni45LHJZOa /jVJLyryuuoUfb8e/R/A5yaRPhZNhNMbYLbw7j3ens4Go4Oou+blYC5blSCcQPuJoZQw l1MfqENQZkcVrlwnJuk2AvdZWC6qWqobf7ECqG1TLyUPF20UDJqrRlhXlECy5dxGQUpD b1t/CGyiKnPtsBzFrecaj+T4UjxJPq6u+gED7ZFnQoSc+CY7P4K/hKyIVgZIQVqFNpCs 9HQ/HEU/90k6Xf/doeThsWDAVdHrcASTRToJaNRSkdy4mst2yriRNSsA6Fv9VCykhY0h 2X0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=Hdr2dRLUt3IvmtpjSWHuCnzGrEz+FDPlFqvXtc4t0b4=; b=VV1fsS9LIpkZmorVaLJLxXxkgf6SUyzMSb1yV9WBhRpVV9tQ2IdO7uiw+du18Y6/7m xBagI1evsL4ovxhFlUouHxO7gzbU71WP5yEfuVv48KdpCxnbDs9VN0QVgnETDVlzKy9r 5UT8aKJ9eEbK0fhJF4DpCMfsIwJPwS0B1uhB+qgzC3WY2g3BcSlesFndpdLKd5ONh/uK gYcMN10bW2yeUpb4UYKXGd5PEP4jhhCMCDBHfA+nG5j9AvOcfsBVJYq3Dm0lm5io1hXT zDimZ2vMD2itw9RUjC2TgCcnNyAvjloLcfwawGCIY6hPlmqtP4YgMwygCr2ndaGzVrRK dyUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=q4AkAROi; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z17si31829243edd.257.2021.10.18.08.00.17; Mon, 18 Oct 2021 08:00:41 -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; dkim=fail header.i=@gmail.com header.s=20210112 header.b=q4AkAROi; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233106AbhJRO6m (ORCPT + 99 others); Mon, 18 Oct 2021 10:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232955AbhJRO6c (ORCPT ); Mon, 18 Oct 2021 10:58:32 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD225C06161C; Mon, 18 Oct 2021 07:56:20 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id o184so4615291iof.6; Mon, 18 Oct 2021 07:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hdr2dRLUt3IvmtpjSWHuCnzGrEz+FDPlFqvXtc4t0b4=; b=q4AkAROiUzc7bXDfhBGMPCHYeQUZqb3uJ6oZABhYhcL65oepI+NFIfsXEhXSS/7HU2 O/zpepFWtjfGD2Rb890Uk+A2nOkal516mf9J578pjQqWXfbI/AdbYgZe34OpOwDJ7YAV xryaon1FTUoLmtAA/l5rg3bqLSYje1LTicxWieABh9ujPGXy0drf2jxJw/mvI2sQOeua w/kUlK5QiIrPsbDmlWQIwmHybLngAeoz9sIDc3DpZB8/GZLT33pX/LZYgzwZ+lsHZBfi a1vkjfTuZVIM/H3GcGkDWlPzwQdhRsCvh+yYTh/JU/tDNizzaPj6V7yYchliOfJEqPIM z+8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hdr2dRLUt3IvmtpjSWHuCnzGrEz+FDPlFqvXtc4t0b4=; b=jFeZeVK6nuP8N1yZ6BH9OVp0dh5IK9V4/R8nbzYtgmLTkHsKbLfFLxwB5SnvhpiAPl uSUE7NELIIGgd1aF/TCyBqSqZi50HrBXApJmLKVyB9Po9xOmoql7D0KcBrtBTgsr0TAq aXiWLnjHccx6AYG5NXUic5x6LNNVJjCq1MRTnRmyBbae2J0yL2nYyGx+EHUDbeMRcjtp gK0Sq1bLMpmwzhY+vy/wjdBSpbkunD2KXHS1f4IZPTXBLUq3JWCSWwA9657H9BoHmJmN D5zOhTrOkYdlWRlIs7UpYcTi+khxrJESSraGK6aazROuIAHoSD02ttZX3RzNErgPgoeN zOCA== X-Gm-Message-State: AOAM532HTngAwz/cGSwhbfS1Wr6n4TrqESomnDdjdka2Y5135IqeWYQ5 UbRk16yitYwEZ88Oib7gi9sAQtDncEQ= X-Received: by 2002:a05:6638:3052:: with SMTP id u18mr175359jak.148.1634568980317; Mon, 18 Oct 2021 07:56:20 -0700 (PDT) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id r24sm6867968ioa.5.2021.10.18.07.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 07:56:20 -0700 (PDT) From: Noah Goldstein Cc: goldstein.w.n@gmail.com, axboe@kernel.dk, asml.silence@gmail.com, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] fs/io_uring: Hoist ret2 == -EAGAIN check in tail of io_write Date: Mon, 18 Oct 2021 10:56:13 -0400 Message-Id: <20211018145613.22186-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20211018070242.20325-1-goldstein.w.n@gmail.com> References: <20211018070242.20325-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- fs/io_uring.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index d1e672e7a2d1..18293407e8bc 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3648,21 +3648,19 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags) */ if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT)) ret2 = -EAGAIN; - /* no retry on NONBLOCK nor RWF_NOWAIT */ - if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT)) - goto done; - if (!force_nonblock || ret2 != -EAGAIN) { - /* IOPOLL retry should happen for io-wq threads */ - if (ret2 == -EAGAIN && (req->ctx->flags & IORING_SETUP_IOPOLL)) - goto copy_iov; -done: + + if (ret2 != -EAGAIN || + /* no retry on NONBLOCK nor RWF_NOWAIT */ + (req->flags & REQ_F_NOWAIT) + /* IOPOLL retry should happen for io-wq threads */ + || (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))) { kiocb_done(kiocb, ret2, issue_flags); } else { copy_iov: iov_iter_restore(&s->iter, &s->iter_state); ret = io_setup_async_rw(req, iovec, s, false); return ret ?: -EAGAIN; - } +} out_free: /* it's reportedly faster than delegating the null check to kfree() */ if (iovec) -- 2.29.2