Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp553721rdb; Thu, 2 Nov 2023 10:59:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnPWOXCl9+Mir6DZvXy99Mh5TrHb/exeni0T221WRv93uDy2s8WanqQHYzcGkSHMr1VxeK X-Received: by 2002:a05:6a20:8e0b:b0:14c:a53c:498c with SMTP id y11-20020a056a208e0b00b0014ca53c498cmr20010024pzj.10.1698947982553; Thu, 02 Nov 2023 10:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698947982; cv=none; d=google.com; s=arc-20160816; b=aXlU9ca3G4Eu2Ol3wLhD+07UjSZ6X0eQOCJqOCTiuK+5o8QBSj/hWZNoguG7h9L4LZ UX8YfRwROGzqHnEiHKupf6FBFbfdHl4Gk4lNn/gcPD8Dd8UUpiKorw2geJl+y1xbggZO pgbzDNALH6RlZ/dHD61YrNqta9Wli/QWV4iL4W01oLb4Z7l1o606tXXNcZfqv2uaIrJW m9AKB1TWeAXYmZGMYaZj9geagNU8QU5sNSs9yh9orVsrDohH6pY5BGhKtPz7PBfEPw9Y 6a5NiMzl6WOKHLNMoIhyhSex5UslBty48zPaJS2rEPBqWgsIRuPxyd3DVBBixaxSQ5QU 7saA== 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=Gk/VzT94qDMubCcKVAsuWCAs+LXHGNl5LhGnwC/C5pk=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=yc7h6PkRSHCZp2qjITrXPyyqJVG7sfn3dFDFhq98oDuNV+1TyNk/Ri/Wlvf2l+MFdt JvYirG+Dv9wRynxfIaLGEDqsyfzpnuG+JT3ZICQDiVRssXD3qx22SKIgbDoMVdZ2SOZt 47rXeCuB0uxfKZy0eVLstrDbQK3bC6PSCB47PAcqInpAqPL7KlGXVzuoTvpqtidqGYc3 9mKZylP8ji1fgraT/MmZRF1a2HyMJEb4DdjcNPnojR3Vi9lSN2Frt4/VDe/M490h/CzA iw8BEAc0YkHIDfPSIzNOcTXRJtxB1npuRVoGUpQ3WnTQYJ0dlY0BQMuuCANKe6fC8A4U mzHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ah9r9+5M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k20-20020a056a00135400b006bd20945b23si77375pfu.37.2023.11.02.10.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 10:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ah9r9+5M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id C47B3801B90B; Thu, 2 Nov 2023 10:59:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345012AbjKBR7F (ORCPT + 99 others); Thu, 2 Nov 2023 13:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234577AbjKBR6f (ORCPT ); Thu, 2 Nov 2023 13:58:35 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F28D67 for ; Thu, 2 Nov 2023 10:58:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d86dac81f8fso1517704276.1 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=at732XxqwcauwDPMYZjpCnmyylQx5SdD41ard3+CnLtyKnXAbKGxV+QjyRGTJt2n8t I39QZHrDdb9hdm9sg4odsR8EBJBSclPXoX2+h+bbjZ1xPkYLMNxyX7iENF4wrDTB9Hwg b6eOoE75Acl6BxOLQ0H8MlaeQoUcq6KIyWenUZDZOtH7utJrxzLCFHx/l3IaPEIlNicR PhhFJYeev4kslyC5RHM/veQGUlwa545O/Dx8ABwzAv3p8HZvDd6ZQcayg3DLu6jJ5wMV hCYA7etqyIE0tgUS1ShkyztDxBNcAEGBLXXNYeotTdaKQAgjaa+l4taHw2hbpYDQu4kC hh8Q== X-Gm-Message-State: AOJu0Yw7tr90bRNdZaV1SIgz6VB0yzCbr+D2n4nzk2IDUv9iCvL7e3ZY pBdQXnelZ5x7ASLOPyMaNR2Mfxmxtugj 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> 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" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Thu, 02 Nov 2023 10:59:31 -0700 (PDT) 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