Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp193711imm; Thu, 12 Jul 2018 17:11:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeNF6beDkFFbLrs/JSUJO5gaILGzg0Y7NuRY8mDxTQ8aR83GaXylIfwFEL17zR0wLQY92rv X-Received: by 2002:a63:4f1a:: with SMTP id d26-v6mr4034139pgb.121.1531440662535; Thu, 12 Jul 2018 17:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531440662; cv=none; d=google.com; s=arc-20160816; b=As34nh3Q2yoJ+H5pDii65blg1zdLQ7LwhNOzC7FMzw9dNnZhDUK8C+o9oj1z5t5Lra k++ilfiCv5pwboQfLIJI+UaiwykJZkVqAI36WBTfJl+HBmbrcaZcTWVHNmqj1ZQjIOZC thl1yDJ6YL8D/+vrc5tbh/OeapUvMSW0Cac3nUM4+8Yq5NUUBFRJoMXbyUvYDpA4BNxL MjXpPn5hToixlOoLnQBrGewi8TFKvSJCeOpf1LN383ysa8+t8tPfD7E82UC3LISd9iZ0 KdDPdxyAmmTNMWM829aN+45wskLhSsJw0KMLJJcZhcInS4wFCS8xZc9zcZKxFMU3SIjm Ke+Q== 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=Z15UaSzJRjo8tNMEdcU0lrFYH9loaE8GxwYN54R5itU=; b=gsk+IirJY1m0BDP9eKwjh3KCw5/OWTMy0ylhppycoZgQYbTYDWU6VCGjDbmVo4BK70 MEowcczXoCFy9/uY9JuN/MKTtp/vpuqSIuZKnebbEF+snPOLAlJLV9qsjgH8XlJrNzgv Z2s6YCV77gh4kvGXyG3TGwHH0ntqWy2xmzqO4LrsH35t7RqiCwKeRgLDSwkmWL8CSyun Xa3wlUWwqTRd3hakFQDN1n0uWF95ba2ZGzg49A5+ch7M9hMNSmGmc5xmz89SrCL5TAQg TeM5JBcKUaZrOLfpqYmTdQ088s60a0sqfhHI6WBlvs3bcYzvyCWUW2622ep77zwgL0dU r1mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=OXTawfza; 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 f28-v6si25000843pfh.33.2018.07.12.17.10.47; Thu, 12 Jul 2018 17:11:02 -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=OXTawfza; 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 S2387835AbeGMAVv (ORCPT + 99 others); Thu, 12 Jul 2018 20:21:51 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36253 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387819AbeGMAVu (ORCPT ); Thu, 12 Jul 2018 20:21:50 -0400 Received: by mail-pl0-f68.google.com with SMTP id a7-v6so11358256plp.3 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=bxnRQjCPlHMrzRY/DmB2FJOIMjqYOU1ic8Ou4ryFNpLOekYSV4BqL3rNdciYlf+pid OxkUu3puu7F+EgiA6ecF6+yLrsPJxINdP9YoEAULXjIbMN6ue/sg0vyR+iLKEGvL7kxy p+zr/g7a7szfbuWCf35OY65BR8JaYJeT2Kpaf+PgZJUOiORyoSK7jk7KWy7hoJa8KA1M mSQQWFZagpnRAoqDJrX75/SEnx5DTNwsFuPeL1VVW5/hlwtFxbH46BRNMuC01IjhCNn9 sGFrAMDwrE9L3H5oO/w19j8HxRMl0LDiCR3kPh8wYN6oy/Z5+GeWqqX73aVLYuyWijVO VSsw== X-Gm-Message-State: AOUpUlGBa+hUslhE6N1+2De+C+/Q4qDzSK+wpLmL/RIX86JuJFl9oEjz jLZ2fq6MQMLuuwEKVta7zAZatpHYvSs= 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-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 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) { -- 2.18.0