Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp23248rda; Fri, 20 Oct 2023 18:48:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDhqXFu6yoFTHj0Q+eaGTnfmja4uivlAmbomvBqQl+mo+9j60PdpQEey2Z+lxCwMOk3FXS X-Received: by 2002:aca:220e:0:b0:3af:e67d:8295 with SMTP id b14-20020aca220e000000b003afe67d8295mr3564006oic.40.1697852891737; Fri, 20 Oct 2023 18:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697852891; cv=none; d=google.com; s=arc-20160816; b=yTQ5+yjCfOhL7391m3IJO1MFOzOfhwvnY5o8Z4JI5G2vjRkAas1QTEBpj+PtKWViim tcbkA/QaMlPStBQwaOGL07vMyTxk3hwGQXDvTVqGNzUHr9pgLgUW9dcvtBXr6hkMrgsa U/1OskN0uNhmKXAiLeutjrK6mJK/hRG78iDWpM7tcywBj20ED9CbUXCsrRW8q+0VSp/s ii2XHKgftSdC6F1Qt/Hcoxb6dXVEE7md+vbMc2BZ6Q/RDDSsQW+EX2qw/3alLlcVytl6 q/D2mEFIm991R/AUWV0rlVBngMU+RXJVZWytO/Zul66yMJSLBkXzHS54Uny1baEZCCPx AwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=AArv6NND8sNmS1bhOUvI1W+fDsuKKQhy0xCXRpcIlv4=; fh=38O5UD8+XixcB2jM/XUsOv3NnMZZTIqqbznw43+apgk=; b=C2h6uLZtAARvavm2fqEpnkSrtdU2RbyftB7xEyhEMExbGpwsvnZAkX90gJMbzdWvCR thAIGIJU30QFbOrCtvYgO4f1SBiG/RmvFs9MSMBazF0agV5OLwg3REKSG6G6PVSmilZc R24M9xXEoJuaYyKwz+WsJkG1Hv5qgJzFWzI/am+epVIvo9zwyqVo19slWfd2izdY/2nw MKFebQ+4QpwwhVNJytr6lA4tqkCIYvdv2B7T4d7LN/PQc2LYPlTg2iwP+QuUUHZ79ASG NSp3ocxxb5DcPqretcoefLq/svMInJEhgR5ABMv+anM+OZnS/e0gPpZfIUz462UNG5d0 L7cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id w17-20020aa79551000000b0068fb95e5401si2835163pfq.65.2023.10.20.18.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 18:48:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 63FCD82A5993; Fri, 20 Oct 2023 18:48:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbjJUBrp (ORCPT + 99 others); Fri, 20 Oct 2023 21:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjJUBrn (ORCPT ); Fri, 20 Oct 2023 21:47:43 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ECD3D7A; Fri, 20 Oct 2023 18:47:38 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SC43n6PLHzNnGr; Sat, 21 Oct 2023 09:43:33 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm000003.china.huawei.com (7.193.23.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 21 Oct 2023 09:47:34 +0800 Subject: Re: [PATCH] perf data: Increase RLIMIT_NOFILE limit when open too many files in perf_data__create_dir() To: Namhyung Kim CC: , , , , , , , , , References: <20231013075945.698874-1-yangjihong1@huawei.com> From: Yang Jihong Message-ID: <70653005-d149-6ecf-b2fb-93a77376a504@huawei.com> Date: Sat, 21 Oct 2023 09:47:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm000003.china.huawei.com (7.193.23.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 18:48:09 -0700 (PDT) Hello, On 2023/10/20 13:59, Namhyung Kim wrote: > Hello, > > On Fri, Oct 13, 2023 at 1:01 AM Yang Jihong wrote: >> >> If using parallel threads to collect data, perf record needs at least 6 fds >> per CPU. (one for sys_perf_event_open, four for pipe msg and ack of the >> pipe, see record__thread_data_open_pipes(), and one for open perf.data.XXX) > > Yep, probably one more for the dummy event. > >> For an environment with more than 100 cores, if perf record uses both >> `-a` and `--threads` options, it is easy to exceed the upper limit of the >> file descriptor number, when we run out of them try to increase the limits. >> >> Before: >> $ ulimit -n >> 1024 >> $ lscpu | grep 'On-line CPU(s)' >> On-line CPU(s) list: 0-159 >> $ perf record --threads -a sleep 1 >> Failed to create data directory: Too many open files >> >> After: >> $ ulimit -n >> 1024 >> $ lscpu | grep 'On-line CPU(s)' >> On-line CPU(s) list: 0-159 >> $ perf record --threads -a sleep 1 >> [ perf record: Woken up 1 times to write data ] >> [ perf record: Captured and wrote 0.394 MB perf.data (1576 samples) ] >> Signed-off-by: Yang Jihong >> --- >> tools/perf/util/data.c | 12 ++++++++++++ >> 1 file changed, 12 insertions(+) >> >> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c >> index fc16299c915f..098f9e3bb2e7 100644 >> --- a/tools/perf/util/data.c >> +++ b/tools/perf/util/data.c >> @@ -17,6 +17,7 @@ >> #include "util.h" // rm_rf_perf_data() >> #include "debug.h" >> #include "header.h" >> +#include "evsel.h" >> #include >> >> static void close_dir(struct perf_data_file *files, int nr) >> @@ -35,6 +36,7 @@ void perf_data__close_dir(struct perf_data *data) >> >> int perf_data__create_dir(struct perf_data *data, int nr) >> { >> + enum rlimit_action set_rlimit = NO_CHANGE; >> struct perf_data_file *files = NULL; >> int i, ret; >> >> @@ -54,11 +56,21 @@ int perf_data__create_dir(struct perf_data *data, int nr) >> goto out_err; >> } >> >> +retry_open: >> ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); >> if (ret < 0) { >> + /* >> + * If using parallel threads to collect data, >> + * perf record needs at least 6 fds per CPU. >> + * When we run out of them try to increase the limits. >> + */ >> + if (errno == EMFILE && evsel__increase_rlimit(&set_rlimit)) > > It seems weird that we have this helper with evsel prefix and > it does nothing with evsel. But it's a separate concern, so > > Acked-by: Namhyung Kim Thanks for the Acked-by tag. Uh... The name of this helper doesn't seem to be appropriate. Okay, I'll submit a patch to fix this helper name. Thanks, Yang