Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp264231yba; Mon, 20 May 2019 08:19:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqweUwTdD1Plq3u/ZlnFOT2IZqAfJclJGTiAmiGAqEgkt0YbiCJRUFBd5WoHX68b/gWNxUUH X-Received: by 2002:a63:ed16:: with SMTP id d22mr75144076pgi.35.1558365582097; Mon, 20 May 2019 08:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558365582; cv=none; d=google.com; s=arc-20160816; b=RMI6pTak45/0N2/mdPoYWBRZ1JBM2FC97648IEAMi2dt41mVeeAoCEIF3FdgOftuHt 3KSlckjjVRyaRDKxku+13RgtZ0xs9oN9wFQPBzAtGGf2oZBzJ7NVOT6SyIwT0crMrOmc kCKXoZbRv1x+y6/WDxWdAgeyE5y4uZVT6/4Vmi+k+XuuJguNgJYm+RA5Dg2RfFyYaHF6 YtNQeTz0N+KxYXiH+jOg/+evZ+2r7/uuram4DvmkSFxIoUkCrcwlXHToJqh9mG+j2pHT xGMButT5xVQudJ1K9Y7VartUon8cZNFn85eIQUP4/awWY7PQWWABZPXDmVMux3Ub6mDH INkw== 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=bDEtfmkdjunZ/xBsFX+/ryfEnIMd7ZVSh/0Jo2DcZW4=; b=gKbfx2MzM0Zbu9s1h70siaZe+fnr4lS3ikvSGokyhNT3gosBWyKxRlbuDerDBiydld 8z89NXglfGXSrudblSkiP29NKeMOIt1rC4JzwWw4s4jETF1GzRt8sxnUkj+GEKmyk8Y7 zd52yS9r1LOMzaT/s81/5JcoKqoYdiAZCUax1IxfViCnwmZaSe4CJtgP2g3SRqE+6uFN hy0MdXNsIG+3YQl2Uqo+0Pg/iwkBeEG1r1w0h1XFn4jL+fG5TJf61ohTJExykjNUvWjM RQsQr0Pt6C1llS9ju9nOC+IZYnd98bNzPiNDKPh6MkLplseNsO8eNxpFUsWKkszC/fQG gPdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yifoIw2t; 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 z19si18265289pfa.260.2019.05.20.08.19.26; Mon, 20 May 2019 08:19:42 -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=yifoIw2t; 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 S2388082AbfETMVB (ORCPT + 99 others); Mon, 20 May 2019 08:21:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:34476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388067AbfETMU6 (ORCPT ); Mon, 20 May 2019 08:20:58 -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 3D23C214AE; Mon, 20 May 2019 12:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354857; bh=YFU/QKlpZL71fZy6JIevh2vlJq1wS1U6jP3tgfScQ7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yifoIw2t/17DAI73z7QpPitXX+FBCcNUw7P4LblF6jYtwLpseuPdU4hCx+b6wRO70 GFp4dFumMFXeikKZLiW+WKLIh/TPi+HNXRx6GfTmQCt4F2nIVyKCTIDTY8UtgHeT8c iDqAmK8Dm4opSjtmj94IKln4LBx40ZVPhbrobJlk= 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 4.14 62/63] iov_iter: optimize page_copy_sane() Date: Mon, 20 May 2019 14:14:41 +0200 Message-Id: <20190520115237.780771243@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115231.137981521@linuxfoundation.org> References: <20190520115231.137981521@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 @@ -687,8 +687,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;