From patchwork Wed Jul 18 22:58:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10533427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2FC8D600F4 for ; Wed, 18 Jul 2018 22:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2001D298BA for ; Wed, 18 Jul 2018 22:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 143EF298BE; Wed, 18 Jul 2018 22:59:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0F17298BD for ; Wed, 18 Jul 2018 22:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729309AbeGRXjm (ORCPT ); Wed, 18 Jul 2018 19:39:42 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41970 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730203AbeGRXj1 (ORCPT ); Wed, 18 Jul 2018 19:39:27 -0400 Received: by mail-pg1-f195.google.com with SMTP id z8-v6so2653710pgu.8 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=H2RcuRs2dK2w1a4My3xspvgmf87yO3O2Xs3W5sxrJdG7iPrz0l8g0qhQebhDDuwEy6 PaLWL6jykx3a7NdffUcLhDtEdnEh7skJAS79MppKg+mQNl5G2I/j1BQLa2/9bqXZf10e IYNSLrfGBzvy/3C5d5B/Ih+9M8SEF69r1cDPllstfuqSTVwJbejAWywOcxiDBUe2Gk5q NPFgcy/aXSuXu5/ZB4/fMZG0babe25FoumqGh+0RqBPYvnQ8Im60D5Q8eF50ub4aSHU/ 5K9pweWdtlcZ5MGLdZKITkJDnatUUyWEyVmbYWyEDXGeu6Guta9mwqqGtz2Rs0gRD1g6 lHtA== X-Gm-Message-State: AOUpUlGobGWNWUOoVrX8tTTBtj6RDt6GZ2whNZcva7Cv4wgsQhOUgUkj aA5rmH0LcmWMUIUzdqShq0obbg== X-Google-Smtp-Source: AAOMgpe24mo4it/+QYqoyfnJHoiRI6kpUa58/Vu15J9CUhdVvlKMEqpbQWjJbaycGBRQ/Ct7TwazZw== 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) {