Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1060617imm; Wed, 18 Jul 2018 16:00:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcbaoDukXzCsdnaF7SNj1u2YBMnoIt15nl/6SNqabjRousOjuSUerHlyH/+UqZ8N/0LwMBr X-Received: by 2002:a63:3686:: with SMTP id d128-v6mr7327900pga.18.1531954842467; Wed, 18 Jul 2018 16:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531954842; cv=none; d=google.com; s=arc-20160816; b=TwOa/Xj+Dk+wsh9roCfvmGxg3H41QDe2x1Y6nTiw6cpf+txuazDF05KwvruK7n9Uda XGqLOsekSiC4NFM9nv0qFcf5SxNT2O4w1ZYEkAp1H14GoziEEXuwkth/96rb8eO/ljYX agtsg5aya02UbkCAa9FZaDvXZX6EokR8ccakd4V962v0QK0zNmIH9MRSbtKsWePGOBS6 OIAiv6RIqneE76OaR0F3o67IN0JUBFle2H17lWG7pOwM+OzgGbEa0Vb9LDBzXIdnnzNK oDmoFauPZlHBCO7PiDmk547dw1+EaOoRklTwm5Hv0pbZSo6wKOncEe2o9PRVrKP8Heg3 LGpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=3zK1N/1xTLC08ekFsVD34euJSqM/sHfKuTlLNtQ5ic0=; b=EMTtCTIlSDnf01jjv8sDaX2wQNCtbzaFi/H07Z9URyTY9a4tvPlq90QDmYdBs3Sen4 IGf9ccJ66hGEynL1K8XKivS8MhEY3k2pDNPyQZ7xPluqyMTdbM8AklB9XSdOVXjXKQL+ +jHyiYE2tE/LYLXb7OtPMNgd/L3nWZ/sDEEwN4ctGl4qrNUsbCygkazCdm+ISHd7Wb1P miTyfDFeaR7pjomZWzpu5urqRqwmYWTCPidlxuuH894uEi/zWuBJVmYmJL5NMWZMbVyC EgvST1UJselDNedAusKQgvp9kTKBNSzLGI7am16nzAc3cgDG5uWI+LhrUOHmUbXCM/pW P/cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=jYq9jMCI; 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 c12-v6si1761032pgd.359.2018.07.18.16.00.27; Wed, 18 Jul 2018 16:00: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=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=jYq9jMCI; 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 S1730798AbeGRXjn (ORCPT + 99 others); Wed, 18 Jul 2018 19:39:43 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34076 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730226AbeGRXj1 (ORCPT ); Wed, 18 Jul 2018 19:39:27 -0400 Received: by mail-pg1-f194.google.com with SMTP id y5-v6so2671863pgv.1 for ; Wed, 18 Jul 2018 15:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3zK1N/1xTLC08ekFsVD34euJSqM/sHfKuTlLNtQ5ic0=; b=jYq9jMCI99K9s8rIV9bv9dmiWcxRNIVv37el/7baBAnuBmCBh98g86uW4AIhluKPyM lm9tiCvxG0sd15pW4MTgpIVndjGdSUbA3LGKiSr/VOUASiPJaL3onF1Pnd9ad6DXwGou 5FOd3mf386igpAavtgeVjWzUQRrdyjRWev2qgWT5omaq7il/4mLYD7tMZQqSMX5nmP6n xftRyDmce2snItwAU1BClBeD/v93P3iPcHOLGnjBzfsc8XU7uV8QIwK7EwTW0Q8IiKNW 2TUVlvLIbtwjKnn77m4A2BNl2+Dw3OnijvudmwP6PKlFefZISaPWm55mRErvmS9SAHPS oB3g== 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:in-reply-to :references; bh=3zK1N/1xTLC08ekFsVD34euJSqM/sHfKuTlLNtQ5ic0=; b=shNwW5a5Io6KQ++N45ZF7QVdFcAJlKPt6jWkkk+YMoSHPqqHxwU6L8bt+8QvpK8klF uccOH2o6TGvGRMozWTEZNBIfZ1pa05cUptnY2PCmbM3I4HluKjadJ/8w0gCCphhiODQz SM3A9FwykSCTp8+6gqnrU7xI2wKv7uwNi26zGzgpjfpR3cMjRVuDW7purscif/iU4uz4 bdp7By+XInlG5iqWwqbLCD/wRNrI9KYK0oGIMzhObE/tjMtF6t8BFVPpD+7NEuT01Fxd C2JChttGRztSLWOJ6qJCCQH26m3WDB1dzaCYxcqqjzGIcq2nuPdNJnjuqhLGuTjP36X9 HRhQ== X-Gm-Message-State: AOUpUlEyamJRLSLesisPiHh4fNJFeeuO20980IO+C3A9pgQKYEeJgxlW RINF0TA1PWEo7+Rah7gqgv0cZUj9WyY= X-Received: by 2002:a63:d518:: with SMTP id c24-v6mr7582625pgg.357.1531954760736; Wed, 18 Jul 2018 15:59:20 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id s16-v6sm6377946pfm.114.2018.07.18.15.59.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 15:59:20 -0700 (PDT) From: Omar Sandoval To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton Cc: Alexey Dobriyan , Eric Biederman , James Morse , Bhupesh Sharma , kernel-team@fb.com Subject: [PATCH v3 7/8] proc/kcore: optimize multiple page reads Date: Wed, 18 Jul 2018 15:58:47 -0700 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Omar Sandoval The current code does a full search of the segment list every time for every page. This is wasteful, since it's almost certain that the next page will be in the same segment. Instead, check if the previous segment covers the current page before doing the list search. Signed-off-by: Omar Sandoval --- fs/proc/kcore.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index e2ca58d49938..25fefdd05ee5 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -428,10 +428,18 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen) tsz = buflen; + m = NULL; while (buflen) { - list_for_each_entry(m, &kclist_head, list) { - if (start >= m->addr && start < (m->addr+m->size)) - break; + /* + * If this is the first iteration or the address is not within + * the previous entry, search for a matching entry. + */ + if (!m || start < m->addr || start >= m->addr + m->size) { + list_for_each_entry(m, &kclist_head, list) { + if (start >= m->addr && + start < m->addr + m->size) + break; + } } if (&m->list == &kclist_head) { -- 2.18.0