From patchwork Fri Jul 6 19:32:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10512425 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 E0F9F60325 for ; Fri, 6 Jul 2018 19:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF0E7287AC for ; Fri, 6 Jul 2018 19:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2FBF287B7; Fri, 6 Jul 2018 19:33:08 +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=ham 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 6C393287AC for ; Fri, 6 Jul 2018 19:33:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934811AbeGFTc4 (ORCPT ); Fri, 6 Jul 2018 15:32:56 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34558 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934776AbeGFTcw (ORCPT ); Fri, 6 Jul 2018 15:32:52 -0400 Received: by mail-pf0-f194.google.com with SMTP id e10-v6so9187326pfn.1 for ; Fri, 06 Jul 2018 12:32:52 -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=oWrXkw863CtgwaYzdEUdUD8smkG4UEhz6OHrx/76WIU=; b=qff2RF20yCB2Ly3Yh4l44wMwkBf/r4MjbaQ6pRR9D3GnaRl/oPJ5PV2pTGJUNhMBko RqWWLrYMJ1JX/B3fdhodMKuz5JvL14PDNnPazMXA88K+3n6yi42M9GrPvld1GWnskOg4 uAKxvp3yGcGTQWA2+M0mLaZkzHNpKBhDcW91Jfls2BdADl1B+eLd33gKaNRwtJNEw6MW AbLHcKDsqJmUo8GwNGbedTKPEVP7QJeAZx5h9Ujh8Hg1Huc5reSu3LYLaQUs5I3kg47R L3ykgKHhj96ThU/8ChfohLMZWuJY/ormm9llgfsvZl6DpMbl8PtjrQnQXzsCXvU/HfOr DTgQ== 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=oWrXkw863CtgwaYzdEUdUD8smkG4UEhz6OHrx/76WIU=; b=d1kdYiDBjj2OwxgmiptO26RjxEA5HbCf/YZ6BmtYOXSfIv8dMWe12hmDqy3lBWLNjY pBjwIWs6KOCVNyERpC/to1EYTH/1fgCiebiYP8edkl3Rof/aJ4LI1CMR98beX5KGIw3t KU15VfFUObm8xJ5e4FWMNODsh740hVASWc5KJHb1aQGR2G3knQp6aYKBe1JJHE2bsoIV Nd5sgt9HDEWrp4SCsEz16Q8MYTdOJ+XzwXoKTzMV+6tiFd4mYNG8ikEhBYEPZrpIctsL KEVlDdG3UNn9yFqqOWILKh7q3520LE6gjSJJruvYXy7m4ExbuKyeX/9G9wy2+yVVgwxD 5w6Q== X-Gm-Message-State: APt69E1i2hYkubtLZB/leYuSgfn2VbKRA3yvXxUGjeP8uRhHv4RKNlRU p9Fk5QgXoC+80HCFWolt4LPrcqksq0w= X-Google-Smtp-Source: AAOMgpfNKGejL1CoGvb6Z6V4u5MVE5fsQ+bItkcXYYB/NhWfxMYUlKCtRu6cWVrLSne4RwXJnIHNUg== X-Received: by 2002:a62:ac12:: with SMTP id v18-v6mr11633220pfe.126.1530905571553; Fri, 06 Jul 2018 12:32:51 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::4:984e]) by smtp.gmail.com with ESMTPSA id a11-v6sm12846162pgq.32.2018.07.06.12.32.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 12:32:50 -0700 (PDT) From: Omar Sandoval To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan Cc: Eric Biederman , kernel-team@fb.com Subject: [PATCH 6/7] proc/kcore: optimize multiple page reads Date: Fri, 6 Jul 2018 12:32:37 -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 de225b61f34f..f1e21579cd22 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -426,10 +426,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) {