From patchwork Wed Jul 25 23:59:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10544949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB4E1112E for ; Thu, 26 Jul 2018 00:00:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA0E72A9D4 for ; Thu, 26 Jul 2018 00:00:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDB4A2A9E7; Thu, 26 Jul 2018 00:00:03 +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 C194F2A9D5 for ; Thu, 26 Jul 2018 00:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728628AbeGZBNl (ORCPT ); Wed, 25 Jul 2018 21:13:41 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42326 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728617AbeGZBNk (ORCPT ); Wed, 25 Jul 2018 21:13:40 -0400 Received: by mail-pg1-f193.google.com with SMTP id y4-v6so6308061pgp.9 for ; Wed, 25 Jul 2018 16:59:36 -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=eIz2LDT3jNvOV+6SjD3rQhz1JXwGXwb08hD64XrvRP4=; b=ln0eyIrIZj6RZhlG4r7vuHKAJ58xktXZ6ANYV+nvwes2yRxDFoGPIii+k26dgf3KW5 pT5IF1ayFzjqRrnI0CUjdYYTxSLSNrH8i2AvvpF1J9duD4OQfU5NB1Qe8pOgGpEstxca ZInMRUls8SwZ7UQzGZ7aEtPHasBNXgLborqYaq3xcA4dTSULDSbsa8sAOBrRTsfgJofY FUmJadfe6M60tSHxmUi77W3nFblA5PrtcWkfvuMNrt/zk0iXPYmEDNN3h3JkqHR66+4G jYvdtvEeDTaYjfJiLUzd/VRoamjkb3jxbbh3O8Tu/Mo5JCBoWhmqRTqe/2x6xVwoWCIg j4UQ== 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=eIz2LDT3jNvOV+6SjD3rQhz1JXwGXwb08hD64XrvRP4=; b=RaVNjF2++hvREwrScfbkjJ/13e5Nt/M5Ov7AVNs1tj8mekRqgWc6Ig9NfiGbvIOTwl YpVpLJ+sde4KUEoir0643spY4DKoI1v4e/nE/MUwmtGNdWSAXxQQ8/HvEoPARfK3c1mh +fhNhATqDVrIOz47v49ye9eja6ZA8wA2FV70a8hImGwaBDxVhA60sqcTuWUgpqrMgnuN A0fcwmZW5/UXbIj5S4RGu4qvbNBb7TJU8iZoPnza3tqcGhmLcEWdwEd2j2Bb7dAcHn7j F70gXjz6qIRJGcxph63GuFewvc7rClvyCZ2guY9HatNBEX906Uwb53R6ZWwfagoAGdbD wuYg== X-Gm-Message-State: AOUpUlFgcxStmK2dvg1A8dSgl8l0EkLYPOwtiIRNkU85tgiEqpj7/ofX 4imCB2g6dB5mXMvA0kGRxpZAlg== X-Google-Smtp-Source: AAOMgpeJxn5s+2QROoPSSiqA06mQjcWeQYJBh0Hw08ByAaG2Bj8RP0CxFbmvdVx6pR3NOy/k03sY8Q== X-Received: by 2002:aa7:850b:: with SMTP id v11-v6mr23846859pfn.165.1532563175628; Wed, 25 Jul 2018 16:59:35 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:8d38]) by smtp.gmail.com with ESMTPSA id 65-v6sm23188753pfq.81.2018.07.25.16.59.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 16:59:35 -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 v4 7/9] proc/kcore: optimize multiple page reads Date: Wed, 25 Jul 2018 16:59:18 -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 808ef9afd084..758c14e46a44 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) {