Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp797817rdg; Fri, 13 Oct 2023 01:01:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBsGXYiQZTb9g1/qIkmFlKqtRMwb4anfdP9MRzLDb6ppq7HF7Nfij9QWuXGoTZb1WAHx/r X-Received: by 2002:aca:2315:0:b0:3ae:a81:55a9 with SMTP id e21-20020aca2315000000b003ae0a8155a9mr28069370oie.24.1697184102760; Fri, 13 Oct 2023 01:01:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697184102; cv=none; d=google.com; s=arc-20160816; b=Da/4UsuHQnsXSSHS/zK8d2dPGwHZqbYXJXt3MYxRbyqIgoFEqtjDhV7L8/IrOSS0n7 aXWyVsaALkF1y/RRH+uIPuAdlQG6JDUI1rxrfpU05SrhIJ+mgBr6V4SkMZj8DhCDyP2x WsasVnryU819AbBZ5qIYNxW19tQpqHaigToPTrx/f+up6u20hLLYdRFr4D3dLnQfhdG/ 7/A8k3H8Mo0SmMM3852eiBuIKDQaVrKOg3LqCDHbkQ+Ovp2pgoD4a26nLjX1DjGor9kf 4fA7wER2RaXT+cTruLLMp0DkBwBxEQ9ruVErEyvXDUYRTRkMn4qMg7nyZ0C5FnwZR4EQ 6/ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kkFMdBzvq7puihhd/UCW9F+8y7Sm+2Iqt5F+u17LN2s=; fh=JXx1mv1fB650HoTkc5GIgpDQ5Ey550GcDyaNZ/s6bYc=; b=K2fAKegvJ5713ZdFYuLSDO/9Eh9haRfuvCaWf2VVtVjEpllPwdPHr2ifRZp7hFwysi 9w9tS6xDI+yKnFTtHXFBWGQGokiD5u9TJWrp6nV3lK5xhJVrWo/s1jNjEt7PR1Gvo9km LrkLkUoGSjthrpSfkvNhxjltcc1SLeo4VH0JN0njfTDc6H0ClhRlcraSjoWiLX/MDMSx 4uKVMb/8CCmzdUeGjtq4GC7o6DBpjW8aH5BseJLRQkmtQjEcesXKRLrgbqaIm9ACH4Ub TlT1M3C3Gk9VGuSvag8UwxppPNLqjD0Wu1VjpgsTV+/YmFyPVqoYM6IIZ9Mhfj2ahW2P ay9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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. [23.128.96.32]) by mx.google.com with ESMTPS id g123-20020a636b81000000b0058bc1c85714si3885515pgc.467.2023.10.13.01.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 01:01:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 2EDED81B4549; Fri, 13 Oct 2023 01:01:40 -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 S229879AbjJMIBd (ORCPT + 99 others); Fri, 13 Oct 2023 04:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbjJMIBa (ORCPT ); Fri, 13 Oct 2023 04:01:30 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D959C2; Fri, 13 Oct 2023 01:01:28 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S6JlP2TdXzVlWf; Fri, 13 Oct 2023 15:57:53 +0800 (CST) Received: from ubuntu2204.huawei.com (10.67.174.22) 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; Fri, 13 Oct 2023 16:01:25 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH] perf data: Increase RLIMIT_NOFILE limit when open too many files in perf_data__create_dir() Date: Fri, 13 Oct 2023 07:59:45 +0000 Message-ID: <20231013075945.698874-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.22] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm000003.china.huawei.com (7.193.23.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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, 13 Oct 2023 01:01:40 -0700 (PDT) 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) 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)) + goto retry_open; + ret = -errno; goto out_err; } + set_rlimit = NO_CHANGE; file->fd = ret; } -- 2.34.1