Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp913984img; Tue, 26 Feb 2019 10:43:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IbPaCq76/gcnZGsKL2rtecY6R1y9e5gxo5mTFjLfL5Lf0AV0j8W7lMXixuE0oin6veofN+1 X-Received: by 2002:a63:8942:: with SMTP id v63mr24970328pgd.406.1551206607895; Tue, 26 Feb 2019 10:43:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551206607; cv=none; d=google.com; s=arc-20160816; b=OhhBPV1mfcyuRoHAHTXSz+NqFPLt80SiwBOugEGHcn8MshBKyAmW0o2KyyVNP0LvCm 1l7idRxxpPeoEs4IprNEFYO/YCiuyU9bul0cx8C7XuzgX2GoUkCEEsH0B+e49AlW0A3A t70kXhbYm1j2xSrj37j3K13oVzZDy5oiap4aWUgpHrRxWyZ3/naxTigGmjNBJFMduRAY EtsCiik84ss3H31xUtHZX3GQIGeBLgxDFP7bkblOQFFzTDjZmdpr+JEftbCyF1HyPkTU pr3YSEtoLPSwXDNf9oQcvqrbr0XpzXawdPSuD7hsslkCyMuD4Kv4PClHD1m5sn4j6/ez ZjzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=v4WfsSw47DRlkp9YeYFf0nNx1o0W7a7PFh2stQvOZlw=; b=NRDCPO2ZXKF85l45pW3hQSDszbEd+F5ei+Q1dRyjB+xysM9w0tvlAJn/JUfEo8mqfI VQ05dnLn+sHE2/P5M2hMe47Ss2eTTtoDNnLfTM4s+WBBDvkFfY+gyBCWT/YTJYKOaCmx Bh4Z9QOAHpFNRGmA6/Cc8NLN3CmgLzMssXxpDMhRPbPMakLQUNVQgNiKJufG4vH+Uc8n 4wZS6phpSlHLGwMyPhKjvjq5d5v4d4V7bc5DuydkcN5MkwMMdvRZBRJ8r9ivnnJGupTN 5hXe2npilYUq5U2hJaInBOrMiM69wQxRXM6fUYG/sskS0f8zoYk7t/2hju4QVKjb1g8O 9J4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=h17mYNWc; 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 y186si12524240pgd.315.2019.02.26.10.43.10; Tue, 26 Feb 2019 10:43:27 -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=h17mYNWc; 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 S1729125AbfBZSmp (ORCPT + 99 others); Tue, 26 Feb 2019 13:42:45 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:51375 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728996AbfBZSmo (ORCPT ); Tue, 26 Feb 2019 13:42:44 -0500 Received: by mail-qt1-f202.google.com with SMTP id s8so12889669qth.18 for ; Tue, 26 Feb 2019 10:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=v4WfsSw47DRlkp9YeYFf0nNx1o0W7a7PFh2stQvOZlw=; b=h17mYNWchKn5zBjHq56fo4f1DKtYRjAqAY1H9IrPa+r2X3csFFOW7SzOWpvbY61WN+ M+p06LLo145QchAxtFuTWuajpS74KHCDmQnejJFrftQh6j763c7W5q+mDdbOzlM7EJHf 8CbpvhrGjorvcK5RDgWZcjsyDAmsYy8wA7nIHrbF9WGUcFxQ0IeICcKAy+S+ojN6RygP BydpAZy7K+0dkvxKylakqNBXbhsuWLlhOpAOjTZ2Jf9yEKW9XuQckwx4M/Ux10MfJiQ9 3W/O4MLOnEBeJ+qohZBMnuKh0lLa41dHpPW5DyBw7H1mpC0yRcbDlIC87xAY382eAo/g 9dWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=v4WfsSw47DRlkp9YeYFf0nNx1o0W7a7PFh2stQvOZlw=; b=E01kpJA+vrooiCagOyf6KU2HldXy6SAYcqYIItolsdsfidf9nmv7laNkaEevaQ0GOV 7S+pVaJkSjiv4J2Vc/a03pBaJsF4JxesV71EsCvELMmMDot6lejadPmzR9uqbthJ9+5e smjvqz2AJGQJAYa4NDldX/U00iau05KxBGyrJ3E9LznVHGG38ckVJMZfv3Pbg+pqgBnw kL/JT7KMcWqdhIxCesJPxdWkOh1Z4LL9zLR4I6F8zda4svUWeSrwMc5mU8vVBxRXNO9i btP9GMlA0zFBUkD4T66xIwmrENq+oqXV6tdYMTgddhcwvuUlJ35mwsi+9dKVJo21KCRh zcoQ== X-Gm-Message-State: AHQUAua59ilen5fUtVaYN/SXjub0GSBfQeKkjqd9406s8/9ODzFCVqxt XKU1qgNH2WUbynlIpTdtcNsRLH6dtBzG7A== X-Received: by 2002:a0c:9678:: with SMTP id 53mr14835922qvy.16.1551206563846; Tue, 26 Feb 2019 10:42:43 -0800 (PST) Date: Tue, 26 Feb 2019 10:42:39 -0800 Message-Id: <20190226184239.49946-1-edumazet@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.rc2.261.ga7da99ff1b-goog Subject: [PATCH v2] iov_iter: optimize page_copy_sane() From: Eric Dumazet To: Al Viro , "David S . Miller" Cc: linux-kernel , netdev , Eric Dumazet , Eric Dumazet Content-Type: text/plain; charset="UTF-8" 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. 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 --- 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