Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1703268imu; Sat, 8 Dec 2018 05:38:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/XioOOLiRexQgCPbQaezX/vBZZfw6vELkjVXzoU7xOTb0Gd8r92jVg4Md0sxlo4aq4jEkMw X-Received: by 2002:a63:b4c:: with SMTP id a12mr5226382pgl.131.1544276321112; Sat, 08 Dec 2018 05:38:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544276321; cv=none; d=google.com; s=arc-20160816; b=B1/bxMm0MpJv1pmCJjQaTUyCXqNZH2k6v+tvz3/fIN+ohZdguUECRKh+qNjUFC2Zpi 7zshHFNRtyWC1o8smDyxn+0r+lW8Kp775k/vgofuCve4b/0malfTpB5RE/z37RC8hFdd VifVDpTT9kgGrMFE5jrklh+CrmTjkoNAO1UR3lq5tkvkQVoxdyXEPtKj5dYfpDP/TOaU G0O0F7nnmnrZXntXXMloq2+WfFKy5b/7NKsH6MsaCl1YgD/CBVKvZppZ0Kj2A2IRhS1u ovagWWItewmL2ZKR5AUh2WN9q/7k5FBvdAQRydYfePdLgeOw0aqLnShKPhkLv1MDntNE LAwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=X5TrM5uSqDuHn/TJD2QwMyhxyWPNtLFwaBkvImxSto0=; b=yET82mctYnPP2ziKs98o2sMEfvtuOkWCR680wxbkGbN0UoJ4Q2cpDgLQ3WNLDvwBZ9 AHJrCKDcY06c4nOIbv4tAtb0Jb4TFMR0OWycPvSQKv7aOnZ6dnBdTJX8FIfF8S32vr+i Ie4cud/a8GNxnrELh9VmRP/sI9BmaSFFf/dJws6KFuBgWblJBdjOjjfcB1x0inb1DjP0 qZ0FEesZOkmpXKbxvUBcQI7dc06bj2oJd3d9/xDr7YC7uyHp7iuvLAAJJPjr6ft3f1g8 /2CaGxOumTGVspbRyZZMC5jaKmp1sTLIdxwzdHQgYtidSNdj1HJzMw9u1hQO7a6rEwow LThg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Tj9hXT/D"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66si5753246pfp.144.2018.12.08.05.38.25; Sat, 08 Dec 2018 05:38:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Tj9hXT/D"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726168AbeLHNhl (ORCPT + 99 others); Sat, 8 Dec 2018 08:37:41 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39477 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbeLHNhl (ORCPT ); Sat, 8 Dec 2018 08:37:41 -0500 Received: by mail-pl1-f194.google.com with SMTP id 101so3118841pld.6 for ; Sat, 08 Dec 2018 05:37:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X5TrM5uSqDuHn/TJD2QwMyhxyWPNtLFwaBkvImxSto0=; b=Tj9hXT/DuAvwyjYZmXNs2dWKa8SFX94n+Mm9WunJ70at9IU96NStA70gHxieahsxQ1 8P+7BHAS6+UI3/AOlu0fmG+NlKiBKj7aIpF0NftxogZtmrb1yvNW39RdS3QXpIiXFHse sVHnnqN8NdftgYCTmMifx6TCSh+W3cQGHzCOiuQdMUVXoJ9A6868WCzgSlh12WRHDDmj /xLO9OJhULyvEc6epbTC+840qRVTtdG7QEuSmvC89PrTgJkjqmy6AUWt5T4UUR3BhMQ3 67NGMBUM+wpUmwDQl6BQU0IKaCmu8PByn+wXfM5QviqaAsvfUyVIgdy/5BYf/0iE2n4e pdXg== 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:mime-version :content-transfer-encoding; bh=X5TrM5uSqDuHn/TJD2QwMyhxyWPNtLFwaBkvImxSto0=; b=MbP0Io8TOnmgXz6YDnwkxBwsEy1z5M9tWFhiZy4Woi0QDId9nwHiL1eI/G5cAi77MB WnK2UxZq27Pzkf7xnRFU8YrvAdSNnqIUCNUstffPYLtNUeSRkwhariwOFRk3OSVGgVS1 Qo5faNi94awhV4dXM7iLntD5oQ9sVFKScEc+bQM/DsB3JOZBBrG9QGp0QagcfLqZ3X01 PYiDLQ8uPJBBlsvzlJsTZZGDilZIChtjjgrLYFi9lFjEQCE3FXk/3SPRhM4acfcY9wVS dujqe/j9Nz44oQgJougokRY/0BdBu7QsnjOcPpVnLRYnGyA+K0EUbUp8H9Ed+/1xsE7p baow== X-Gm-Message-State: AA+aEWZ13QUaeJEBGV7SFQKYeLaJqZhigLv+Iuiu8aGonz9Bsk3mqKqJ Nryn2rjnaXRB1tVYcMRbxWGsjFkWuHU= X-Received: by 2002:a17:902:b090:: with SMTP id p16mr5726599plr.190.1544276260032; Sat, 08 Dec 2018 05:37:40 -0800 (PST) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id k15sm10814432pfb.147.2018.12.08.05.37.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Dec 2018 05:37:38 -0800 (PST) From: Eric Dumazet To: linux-kernel Cc: Eric Dumazet , Eric Dumazet , Al Viro Subject: [PATCH] iov_iter: optimize page_copy_sane() Date: Sat, 8 Dec 2018 05:37:35 -0800 Message-Id: <20181208133735.245799-1-edumazet@google.com> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid cache line miss dereferencing struct page if we can. page_copy_sane() mostly deals with order-0 pages. Signed-off-by: Eric Dumazet Cc: Al Viro --- lib/iov_iter.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 54c248526b55fc498c996f2a5ea651262fcc7f61..2a1e282c3d38e2d03b075f54b7f9313e48b90289 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -854,8 +854,18 @@ EXPORT_SYMBOL(_copy_from_iter_full_nocache); static inline bool page_copy_sane(struct page *page, size_t offset, size_t n) { - struct page *head = compound_head(page); - size_t v = n + offset + page_address(page) - page_address(head); + struct page *head; + size_t v = n + offset; + + /* + * Fast path if this is an order-0 page, + * or if the copied area fits the first page of a compound one. + */ + if (likely(n <= v && v <= PAGE_SIZE)) + return true; + + head = compound_head(page); + v += (page - head) << PAGE_SHIFT; if (likely(n <= v && v <= (PAGE_SIZE << compound_order(head)))) return true; -- 2.20.0.rc2.403.gdbc3b29805-goog