Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A740F20B1C for ; Thu, 2 Nov 2023 17:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ah9r9+5M" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FD87D66 for ; Thu, 2 Nov 2023 10:58:17 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a90d6ab944so17709597b3.2 for ; Thu, 02 Nov 2023 10:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947897; x=1699552697; 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=Gk/VzT94qDMubCcKVAsuWCAs+LXHGNl5LhGnwC/C5pk=; b=ah9r9+5Mx7Ay7TVE5aEN5x7jcF+tPkgOeQTM+jnCw68fHVIdy2pwm5fsbDFqETN9zx p3jRoljPgx+Zoo0KSKnzKTcH9d1mwZBNi4TSovjqyKbZGnbxLOFe8zJHbYZCIEYriROw hxFCPC5kmigF1MoUtTqWKyXpgH+DDvbesAVwQpqBrNdGsl2XqOJTxW98PVta5tIajAP1 Eq+qYga0+wukw1Z9kWISluFhq1CK6/kmklkFKNdHnxGkoza9ALmnvNEposdRX2SQTuXA qwDvlDCeC68uEKAdFzcGnLONYrJa40yUcVhuz5WP0/fqFRDe3Nn9svBm03kAnyhzEYMZ D33A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947897; x=1699552697; 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=Gk/VzT94qDMubCcKVAsuWCAs+LXHGNl5LhGnwC/C5pk=; b=tUcQ6gt8MoSV4JZRacqRENTKFa4nouEYfVRlQE9znEyVYlNO6FaZtPejtVxpLaPB44 hO7WV8LT8dSHAlDcztHkGd/s/veGMaBPgFD7ZygemYlXhd69SWNkc8AUScMt99eznCBE h2n/iMdrJNte4OJjm8NQ/ahySbKxTVl8f4wsLTHYsHxQ3LylXItvxGf3sUDd9XlgTMz1 OguiZiqSgeSGIj5nAsUHP9yI0OyFhkgYF1w0/Ie+wmOFZ23Of7FOwFjLPAi1JK5g0VX/ 4H2proWAnyXAFxxdnnGXYeSTgciJjj1aP047pj/BTbQge7HUlt3hl3H926hdmqwbhl8Q +Xxg== X-Gm-Message-State: AOJu0YxFOaoaqvaOG5WtLVCe0SNFoi7bimOk7B9K36nsOKQpQ1XEDl3p sH4PRSDqNwdynff18SvChRzxJ7MVfd+8 X-Google-Smtp-Source: AGHT+IGpeDRD/GEyMSa21NJNFRrWsZEsEPu1fdzYK2ak56e29qQnCpW4H/uIWSAKpNpQBE5QB1PJMQbOQvxL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a25:770f:0:b0:da0:73c2:db78 with SMTP id s15-20020a25770f000000b00da073c2db78mr397036ybc.9.1698947896754; Thu, 02 Nov 2023 10:58:16 -0700 (PDT) Date: Thu, 2 Nov 2023 10:56:51 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 09/53] 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 , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 a985d004aa8d..be3dab9d5253 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 @@ -1552,25 +1553,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; @@ -1603,7 +1600,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.42.0.869.gea05f2083d-goog