Received: by 10.213.65.68 with SMTP id h4csp1799038imn; Mon, 19 Mar 2018 13:35:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELso5RFrRhY0HcWqLYplVWh/wyV5qWbhau5PPwUxk3CpChKhD2k7SUyk8Bnwvz+aSMyQwGfY X-Received: by 2002:a17:902:9696:: with SMTP id n22-v6mr10761379plp.29.1521491705753; Mon, 19 Mar 2018 13:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521491705; cv=none; d=google.com; s=arc-20160816; b=i3iSiaFCjJ4ebnEWIQry9QhHw1Lcy6i3qPzUOy+5HqqyhTWbsTx0qVjs14uJlpIJLe VyqIqQyoU3A4ljr+Q8bma0dp9XQnmEgCWnbq/YtGf1HJ+hbYRHRY2Lvh8OPOM8Ek3vBd 0675ZmcPMzHcekEWfPIc58vowpCZnkpFsHxv0eHQBlBhHLXRxLtld9FSgiP8Bkd/OnMB qWrcM2UoWY7Zq5PmpDhmc+B9tSnO0D/Y/e1/vHa5PmyVcGO9NMFxhhw2EpZbdyC5dkqU hWH6dAjUtLKGK52svxIQbJlZeHJ9x1YdtFmDv24GELKcXHLcW5He2OIXlCh8e4t7s3zZ xbpQ== 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=bk1HLHx+YB244Ttet9fjA0bfhtLlwUIwEwChn8HYx2E=; b=OsrHPhwW/w3vNRzIWmamkoZkQ+wJ76TWO1KcbziXMj3+3W+CYUNRBCP43bt0NVy3JB O+GSGP0Q/9swh8ZEPx6Vcduz/iL6O5rNBFja9KiSSwJGTVV+rLl5FYtOZEY89E4mHbBD Yxngh6AyhrpGu/jfaTHoIHtIcv02rzj6BmfG0Uvx3J6tfDffchvD6BcUebcShd7ClIW9 aGu1c+QxgbmC4RVNg1zgMkTELj/f03NW8amtNTLmW40/cZqp6wUYg1gAp9RCZFj7wFJ0 hXq0yOgxR4Vez816vUzSRz64cLKC7Bzjea3crKgRgmtWbMbZsSsnsY/m6tf9r3Z/UgLE kQzA== 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 b10-v6si44614pla.260.2018.03.19.13.34.52; Mon, 19 Mar 2018 13:35:05 -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 S935551AbeCSSMZ (ORCPT + 99 others); Mon, 19 Mar 2018 14:12:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42698 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030464AbeCSSMT (ORCPT ); Mon, 19 Mar 2018 14:12:19 -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 3DCE91200; Mon, 19 Mar 2018 18:12:19 +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.4 014/134] perf tools: Make perf_event__synthesize_mmap_events() scale Date: Mon, 19 Mar 2018 19:04:57 +0100 Message-Id: <20180319171851.147448695@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-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 @@ -234,8 +234,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) {