From patchwork Fri Jul 13 00:09:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10522453 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 0CAF66032C for ; Fri, 13 Jul 2018 00:10:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F22EF29372 for ; Fri, 13 Jul 2018 00:10:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E675D296BE; Fri, 13 Jul 2018 00:10:12 +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 99BF929372 for ; Fri, 13 Jul 2018 00:10:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387823AbeGMAVv (ORCPT ); Thu, 12 Jul 2018 20:21:51 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40334 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387765AbeGMAVu (ORCPT ); Thu, 12 Jul 2018 20:21:50 -0400 Received: by mail-pl0-f65.google.com with SMTP id s17-v6so1964928plp.7 for ; Thu, 12 Jul 2018 17:09:53 -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=Z15UaSzJRjo8tNMEdcU0lrFYH9loaE8GxwYN54R5itU=; b=OXTawfza7tZUQKWnWOBGLrlyvtI9Y+hFH6QBzVopvbKxoVKtdEDIvrHDuDftvcDR3Y 8Ss5M8d8QLGHPc9Kdl4oS9FmyCfegf1mM0JEX4GPK9V1Mb0R24CasC9s5qEUbrTXrQ7U BM5lbNiqAXVw6frAd4NPI3xvQqP3OE32FkOLSfhADi/USsQ2YlJpw21lijL5M15PVQUC z6jMg9Ndy40m3A1J+78/yo54qUV6G5JMZ/96dVxqsWZ3Ub43tZZEfxil693wdnGcGghV C/NU74g1iNAj11UPTq42GZXrZoNfsikYy3H6gkUorzJKn2kTXstep/jA0CoTB6ssZeM7 1sbw== 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=Z15UaSzJRjo8tNMEdcU0lrFYH9loaE8GxwYN54R5itU=; b=cvf9UcvKAma7mSHc4KQJlhUBG4/slOU0WxcuJH0hI8M7JfWZyRPg4M1Z8kVFQ4793m idtB3xAu8Ki/DAhLVj8RS2d5JhqBv/3mdNz8udx6mQ8YGcy7ZsNDF/wpt21QSVor+ql4 CjM4PqHPyg8BNwPsZIpaYfkw7l47ESt0kbUpL6PtkbMzctsuhPJbR5UkSH2zaCl6Funo FtyqytMCSJw5vTrcPtIUqbl6xqcmJMySdPfqj0m2/XYAhEo5lgQnDdJnkuSUFmV1y6zs 6KGee5BYyQGmeM7uJOUEoY6UaZiSyVOw+AAAWZ4Lx13M5tRXhgF/Gd30hMHqxFRwVjS2 D7Xw== X-Gm-Message-State: AOUpUlHfOski8F677kqK5VhHNkQY0Iro0dv4idxCyCnG+z58SgU5z4k3 WNzUs60yI/48XLt1FmonLCs4+A== X-Google-Smtp-Source: AAOMgpfcZPHhirctnO86EyKWh0Kywl+e2S4Ae1URppZPMQrDHjX6eK4uHA8NpuGeUgtX06XsEeJs0A== X-Received: by 2002:a17:902:9a01:: with SMTP id v1-v6mr4213791plp.20.1531440592324; Thu, 12 Jul 2018 17:09:52 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:74a0]) by smtp.gmail.com with ESMTPSA id b86-v6sm4452067pfj.35.2018.07.12.17.09.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 17:09:51 -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 v2 6/7] proc/kcore: optimize multiple page reads Date: Thu, 12 Jul 2018 17:09:38 -0700 Message-Id: <296622acfe01efc2e93472b312afe9e374370abe.1531440458.git.osandov@fb.com> 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 a7e730b40154..d1b875afc359 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) {