Received: by 10.213.65.68 with SMTP id h4csp1772224imn; Mon, 19 Mar 2018 12:51:30 -0700 (PDT) X-Google-Smtp-Source: AG47ELubrKqmOCoa6JGkYVTqwRMX8Xsn0NOSg6YdxBXkmHG1268bagrwMLh/GzU81u1vE8LsOqWg X-Received: by 10.99.119.137 with SMTP id s131mr9699829pgc.296.1521489090515; Mon, 19 Mar 2018 12:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521489090; cv=none; d=google.com; s=arc-20160816; b=u7MUaKl/4o1x/yUhFs3rRcG8+NpLY6SX5DFm7XUfM3DFvrnI2OGwe8IkRbCMTNOWsh E6t+Wjw4MCi1n8iAN7kQ0XiKFHd4ev539OkawUxSdg5bcaJw3dyrv4Pfm15IfWk/XfWn DP+1tLRrhfkJuOpNjMbaprXrr/KAiH2UoGB6aOkus9joaKQcOTzUE95yWw5mInFuXJQ6 WFaiObALMvYUVElASqdOcmPJdYM7ypLJzk6EPL1TEMvoVJib6+qZY86PRUoHYPbn++0F WUNdOduudZi2ZZQt7g1lzSEhLVS6FS3S8cAkg97xO6NVBLNkU5xJkqnc/dvcZwyJ7oxz 707w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=NB60m3a5ZJAGC8m0CO4GObmCzpQfM45D8y1e0BpKRN0=; b=UNgYONoHwX0q2SBdvfuQoE7gN5kN6g+QQ550DFjKUr1C5uKlVB7AF5tCiaGsfTu5Z7 DE27YY89qGg1VHb6TMxNPsJB5cuI82trWlViQ/0n2cci2p15dfJUOOJtF9a567RZMN2c dtq0VSROhdmBmquKafwZSqUZq/ExvG7UO/RmjVoMO/xYhJ7GyZNfXK2e92ehoyQboj14 tDljNGD7LajNJdxK3mMllqFeVvHeebHnAkAFV6fVI647St0YlVS0AGTOi4hpX7AskDiR KptleEp+zDOAQNYJfPGqv9VKG/pGLPmIIDazj8AL88hx0DuOjrvyIGTlRppa6cdIufa+ iDtA== ARC-Authentication-Results: i=1; mx.google.com; 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 94-v6si521785pla.215.2018.03.19.12.51.16; Mon, 19 Mar 2018 12:51:30 -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; 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 S970057AbeCSTsS (ORCPT + 99 others); Mon, 19 Mar 2018 15:48:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47574 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969501AbeCSSUQ (ORCPT ); Mon, 19 Mar 2018 14:20:16 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 44CF81136; Mon, 19 Mar 2018 18:20:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Eranian , Jiri Olsa , Andy Lutomirski , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 026/241] perf tools: Make perf_event__synthesize_mmap_events() scale Date: Mon, 19 Mar 2018 19:04:51 +0100 Message-Id: <20180319180752.248879504@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephane Eranian [ Upstream commit 88b897a30c525c2eee6e7f16e1e8d0f18830845e ] This patch significantly improves the execution time of perf_event__synthesize_mmap_events() when running perf record on systems where processes have lots of threads. It just happens that cat /proc/pid/maps support uses a O(N^2) algorithm to generate each map line in the maps file. If you have 1000 threads, then you have necessarily 1000 stacks. For each vma, you need to check if it corresponds to a thread's stack. With a large number of threads, this can take a very long time. I have seen latencies >> 10mn. As of today, perf does not use the fact that a mapping is a stack, therefore we can work around the issue by using /proc/pid/tasks/pid/maps. This entry does not try to map a vma to stack and is thus much faster with no loss of functonality. The proc-map-timeout logic is kept in case users still want some upper limit. In V2, we fix the file path from /proc/pid/tasks/pid/maps to actual /proc/pid/task/pid/maps, tasks -> task. Thanks Arnaldo for catching this. Committer note: This problem seems to have been elliminated in the kernel since commit : b18cb64ead40 ("fs/proc: Stop trying to report thread stacks"). Signed-off-by: Stephane Eranian Acked-by: Jiri Olsa Cc: Andy Lutomirski Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20170315135059.GC2177@redhat.com Link: http://lkml.kernel.org/r/1489598233-25586-1-git-send-email-eranian@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/event.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -255,8 +255,8 @@ int perf_event__synthesize_mmap_events(s if (machine__is_default_guest(machine)) return 0; - snprintf(filename, sizeof(filename), "%s/proc/%d/maps", - machine->root_dir, pid); + snprintf(filename, sizeof(filename), "%s/proc/%d/task/%d/maps", + machine->root_dir, pid, pid); fp = fopen(filename, "r"); if (fp == NULL) {