Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2186195rda; Tue, 24 Oct 2023 15:27:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjaUOEkENS4nGcbQfFshsFVfNVpfyowEKdYj5iED7W8zfvLRBr8XY3dyKjTGUD7ziyJdP0 X-Received: by 2002:a17:902:e5cb:b0:1ca:220:ce42 with SMTP id u11-20020a170902e5cb00b001ca0220ce42mr12170737plf.37.1698186471907; Tue, 24 Oct 2023 15:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186471; cv=none; d=google.com; s=arc-20160816; b=T6v3nyEP5S/kL0Eu1y/eTMiDlUaOG5alJfmXlrV8rkxGsNNFtLF9S/JnYiuGssAATM v28O581UUYklvbV46ithi2RjNRv6+AZ8gMJYmFkiR0tOlrEO2dzJtuZMQBNAzF94KXNa VPlLfOm3qBBqGYEvtrI9W1x5vVuybWgtHMlVCbvV/HDFWAi+XFOQIxHrVlSbnKFXckyG g8YB0f5fehoLW++uf8r8G0/2NQz49LB1TQRiqwQUvA/vJEtvY57LPvVj6OLWH0sfrLqI qpBRZf/UlhvKeCu6iNrqH/42S+CDinRGHV0hx/zstCqLygZ4IoF5Kks8vRBcUa1UfBOc OoRw== 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=RoZZ8YDCVCxLUMcPN0SyAz4FQGuYm4BBqKyuZJTny60=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=i4fvvttXSqmk5rWN+S0p7VG6ixPDLoe1Fo+VWDg/TcRoFknf1sHrPSoz8fHGbb32hE kYp1ETvm97HbgY/0GppfZLlkEs7uw2RsILlX55gypEEXwZJEsIObc8y7RQ/MgasdvZ9N kwo/dHRbydccT7t44Czex6n0L929tj35+PBZhdfuPRJRcbGgVfh0IepwbgabZGssXsms 6HY7OdvsNBhuv+n5hLJytQCzgFeGvMrJWWAGtW2/cYw3eYEoLisymB59S+dUIKzRjO8e qeShnIsGHJT8MJZdPmBe/3o6VQJ9/zsXW68sqqhQ1/CC5a9pB1JxUN/8dWWk8tOrCBD9 6zvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LxQ7TUcE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w4-20020a170902e88400b001c474ff2fdesi9483424plg.378.2023.10.24.15.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:27:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LxQ7TUcE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id F3200802541B; Tue, 24 Oct 2023 15:27:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344653AbjJXW1f (ORCPT + 99 others); Tue, 24 Oct 2023 18:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344433AbjJXW1X (ORCPT ); Tue, 24 Oct 2023 18:27:23 -0400 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 38FBB19A8 for ; Tue, 24 Oct 2023 15:24:57 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a81cd8d267so94137487b3.1 for ; Tue, 24 Oct 2023 15:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186295; x=1698791095; 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=RoZZ8YDCVCxLUMcPN0SyAz4FQGuYm4BBqKyuZJTny60=; b=LxQ7TUcExIRiHdVin9naidfy0tXXS0gmjOw+K8Z6+6die0cYFfO8FhJCm2C6nLPP7L G0oV/niPGAWZIL1vGUbDHISIIrPsaQ4mdGq6odFWcNXdHGSj/xtzHUvmRbyyiGxnpl+m mJuvC8wN8X2szmgGGdMH0wuv2XoRobGwIoGUjr/AkdDaGL3NjhDwmvif/ljc2M/0Bd84 1AeQLpKUEJYEN94W1KAEi40E0vJsiqkEoBO15/+ydyqmei/7h4pBtMV6Nls6Y6M8nneV aPwXyNALAdqlZiSauZ2aGT3mDIpFUsYnAfblySVRf9KCPTd7LoQU+IJK3WW5PdUkPyhK zpkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186295; x=1698791095; 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=RoZZ8YDCVCxLUMcPN0SyAz4FQGuYm4BBqKyuZJTny60=; b=hKdGYb3HwRPFAqqOxfxR8NpkPzwUWegiX+7w8MhfKA8gFXyidH0w+Z9mWhRZzMBn6+ 5qbxzMy00vP/wqH+X52yE9MkawzWNxMsOvL+xjQFwTE5tXAH/t/p5tAi9hh87sYRPfvn EWRYOw/GQKOvaj62JOMEexRP1LFkFldMgmYuVi4HQME3kpQWqSV3NLw5V30XaAPblnh8 hZW057Rg/m7MfKRj2pJ85iCTT9MPjp/z3SzXJ+ApfqaB63AppZMm9jWxmmcxig2BoYEK Iefi8i7vP+qePz4WFQQRgMtENrfQf/2guHmVrHbeAZmGr5RRWTLdgMYoM08Xe4DeAjW/ r/AA== X-Gm-Message-State: AOJu0Yxpp83BiWysZOhhHICJqv7yrajotFf3tgxj8K+NJk33Lltwqjf5 xTECdzvQCH0mhIh0PgGKT9WjtK/Az/Je X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a05:690c:3142:b0:5a7:a98a:4af0 with SMTP id fc2-20020a05690c314200b005a7a98a4af0mr17210ywb.3.1698186295659; Tue, 24 Oct 2023 15:24:55 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:22 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-20-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 19/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 , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , 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,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:27:49 -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.758.gaed0368e0e-goog