From patchwork Thu Nov 19 23:24:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11919191 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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 65F59C6379F for ; Thu, 19 Nov 2020 23:28:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 256CD2145D for ; Thu, 19 Nov 2020 23:28:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jLyRdwi8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbgKSX16 (ORCPT ); Thu, 19 Nov 2020 18:27:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726123AbgKSX15 (ORCPT ); Thu, 19 Nov 2020 18:27:57 -0500 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF33BC0613CF; Thu, 19 Nov 2020 15:27:56 -0800 (PST) Received: by mail-ej1-x641.google.com with SMTP id i19so10313667ejx.9; Thu, 19 Nov 2020 15:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vG0la9jq/M1aNuNVjI3CB3YTuTYiHqFptMWAHHu2/GY=; b=jLyRdwi89tUGez6ZXP1Zywcgv/TYl9a3cfj3c82Sur0K7xQFtnLPahePEpIYWZDVdF 7kvhQAGbvUH17EwLsLHkIZZFl0BGshnpbFpvKVJkNRq2X1aeikzGVMRhcPABOdxdMGpx TzCJ94gKzQqJ3B1FBH8wCMAQkDkOW5itOgxtv/NjfOBzzM7SBE9NvKbI9e7g2GnRyHrN 95l3s4xCF8TWXAOoC/ZYStJ5sXeiw41DXYWTQvoKj9IIjYB56ePcXTw/FaIqsHwBAFjp YYctGqoBLXIs4wOAqrnyRWDxMPhWkXs+g55kmStCfqOt3jsWP4b3amGodWCJTJb0TD// yG9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vG0la9jq/M1aNuNVjI3CB3YTuTYiHqFptMWAHHu2/GY=; b=MtMdY9427WIioUBm4ozazEJKhcnLN/5FkF9PJRuoFdENIaWEyuZYt1SXhz/u5blNAw OIe3LKh7UteWshh9ty7HAR45pWu9cEdOAcvcJESWk5920ija1sQpI4TKy25wfBAofO4h RpVe1vAtRLno8Yt2LcdL7ZJQ9g4KFgwJKcsIJ4qrpmcHITVWaYFLyjxTwL84ram/YAYu Wu3fmQ14jYCgOCYo45feqL0L7AXH3n4otTxCxxa8T17LktiC6RzaNztxwqloIBlwNhQP 3pz7Bf89q7QII4WVg4v8EE5cKfhezq2a6rFy69/M3eEp/sGoN3QUT7JhMfhpv/u+J2/6 IpKw== X-Gm-Message-State: AOAM531zevsaea3rxDO0J3aP+v2FxUOlFlQHcLGd06UuCB0ryaMSqox4 M0INettBwsVRrhvPq6n0dndtKKbHApMQZQ== X-Google-Smtp-Source: ABdhPJymWkJd80yAzlT02yp+AoXi45G9dWs64mgBWGw9Jv3MS5mr+duBUJXA8o5Mvk37jtI/ITmgxA== X-Received: by 2002:a17:906:a195:: with SMTP id s21mr29337444ejy.146.1605828474887; Thu, 19 Nov 2020 15:27:54 -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 n3sm458114ejl.33.2020.11.19.15.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 15:27:54 -0800 (PST) From: Pavel Begunkov To: linux-fsdevel@vger.kernel.org, Alexander Viro Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] iov_iter: optimise iov_iter_npages for bvec Date: Thu, 19 Nov 2020 23:24:38 +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 The block layer spends quite a while in iov_iter_npages(), but for the bvec case the number of pages is already known and stored in iter->nr_segs, so it can be returned immediately as an optimisation Perf for an io_uring benchmark with registered buffers (i.e. bvec) shows ~1.5-2.0% total cycle count spent in iov_iter_npages(), that's dropped by this patch to ~0.2%. Reviewed-by: Jens Axboe 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 23:24:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11919189 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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 4843EC6379D for ; Thu, 19 Nov 2020 23:28:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC4FC20756 for ; Thu, 19 Nov 2020 23:28:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pDS4YWZM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727026AbgKSX17 (ORCPT ); Thu, 19 Nov 2020 18:27:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbgKSX15 (ORCPT ); Thu, 19 Nov 2020 18:27:57 -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 67E09C0613D4; Thu, 19 Nov 2020 15:27:57 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id y17so10300389ejh.11; Thu, 19 Nov 2020 15:27:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PEG2CD9QwVdNv/i79I+tmKVH9JHsgkoJa/Bpyng44Pw=; b=pDS4YWZM0xDCSyd7nQ6UXWzJ6iVm+gjhGcLXJPGeQAuGW+RgzJJJwSUJeeJ28Scfa0 OavWqmLPvWVxtQf5u+xeEUtJaJexbLO5SQV7wnuk4pce+xjeXBpbqUtMGUBnQB/L/823 FDnHmUCBsGIyQUZeKFf2cT4ru7uBHB9X+yFY/Zoq7M6MiRfBRl8fTsCswNc6s3guI35k 6XbEYg5j4bZMiAigGMBWoofx2q5iIfgFNKAemAVOF8RAEnIV8kcnCfkjjNPQ8k+1ztgO e7h+CeFWlam70lGYaehyBuqoZi0BC9m6pVrtOV8abLkOMq7iNFIyZ1oK12MZ9cXKGa1P sgmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PEG2CD9QwVdNv/i79I+tmKVH9JHsgkoJa/Bpyng44Pw=; b=S/dKgnG18JW0UolUcrXmnwWV9ggYHDu+WSW1JMcVGjgyB5sbDRX/mQ78G+vs9YITCq bnLwS1eepGcG8WxA4pdDVAoL6t1u90y1mv6b4P+fp6DFJH3NLEgEdydIrIvJ0uZNOnN5 Oo3H4a1S7tOILbIOg+i/mKBK4koE67eC4jgmUcWobwjuTDK64DKrW25zeO7t0xsB+DWO D3jJowK7lfRpvuORNNk5IsH1uBf+DQLdAn3/HeCJqbk8cV8UnfW02QIyfzdW42cB+MYd 5rcb1T35hxcoF5XeDCHZ9qL6SxgL7odnfcn+EBdclPMYaZ5eo8Tpm9IBXsrjQQMD8SdD WRiQ== X-Gm-Message-State: AOAM532km5Dh6qadsIEget2Z7cptaNFwPuNKwamYgADo9MDF0LrPSzjV 10o4wsQtXZFxmLMPq+wCObkgyH0ledWRiA== X-Google-Smtp-Source: ABdhPJxrJaJb5bLlCj4U3qmJ2UGveo4KTfxI/RC3Z19irfRIvbrRMnlilouwTp2Y4RfowAF4ODg1FQ== X-Received: by 2002:a17:906:b745:: with SMTP id fx5mr20185565ejb.103.1605828475893; Thu, 19 Nov 2020 15:27:55 -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 n3sm458114ejl.33.2020.11.19.15.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 15:27:55 -0800 (PST) From: Pavel Begunkov To: linux-fsdevel@vger.kernel.org, Alexander Viro Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] iov_iter: optimise iter type checking Date: Thu, 19 Nov 2020 23:24:39 +0000 Message-Id: <70d65e06b22cfb11f70b92c12c4d176f36b0e646.1605827965.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 compilers, so even if some cases were handled separately with iov_iter_is_*(), corresponding ifs in iterate*() right after are not eliminated. E.g. iov_iter_npages() first handles bvecs and discards, but iterate_all_kinds() still checks those iter types and generates actually unreachable code including iter init, for(), etc. 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 Most of it is ifs that are executed but never true. Reviewed-by: Jens Axboe 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)