Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3427309rdh; Mon, 27 Nov 2023 14:10:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6q0Ollzs/cO3uMaD61jqHdqIGYN89x+z50+0NSTrIfxyCCTm4n38YSvPZRZWq+AxV18J/ X-Received: by 2002:a05:6a00:2daa:b0:693:3851:bd3e with SMTP id fb42-20020a056a002daa00b006933851bd3emr13862821pfb.3.1701123009100; Mon, 27 Nov 2023 14:10:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123009; cv=none; d=google.com; s=arc-20160816; b=0j1A8QdBr3Walz0eSQMy1FeXcg/5LLXY+oKgw0Z7lYeRXNjpmcXkPSMQgruM+FMxla QIWFcI36Hh639x6uNbS6Q+LEjzy/XVolkhiRyFpTqVgG7DqvrjdSPuKiT+gmfZUvL9ch 5RzfULTLM2T4mexQsT/9HeSe5v85G4bfLiXezaA3Loecv4XuPJXvdaSR6gOtaZUC/4qC m3nF33dev7xw2G0L4Y5I5+HbLSIrrekKKI+CG9JTNa2WpNDEHrPYFy093nsRVQDIfTPG 7hUoA8HNdHCp6m2VI6wIxir3pOJws+fExkC/RAcBas/LsVhKsn2aNCYzn6uh9rmwl/Yy l4Mg== 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=wM9qRu2sJgUV9aoPmw3JmrGSGiE8RlVBwZZnO/fs3Sw=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=ACzS+MsJc2AFcs2XW3Zi4/K6ykj5GXDNLNUARGruoI7/FxKOlJHtMkaF0yVcl7xe83 tBp95imns39rQUpoErDKY2GQ615KH9URMRw1HlN0QsT6F7P4/xTw2phK7y/dShCb6YS+ zKjHL3036a2Se/vBUMvCXuOVp4A+zaStRrI7dJM7LDj2UV1ezP1XwTtlZzu1RWX0bYKM gF2l98ig3TyIsacTSW2G+XS8a83Cgx4n90p8yd/6kNw3doTUm1Z66FyuuL/KZg81AIal +gF/Nqv/bON88D6xcSRo0ffUUSNxvrFoItNnld4Y92KwqVmhwiiZ+Qn27Oak6sCImC22 H+3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="mH3v/Qqj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h11-20020a056a00170b00b006cbe53e19fdsi10836242pfc.222.2023.11.27.14.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:10:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="mH3v/Qqj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id AD61780764A5; Mon, 27 Nov 2023 14:10:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233734AbjK0WJm (ORCPT + 99 others); Mon, 27 Nov 2023 17:09:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233647AbjK0WJg (ORCPT ); Mon, 27 Nov 2023 17:09:36 -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 A152D10D8 for ; Mon, 27 Nov 2023 14:09:37 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5cd0a4fba39so57333847b3.1 for ; Mon, 27 Nov 2023 14:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701122977; x=1701727777; 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=wM9qRu2sJgUV9aoPmw3JmrGSGiE8RlVBwZZnO/fs3Sw=; b=mH3v/Qqjie6fqp3leZ6/BKCvdQ9WA35tC4OSxj/W9KXpTZYvF+O9xM4gPzMGcqjMnj +CN1knZQbxLIfdL+oYOGACc7sKJ7K64f7qXQQ45eFJuITH4w3IBHoSojc/Z3Ef/yDZiA iB/3fVgrlX+ADF7YG0wu2gwb0Jruub3eH/xyJ6dTcP6ul7FHfJ0RaphX1E8ewyjQLjVu ibYL3Vv8gpGf37rrw4y38iS2UEe7Jwi8iVh8WGHto5gdZbO5RzCKj3gOy8QzlsfvaeyN r2NCuQJJurAoT897Hu59zoMC3JeyfCvvlFgAKMar6Becl94PvOqyagPbsSuu1cp+YfcR W35A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701122977; x=1701727777; 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=wM9qRu2sJgUV9aoPmw3JmrGSGiE8RlVBwZZnO/fs3Sw=; b=O8/bSCZzK31CFzPnQhJG1p9eBdzDJS+qzM81BT2ZTeclkQx1oAjBDtgCbOfKnYBKaL si9tIGmbuX4oCIfl+UkvTZeAPqdtN9ucQTEHP8U+PCtOQDKgWRqTRw9W4gLmPXdrgAP+ Rzw8VUzf0QjucAi6Y0irE9H+ZKOghhZaZerOpPmEcfqHWq6pAfgkKxwmRixHnTAC4UkE rAex3pB6l4CTYXtJ9vZPhpb2t7bAhg3LUkWurUdyiYZh+e9OYuVeN8MLj+ksdUMO5NT/ o+zhgQzIgXL5qTUIYlhK6czUpXez2A1dOfDE01Nlt8BFVOCQYyFGf0ZZTBrFwmPOP1Mk gm9w== X-Gm-Message-State: AOJu0YyiXDM6U8LNob6NrPR/LB9RbbWTsELkllfkVrdE5mB9Sg5bGQST 7rfHNSfgFcner2/RDnzXbFL9/iVASWgt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:f84:b0:5ca:ad72:2d78 with SMTP id df4-20020a05690c0f8400b005caad722d78mr503568ywb.8.1701122976902; Mon, 27 Nov 2023 14:09:36 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:19 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-8-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 07/50] 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, Guilherme Amadio 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:10:06 -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 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.43.0.rc1.413.gea7ed67945-goog