Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1436181rdb; Wed, 6 Dec 2023 21:05:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEcovP2dmJeh+bjl7idMBOuRZ6ztKI6Oh+gPxd1tYYJgiQZNevbRCpcKXpkfUPBdJRalqm X-Received: by 2002:a05:6830:4c2:b0:6d8:50f8:493c with SMTP id s2-20020a05683004c200b006d850f8493cmr2396048otd.2.1701925510540; Wed, 06 Dec 2023 21:05:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701925510; cv=none; d=google.com; s=arc-20160816; b=f2waLZSb+RwL4Tco3d9DzaaeKD6wZnmSFTeW3GpE99igRbLheW5c6WSQmHTjchXec9 Kd7y3Cf05532HoESV7ZQmSWuMp/r+FgxqhOulf5yyGdOwcOiTCwQmrtwonL1qvWCeYaH TGrypk0apsDqfLgGmzsBYSvd9pnoBb7HdYfVtPYUqT8jRQ7KV/r74r/ERFJBvFtvxi6P dt0vNXVVYzMmDw7Seggu4MwhzG/1DO90Oe2rPM4UuiuI6k+WmzQ/sfW2ZgyfeDI4IBGp lMsXYemXK1PlchV7cS29R8MjnUDqEz9OCfxT+AgmRYtg4csgNzHGWWpfIr85jjEaGPat GF6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=vr0pLcjARWkwRyuRy64mQ5hPn4FBvP7Yrmix4YMSHq8=; fh=QzUk4cZ6Uwc0ZODL+YdB/QCafLy0XaBsfa3jMegGZmQ=; b=wSEy8gPnP2E7FvuxhiOX3c7B7DXsLrb1RE+GLadqkifg3hLmZnm0zDHfjyfae7AhWT KL5PFn89Z3qUEM1Hn8tJeKtYmCTXxtx2JlrlPxX+9Syb+6ZqKu3P50e889/Ue03CXv4p 0VrD7koNxjK+PiKJheqW1Mqn4gK5gsHb56MehzR6DMqpOpBheXmVvfy8Z0P6FahKMasV k5EqDNyK2TIoIoIvEiq2InSU8gTVf2juiS4pcH1dbSApt7f4Ea4jgFmavli2G9LCS23j Eg5xE/nseEXxycHBcuN+jbVwUhvIjWUJsSIcEZHTTCHZz2Vz0ELFbF7T8uAT+N3LMkTF 5ARw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tzLVYRep; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n7-20020a654507000000b005c6b0557950si518263pgq.76.2023.12.06.21.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:05:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tzLVYRep; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 89A8580DECFD; Wed, 6 Dec 2023 21:05:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbjLGFEz (ORCPT + 99 others); Thu, 7 Dec 2023 00:04:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230274AbjLGFEt (ORCPT ); Thu, 7 Dec 2023 00:04:49 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D02BBD62 for ; Wed, 6 Dec 2023 21:04:55 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d42c43d8daso2129047b3.0 for ; Wed, 06 Dec 2023 21:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701925495; x=1702530295; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=vr0pLcjARWkwRyuRy64mQ5hPn4FBvP7Yrmix4YMSHq8=; b=tzLVYRepPMTmJKb7UMmnkBF+o2AIHgW8nOnfnUOdz9sIJNjLQiO/H1dHUgM46pgmu6 wFWPg82dOuZ4mZgufU5a9GASZpUPegL3jki9oN3ckLC1zjgCVsV8fIZnJDuXuIvo4zkk Isj1a1FQFsTvJ7HBci0K+MkzVOkWRAhIuWdaUw4qzQ3UgEBKxr829aBYnGtwJfThEFhW z+D1pxDM7jNrowFzhiFOK+DwteSh35x4maPZ0IFL/kxG9zDGHSHRLxO0YGPs1eeIVBBv 7vbKSjgeJFxFzGpxvhaJXs82GbiegClW9EIIS2qQHUZTiC0K9E2x623A8L1RJh2wjyg5 5UBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701925495; x=1702530295; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vr0pLcjARWkwRyuRy64mQ5hPn4FBvP7Yrmix4YMSHq8=; b=BvhYiCahqHiYXFp5tHIE6yiQy6xcLTFJpkdJsxbfCzwBfKe0uYE6XaEOQ+x4dp35Ae sS2bcsdL/Pl8JJBimgorCLQZczsRo20Vb2XjyOaXh7d4NPYy7dgV+Xx1CSPR9KbrblPi y+7mb2PseLAe1xyeIzHrx38iPLLfW24OyEKkhP3nDawIii/IhOJ7l/o+tG+bpEh59F6P UQXBEURKornr2/C+VmBrg5yB/Ou5mkqlVgcq7lPwLEGkXfIX3Y0lXPLMe5gvE4b5A/RS B+mjAuy1jlezBzcbI96HO3Wkzn9r2X6uYFd0Vg78LxHSYovaXma41nRCb6D1++lgBekn UqPg== X-Gm-Message-State: AOJu0YyKKZZCvgiL3NtKx1EwyMev5pB2RrHpdXINovLKEmT8sW326/Vx 5vOODq9PRcBFNPcue1l5NQqAU/xbcOv1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a05:690c:3382:b0:5d3:985c:800c with SMTP id fl2-20020a05690c338200b005d3985c800cmr144441ywb.3.1701925495076; Wed, 06 Dec 2023 21:04:55 -0800 (PST) Date: Wed, 6 Dec 2023 21:04:30 -0800 In-Reply-To: <20231207050433.1426834-1-irogers@google.com> Message-Id: <20231207050433.1426834-4-irogers@google.com> Mime-Version: 1.0 References: <20231207050433.1426834-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v1 3/6] perf maps: Switch modules tree walk to io_dir__readdir From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , "Masami Hiramatsu (Google)" , Thomas Richter , Quentin Monnet , Fangrui Song , Kan Liang , Yanteng Si , K Prateek Nayak , Artem Savkov , James Clark , Ravi Bangoria , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 21:05:09 -0800 (PST) Compared to glibc's opendir/readdir this lowers the max RSS of perf record by 1.8MB on a Debian machine. Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index c5de5363b5e7..b6831a1f909d 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -36,6 +36,7 @@ #include // page_size #include "cgroup.h" #include "arm64-frame-pointer-unwind-support.h" +#include #include #include @@ -1551,25 +1552,21 @@ static int maps__set_module_path(struct maps *maps, const char *path, struct kmo static int maps__set_modules_path_dir(struct maps *maps, const char *dir_name, int depth) { - struct dirent *dent; - DIR *dir = opendir(dir_name); + struct io_dirent64 *dent; + struct io_dir iod; int ret = 0; - if (!dir) { + io_dir__init(&iod, open(dir_name, O_CLOEXEC | O_DIRECTORY | O_RDONLY)); + if (iod.dirfd < 0) { pr_debug("%s: cannot open %s dir\n", __func__, dir_name); return -1; } - while ((dent = readdir(dir)) != NULL) { + while ((dent = io_dir__readdir(&iod)) != NULL) { char path[PATH_MAX]; - struct stat st; - /*sshfs might return bad dent->d_type, so we have to stat*/ path__join(path, sizeof(path), dir_name, dent->d_name); - if (stat(path, &st)) - continue; - - if (S_ISDIR(st.st_mode)) { + if (io_dir__is_dir(&iod, dent)) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; @@ -1602,7 +1599,7 @@ static int maps__set_modules_path_dir(struct maps *maps, const char *dir_name, i } out: - closedir(dir); + close(iod.dirfd); return ret; } -- 2.43.0.rc2.451.g8631bc7472-goog