From patchwork Thu Nov 19 15:29:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11917945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7C88C6379D for ; Thu, 19 Nov 2020 15:33:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67FCB2225B for ; Thu, 19 Nov 2020 15:33:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AI+Zu2tR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727946AbgKSPdH (ORCPT ); Thu, 19 Nov 2020 10:33:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727944AbgKSPdH (ORCPT ); Thu, 19 Nov 2020 10:33:07 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68D4AC0613CF; Thu, 19 Nov 2020 07:33:05 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id k27so8464660ejs.10; Thu, 19 Nov 2020 07:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QHs9GIlt4UaOPU6hF2x6d6LK3yQJupb3Ug5YzgmTPR0=; b=AI+Zu2tRSFla05NeOjV7j1LuI2o+bXvtNEYsWnLGgehDDzlYH8RtG4ujs12CzTreeq CMcldJ0P17+H1FPIW9flBG0LK/89ctUlFkd0pb3TvRMkNU33WYhEdyMynG8z+318K3aV ZMoTf6XQWFk9UIhHVQcLJATlr+qoXDBee7BHFWyAYXo+VzHZiAEZxokFoOkvawZWr4tg euyhCt1MolVPLVZKHQYh1YLj9OQssVMrw1mLD8h6ahAF2eryyXd4y9yNe+kHKREkkaC3 sL/HN2Vd4hWZafDkfmEeLVY0f90JVvQxGjsE4eKKaw+vfRaSeocBUxrB8kQ0gRMfsUjO +bdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QHs9GIlt4UaOPU6hF2x6d6LK3yQJupb3Ug5YzgmTPR0=; b=Z4lQ3uoKw286OSjDMGh6TYqDkl1EWbmudX46hEnYAro9UcUAWTjVp0HF5gXO4lT1rH UaoET0RLPvjHsUvbUCWBUTF39nyznsAg70gzBh4unH+49a9U9gB0vQgE6MvJrKII4ntN uD1soc3Z5Ya4Yugwe33ED6gkuW3lCFdPgb7/C7lIACsFSWzQju3yLFTzQN6tCu1/IGWp Aje3hmnRYvogz43VGv3lyqWhGVPVw4Rl6D+FGYl/ee6043GxLY9gOmsWGg11iEMtWuyC /dhnPD/OFV8gYqbi4nRdv9FKvecNlFpB5De2GqBhx9Uyv4IYDgyCYF5uvTbSh56hOeEz LLMg== X-Gm-Message-State: AOAM533pvj9ewmR4/3DbmEBbEWLSGt/lO5cNKaBm5H4/YfnhTUHrKRMb o7yTyHNkguYJI3EBeu/LwcmlOIfurgqZ5g== X-Google-Smtp-Source: ABdhPJx6W/2Vpd3ZNwy0PWPOd9RURIuLaLFpAeAZkM3ojboamNSQ7XSusToFwza8wimIR3a2Y8arHw== X-Received: by 2002:a17:906:ca93:: with SMTP id js19mr30379533ejb.537.1605799980166; Thu, 19 Nov 2020 07:33:00 -0800 (PST) Received: from localhost.localdomain (host109-152-100-135.range109-152.btcentralplus.com. [109.152.100.135]) by smtp.gmail.com with ESMTPSA id u7sm3595612ejf.83.2020.11.19.07.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:32:59 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , linux-block@vger.kernel.org, Alexander Viro , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] iov_iter: optimise iov_iter_npages for bvec Date: Thu, 19 Nov 2020 15:29:42 +0000 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Block layer spend quite a while in iov_iter_npages(), but for bvecs number of pages is already known and stored in iter->nr_segs, so it can be returned directly as an optimisation Running an io_uring benchmark with registered buffers (i.e. bvec) perf showed ~1.5-2.0% total cycle was spent there, and that dropped to ~0.2% after applying this patch. Signed-off-by: Pavel Begunkov --- lib/iov_iter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 1635111c5bd2..0fa7ac330acf 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1594,6 +1594,8 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages) return 0; if (unlikely(iov_iter_is_discard(i))) return 0; + if (unlikely(iov_iter_is_bvec(i))) + return min_t(int, i->nr_segs, maxpages); if (unlikely(iov_iter_is_pipe(i))) { struct pipe_inode_info *pipe = i->pipe; @@ -1614,11 +1616,9 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages) - p / PAGE_SIZE; if (npages >= maxpages) return maxpages; - 0;}),({ - npages++; - if (npages >= maxpages) - return maxpages; - }),({ + 0;}), + 0 /* bvecs are handled above */ + ,({ unsigned long p = (unsigned long)v.iov_base; npages += DIV_ROUND_UP(p + v.iov_len, PAGE_SIZE) - p / PAGE_SIZE; From patchwork Thu Nov 19 15:29:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11917943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1443AC56201 for ; Thu, 19 Nov 2020 15:33:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F32B2222A for ; Thu, 19 Nov 2020 15:33:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="StPY5tN5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbgKSPdH (ORCPT ); Thu, 19 Nov 2020 10:33:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbgKSPdG (ORCPT ); Thu, 19 Nov 2020 10:33:06 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B54C0613D4; Thu, 19 Nov 2020 07:33:06 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id s25so8493207ejy.6; Thu, 19 Nov 2020 07:33:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sFYsMGmOpK2x4QIviMW7uuidVMr9J7XluhnZW1l09Wk=; b=StPY5tN5VAfKv4uWxkdpEA8p5ZVTA1L+pQ9JhBSobscj5LrYtzPM8iiEw0Zj7DA6dO 6/HjguHrscTyXFA8pM93ilRJBN69VX3ae7cXzYKZeYoA1MeaklpaOCWmDT8/dEkMIu8j satnwS2f402EMwRkLWTBdJpM7PY3cP6faAhitemb20r/MqL5dlU+jnlvp76J1OSVhcli oKAjKE2fzkrDVrq76bUHtkGpiSCCY8TNuM0qnW1jhgfdoOH5m1+RWOh41D8YvzFTi2NZ AyMcC7Tv744hnPrd2tFkGBah5U+yN36BzjehNuS0DIXdtjJPhAbFHOBmmkizq3nR2XKP HriQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sFYsMGmOpK2x4QIviMW7uuidVMr9J7XluhnZW1l09Wk=; b=lWufVpbwQz4zFs1YTzQeDUg4JmtMEVJMo5BnI3p4QP9Mj7JdwWV3Tv/ABfXQlZNC+l YsEy0P0TxZ6aUg6cjVvYuxhUYdjwU2y6u3z6Sy47HORON1+ZzyWOUDh91YMu/xnAVuoz rYhFiJjvj0rm/8rqIaQiXNq8qKGhyNtQufkcLm8CLZuIAzdbIeb+c4lOvn7J77/T4Pcd ACgfO2Jg/66DOzqcsUJx3OztUAiq/zZ//1ese/J11qfwpO9nz9MXjQIObksj0GYkhd4h hHfsYSMmwvbtQNVFSONcx2t/752TNbkmZRHJbFZBLazc19kZxvxDPzGm9vxTheobyV6V ZibQ== X-Gm-Message-State: AOAM5324lgna4Z+PnO1UoK0hBf4svShxB3WemQHdjSpR3zpYH25yCwri /njUFTeMcDwbPXCDLHlIk6wrHHqToejk/w== X-Google-Smtp-Source: ABdhPJwxuK0ZItBAQZ8zBn4p87medVgNiMcX4WT9XRG513M40yp5Q9zSbvoIIN9eN9RAkgOtQieZCg== X-Received: by 2002:a17:906:e2c3:: with SMTP id gr3mr28209617ejb.471.1605799985120; Thu, 19 Nov 2020 07:33:05 -0800 (PST) Received: from localhost.localdomain (host109-152-100-135.range109-152.btcentralplus.com. [109.152.100.135]) by smtp.gmail.com with ESMTPSA id u7sm3595612ejf.83.2020.11.19.07.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:33:04 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , linux-block@vger.kernel.org, Alexander Viro , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] iov_iter: optimise iter type checking Date: Thu, 19 Nov 2020 15:29:43 +0000 Message-Id: <9bc27cb3ef6ab49b6b2ccee3db6613838aee17af.1605799583.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The problem here is that iov_iter_is_*() helpers check types for equality, but all iterate_* helpers do bitwise ands. This confuses a compiler, so even if some cases were handled separately with iov_iter_is_*(), it can't eliminate and skip unreachable branches in following iterate*(). E.g. iov_iter_npages() first handles bvecs and discards, but iterate_all_kinds() still generate branches for them. Making checks consistent solves that. size lib/iov_iter.o before: text data bss dec hex filename 24409 805 0 25214 627e lib/iov_iter.o after: text data bss dec hex filename 23785 793 0 24578 6002 lib/iov_iter.o Signed-off-by: Pavel Begunkov --- include/linux/uio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 72d88566694e..c5970b2d3307 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -57,27 +57,27 @@ static inline enum iter_type iov_iter_type(const struct iov_iter *i) static inline bool iter_is_iovec(const struct iov_iter *i) { - return iov_iter_type(i) == ITER_IOVEC; + return iov_iter_type(i) & ITER_IOVEC; } static inline bool iov_iter_is_kvec(const struct iov_iter *i) { - return iov_iter_type(i) == ITER_KVEC; + return iov_iter_type(i) & ITER_KVEC; } static inline bool iov_iter_is_bvec(const struct iov_iter *i) { - return iov_iter_type(i) == ITER_BVEC; + return iov_iter_type(i) & ITER_BVEC; } static inline bool iov_iter_is_pipe(const struct iov_iter *i) { - return iov_iter_type(i) == ITER_PIPE; + return iov_iter_type(i) & ITER_PIPE; } static inline bool iov_iter_is_discard(const struct iov_iter *i) { - return iov_iter_type(i) == ITER_DISCARD; + return iov_iter_type(i) & ITER_DISCARD; } static inline unsigned char iov_iter_rw(const struct iov_iter *i)