linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iov_iter: optimize page_copy_sane()
@ 2019-02-26 18:42 Eric Dumazet
  2019-02-26 19:04 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2019-02-26 18:42 UTC (permalink / raw)
  To: Al Viro, David S . Miller
  Cc: linux-kernel, netdev, Eric Dumazet, Eric Dumazet

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 <edumazet@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
---
 lib/iov_iter.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index be4bd627caf060cd89aa41ac88208946da568035..4d6b19c1b1294e1c30f6bbb7137e98cca5121f13 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -861,8 +861,21 @@ 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;
+
+	/*
+	 * 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;
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iov_iter: optimize page_copy_sane()
  2019-02-26 18:42 [PATCH v2] iov_iter: optimize page_copy_sane() Eric Dumazet
@ 2019-02-26 19:04 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2019-02-26 19:04 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S . Miller, linux-kernel, netdev, Eric Dumazet

On Tue, Feb 26, 2019 at 10:42:39AM -0800, Eric Dumazet wrote:
> 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.

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-26 19:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-26 18:42 [PATCH v2] iov_iter: optimize page_copy_sane() Eric Dumazet
2019-02-26 19:04 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).