Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp90376yba; Mon, 20 May 2019 05:32:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzV7gsJXK1tvt/mWzql9poFPhr7t/ZYhJQeWqWF3Bv9RZXtFQO74qIa5+KXDsdUUh06v5M+ X-Received: by 2002:a17:902:b095:: with SMTP id p21mr24307553plr.270.1558355552941; Mon, 20 May 2019 05:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355552; cv=none; d=google.com; s=arc-20160816; b=A1gWf4gzPPE3BnBGP1JM0Q4LvRp3bpLLxStWBdqli50YQk0e80i9qOwmptqTR6P3zJ 7XafkEW+CVJMh9LQvPW3RtTLXf8Ki6TOUPp9FMxGhF0POVz1NX2HcrDsDEprEOqKFbWg OBr0g6hssh6ag8s7NtQcXlJfdKcRFG3BBpjKPFHGkyg3BisXeXh4G/PkypQama6nfVyT MMyDmEjz9jXEbsC9Gxh2Y+uYm5k5sfJPC2WqYlpby0mkwwF7rycktSHtcCAl1SE6HedY htWq6ydNnpojd/50k4TycTles/gakssBhaIYa74ntOs3f9IsdoOkjVNqEi5JSdxP/F9C /qEg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wWcUkO+50az4mLcuZBKbfpADLxfHErGWp1cue8qpZVw=; b=cnpxWaxyGZLWgrfmmqGYId99blJY9LnrVbsIFg63jw9SdoWo673v2nhYGW16LJ/kBU tmg2eMhaECPqw/7ysz24/LjvSJ46M4vxBWd8DubVZVBad/QexnXvbaYydwYSxtitNEQ1 wJ4oPw6fMIpD+tPEaqYJ3mq+MtBtSLSTNRExWT50h2wyWJsDw1lj+QYWIY4loR+fHRYp Tdoj8dRFvXzkvneEMR4ouPN+75ROEN4lI/VbaQgp5/7KTjHVXZ0wPiosBLVARqwwJYyU /lAP7to0Dokgbh4fKWPchAiboi/FDpHUAXJviMpWUtNBBIaSIxLCYNWXF8l0/zUz1Xcs Sd0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BNInjKtP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si18060877pla.235.2019.05.20.05.32.17; Mon, 20 May 2019 05:32:32 -0700 (PDT) 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=@kernel.org header.s=default header.b=BNInjKtP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390134AbfETMah (ORCPT + 99 others); Mon, 20 May 2019 08:30:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:46854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390118AbfETMac (ORCPT ); Mon, 20 May 2019 08:30:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4076220645; Mon, 20 May 2019 12:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355431; bh=EV1/7IpflXgcuo3qsgApL2j+LJlceYK1/Hzf2uetAm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNInjKtP5BinHs0nVsjwGanOy+Lyj9hfVhN7RCfj3hK+Vb1Yh4D0TdvBpTMkk7Mpb F5n77YsG8YrnyNgYxcNirPlFwZqpFeV7qKazUQxHXJ4ix8yDnFeIT/FPk9xt/4//j9 0R1G5UhbYKi5Nohkvy5cvcNUOpoJw3fRrZtiLp6I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Al Viro , Matthew Wilcox Subject: [PATCH 5.0 117/123] iov_iter: optimize page_copy_sane() Date: Mon, 20 May 2019 14:14:57 +0200 Message-Id: <20190520115252.935249966@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115245.439864225@linuxfoundation.org> References: <20190520115245.439864225@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit 6daef95b8c914866a46247232a048447fff97279 upstream. Avoid cache line miss dereferencing struct page if we can. page_copy_sane() mostly deals with order-0 pages. Extra cache line miss is visible on TCP recvmsg() calls dealing with GRO packets (typically 45 page frags are attached to one skb). Bringing the 45 struct pages into cpu cache while copying the data is not free, since the freeing of the skb (and associated page frags put_page()) can happen after cache lines have been evicted. Signed-off-by: Eric Dumazet Cc: Al Viro Signed-off-by: Al Viro Cc: Matthew Wilcox Signed-off-by: Greg Kroah-Hartman --- lib/iov_iter.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -861,8 +861,21 @@ EXPORT_SYMBOL(_copy_from_iter_full_nocac 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; + + /* + * The general case needs to access the page order in order + * to compute the page size. + * However, we mostly deal with order-0 pages and thus can + * avoid a possible cache line miss for requests that fit all + * page orders. + */ + if (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;